{
  "generated_at": "2026-06-26",
  "repository": "ClaimManager",
  "detected_stack": {
    "language": "TypeScript",
    "framework": "TanStack Start (React 19 + Vite 7)",
    "runtime": "bun / node (server handlers + createServerFn run server-side)",
    "python_backend": false,
    "note": "There is NO Python/FastAPI in this repo and no Python runtime configured. The backend is implemented in TypeScript as server-only modules (*.server.ts) and server route handlers. A prior explicit decision in this project was to implement the spec in TypeScript, not Python."
  },

  "has_backend": true,
  "backend_kind": "typescript-server",
  "evidence": {
    "server_only_modules": 24,
    "api_endpoints": [
      "POST /api/report/generate",
      "GET  /api/report/:id",
      "POST /api/report/chat",
      "POST /api/v1/report/generate",
      "GET  /api/v1/report/:id",
      "POST /api/v1/ingest/scan",
      "POST /api/v1/query/router"
    ],
    "sample_backend_modules": [
      "src/lib/ai/hybrid/router.server.ts (intelligence router / orchestration)",
      "src/lib/ai/hybrid/pipeline-v1.server.ts",
      "src/lib/ai/hybrid/extraction.server.ts + extraction-strict.server.ts",
      "src/lib/ai/hybrid/reasoning.server.ts + reasoning-citations.server.ts",
      "src/lib/ai/hybrid/embeddings.server.ts",
      "src/lib/ai/hybrid/vector-store.server.ts (in-memory + Qdrant adapter)",
      "src/lib/ai/hybrid/report-store.server.ts",
      "src/lib/ai/hybrid/auth.server.ts, rate-limit.server.ts, guard.server.ts",
      "src/lib/ai/hybrid/jobs.server.ts, ingestion.server.ts, logger.server.ts",
      "src/lib/llm-config.server.ts (generic env-configurable LLM key/endpoint)"
    ]
  },

  "layer_audit": {
    "1_frontend_ui": {
      "status": "present",
      "paths": ["src/legacy/components/**", "src/routes/**"]
    },
    "2_backend_api": {
      "status": "present",
      "paths": ["src/routes/api/**"],
      "notes": "7 server endpoints, JSON envelope, zod validation, rate-limit + auth guard wired."
    },
    "3_analysis_engine": {
      "status": "present",
      "paths": [
        "router.server.ts",
        "pipeline-v1.server.ts",
        "reasoning*.server.ts",
        "extraction*.server.ts"
      ],
      "notes": "Deterministic routing/chunking/retrieval; LLM-backed synthesis."
    },
    "4_document_processing": {
      "status": "partial",
      "paths": ["ingestion.server.ts", "chunking.ts", "src/legacy/utils/fileUtils.ts"],
      "gap": "PDF/DOCX binary extraction + OCR happen client-side (pdfjs) or are stubbed; no server-side OCR/pdfplumber-equivalent."
    },
    "5_knowledge_vault": {
      "status": "partial",
      "paths": [
        "src/legacy/utils/knowledgeBank.ts",
        "vector-store.server.ts",
        "/api/v1/ingest/scan"
      ],
      "gap": "Knowledge bank is a static client list; vault ingestion API is minimal."
    },
    "6_report_generation": {
      "status": "partial",
      "paths": ["report.server.ts", "reportFormatter.ts", "src/legacy/utils/pdfReport.ts"],
      "gap": "Report CONTENT is server-side (markdown + JSON); DOCX/PDF RENDERING is client-side (docx/jspdf in the browser)."
    },
    "7_database_layer": {
      "status": "partial",
      "paths": ["report-store.server.ts", "vector-store.server.ts"],
      "gap": "No persistent RDBMS. Storage is an in-process Map + best-effort on-disk JSON; vectors are in-memory unless QDRANT_URL is set."
    }
  },

  "architecture_violations": [
    {
      "rule": "No computation in frontend except UI rendering",
      "severity": "high",
      "detail": "Deterministic financial / delay / schedule / loss calculations run in the browser.",
      "files": [
        "src/legacy/utils/lossFormulas.ts",
        "src/legacy/utils/financialDelay.ts",
        "src/legacy/utils/delayMethods.ts",
        "src/legacy/utils/scheduleMethods.ts",
        "src/legacy/utils/delayEvents.ts"
      ],
      "imported_by_components": 12,
      "remediation": "Extract these into deterministic server engines (e.g. src/lib/engines/delay.server.ts, financial.server.ts, schedule.server.ts) exposed via /api/v1/* endpoints with input/formula/decision trace; reduce the React components to API calls. Keep them in TypeScript (same stack)."
    }
  ],

  "other_gaps": [
    "No real auth: login is a mock client-side AuthContext; auth.server.ts parses JWT/headers but no token issuance/session.",
    "No automated test suite (unit/integration) committed.",
    "POST /api/v1/report/chat (SSE streaming) not yet implemented (only non-v1 /api/report/chat exists, non-streaming).",
    "No Docker / docker-compose for qdrant + redis.",
    "Persistence is not a durable database."
  ],

  "enterprise_scorecard": {
    "separation_of_concerns": "partial (server layer real, but legacy compute still in UI)",
    "api_layer": "good",
    "validation": "good (zod)",
    "logging": "present (structured logger.server.ts)",
    "error_handling": "good (typed errors + JSON envelope + error codes)",
    "rate_limiting": "present",
    "auth": "weak (mock login)",
    "persistence": "weak (no RDBMS)",
    "tests": "missing",
    "containerization": "missing",
    "traceability": "partial (citations + sources in RAG; calc trace not yet on financial/delay engines)"
  },

  "recommendation": "EXTEND_EXISTING_TYPESCRIPT_BACKEND",
  "do_not": "Do NOT rebuild as a separate Python/FastAPI service inside this repo — there is no Python runtime here, it would be dead code, it duplicates the working TS backend, and it reverses the project's earlier explicit stack decision.",
  "prioritized_plan": [
    "1. Move financial/delay/schedule/loss calc from src/legacy/utils into deterministic server engines + /api/v1 endpoints (fixes the architecture violation; adds input/formula/decision trace).",
    "2. Add a real persistence layer (SQLite/Postgres via Drizzle or Prisma) behind the existing report-store interface; keep additive.",
    "3. Implement real auth (JWT issuance/session) and finish POST /api/v1/report/chat SSE.",
    "4. Add server-side document extraction/OCR + server-side DOCX/PDF rendering.",
    "5. Add Vitest unit + integration tests and a docker-compose (qdrant + redis + app)."
  ]
}
