# gokulthiyagarajan/neural-justice-ksp-datathon architecture

> Architecture diagram of the GitHub repository gokulthiyagarajan/neural-justice-ksp-datathon, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gokulthiyagarajan/neural-justice-ksp-datathon
- Repository: https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon

## Overview

#### Purpose and Deployable Entry Points
Neural Justice is a Karnataka State Police crime-intelligence platform: FIR/case operations, role-scoped dashboards, geospatial and network analysis, reporting, and AI-assisted investigation. The React SPA starts at `frontend/src/main.tsx` and routes from `frontend/src/App.tsx`. The FastAPI service starts at `backend/api/main.py`; a separate Zoho Catalyst serverless handler exists at `functions/neural-justice-backend/main.py`.

#### Client Application and Role Boundaries
The TypeScript/React client presents dedicated CP, SP, PI, PSI, and PC workflows, with role-specific dashboards selected through `frontend/src/pages/dashboards/DashboardRouter.tsx`. Authentication state and login/MFA flow are client-side concerns in `frontend/src/auth/LoginFlow.tsx` and `frontend/src/store/authStore.ts`. Shared application shell, navigation, and jurisdiction-aware presentation sit in `frontend/src/components/Layout/AppLayout.tsx` and `frontend/src/config/navConfig.ts`.

#### API Surface and Operational Domains
FastAPI route modules split operational APIs by domain: cases/FIR-adjacent operations, dashboard data, stations, notifications, patrol, profiles, crime patterns, and CP-specific views. The API composition boundary is `backend/api/main.py`; representative domain endpoints are `backend/api/routes/cases.py`, `backend/api/routes/dashboard.py`, and `backend/api/routes/cp.py`. Client requests are isolated behind API clients such as `frontend/src/api/client.ts`, `frontend/src/api/firs.ts`, and `frontend/src/api/copilot.ts`.

#### AI Copilot: Request-to-Answer Pipeline
There are two connected AI implementations. The API copilot pipeline accepts/authenticates requests, detects intent, retrieves knowledge/datastore context, executes queries, and formats responses through `backend/api/copilot/chat_pipeline.py`, `backend/api/copilot/intent.py`, and `backend/api/copilot/executor.py`. Its HTTP boundary is `backend/api/routes/copilot.py`. The client interaction model—dock/panel, request lifecycle, and persisted UI state—is in `frontend/src/copilot/CopilotDock.tsx`, `frontend/src/copilot/hooks/useCopilot.ts`, and `frontend/src/store/useCopilotStore.ts`.

#### Multi-Stage Reasoning and Model Providers
A separate evidence-oriented reasoning pipeline explicitly progresses from generation to critical review, deep reasoning, consistency checking, and final assembly. Orchestration and routing are in `backend/pipeline/orchestrator.py` and `backend/pipeline/router.py`; stages are represented by `backend/pipeline/stage_1_generation.py`, `backend/pipeline/stage_2_critical_review.py`, `backend/pipeline/stage_3_deep_reasoning.py`, `backend/pipeline/stage_4_consistency.py`, and `backend/pipeline/final_engine.py`. Provider abstraction and QuickML integration are bounded by `backend/ai/providers/base.py`, `backend/ai/providers/quickml.py`, and `backend/quickml/service.py`; caching/evidence verification prevent repeated or unsupported output via `backend/pipeline/response_cache.py` and `backend/pipeline/evidence_verifier.py`.

#### Intelligence Visualization and Data Inputs
The SPA renders FIR operations, maps, hotspots, patrol context, and criminal networks. Major visualization boundaries are `frontend/src/pages/GeoCommandPage.tsx`, `frontend/src/components/geo/MapProvider.tsx`, and `frontend/src/components/NetworkGraph/CytoscapeCanvas.tsx`. Source data is supplied as SQLite databases in `backend/ksp_demo.db` and `neural_justice.db`, plus raw FIR CSVs under `sample dataset's/datasets/Police_FIR_Dataset_CSVs/csv/`; ingestion/seeding scripts are `import_data.py` and `scripts/seed_full_db.py`.

#### Runtime and Infrastructure
Local runtime is Node/Vite plus Python 3.11/FastAPI, typically using SQLite and optionally PostgreSQL. Production targets Zoho Catalyst, configured by `.catalystrc` and `catalyst.json`, with the static frontend and serverless function deployment model. Declared external integrations include Catalyst Data Store/NoSQL, QuickML, Zia OCR/Speech/Translation, SmartBrowz, push/signals, and OpenStreetMap-backed MapLibre/Leaflet maps. Authentication/security boundaries rely on JWT, TOTP, RBAC and jurisdictional access as reflected by `backend/api/copilot/auth.py` and the client login flow.

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["React SPA"]
  node_spa_entry["SPA entry &amp; routing<br/>React bootstrap<br/>[main.tsx]"]
  node_app_shell["App shell &amp; navigation<br/>UI shell<br/>[AppLayout.tsx]"]
  node_role_dashboards["Role dashboards<br/>dashboard router"]
  node_client_auth["Login, MFA &amp; auth state<br/>client auth<br/>[LoginFlow.tsx]"]
  node_api_clients["API clients<br/>request boundary<br/>[client.ts]"]
  node_copilot_ui["Copilot dock &amp; state<br/>AI interaction<br/>[CopilotDock.tsx]"]
  node_intel_visuals["Maps &amp; network visuals<br/>visualization<br/>[GeoCommandPage.tsx]"]
end

subgraph group_api["FastAPI Service"]
  node_api_entry["FastAPI composition<br/>API entrypoint<br/>[main.py]"]
  node_operational_routes["Operational domain routes<br/>REST endpoints<br/>[cases.py]"]
  node_cp_routes["CP views API<br/>REST endpoints<br/>[cp.py]"]
  node_copilot_route["Copilot HTTP boundary<br/>REST endpoint<br/>[copilot.py]"]
  node_copilot_auth["Copilot authorization<br/>JWT/RBAC guard<br/>[auth.py]"]
end

subgraph group_ai["AI &amp; Reasoning"]
  node_chat_pipeline["Chat intent &amp; execution<br/>copilot pipeline<br/>[chat_pipeline.py]"]
  node_reasoning_orchestrator["Evidence reasoning orchestration<br/>pipeline coordinator<br/>[orchestrator.py]"]
  node_reasoning_stages["Generation through final assembly<br/>reasoning stages"]
  node_evidence_cache["Evidence verification &amp; cache<br/>grounding controls"]
  node_model_provider["QuickML provider<br/>model integration<br/>[quickml.py]"]
end

subgraph group_data["Data &amp; Deployment"]
  node_data_sources[("Case databases &amp; FIR CSVs<br/>SQLite and raw data<br/>[ksp_demo.db]")]
  node_catalyst_runtime{{"Catalyst serverless deployment<br/>production runtime<br/>[main.py]"}}
end

node_spa_entry -->|"renders"| node_app_shell
node_spa_entry -->|"routes to"| node_role_dashboards
node_client_auth -->|"scopes access"| node_role_dashboards
node_app_shell -->|"hosts"| node_intel_visuals
node_api_clients -->|"HTTP requests"| node_api_entry
node_role_dashboards -->|"loads data through"| node_api_clients
node_copilot_ui -->|"submits prompts"| node_api_clients
node_api_entry -->|"mounts"| node_operational_routes
node_api_entry -->|"mounts"| node_cp_routes
node_api_entry -->|"mounts"| node_copilot_route
node_operational_routes -->|"reads and writes"| node_data_sources
node_cp_routes -->|"queries"| node_data_sources
node_copilot_route -->|"authenticates"| node_copilot_auth
node_copilot_auth -->|"permits request"| node_chat_pipeline
node_chat_pipeline -->|"retrieves context"| node_data_sources
node_chat_pipeline -->|"invokes reasoning"| node_reasoning_orchestrator
node_reasoning_orchestrator -->|"runs stages"| node_reasoning_stages
node_reasoning_stages -->|"verifies output"| node_evidence_cache
node_reasoning_stages -->|"uses models"| node_model_provider
node_catalyst_runtime -.->|"alternate deployment"| node_api_entry

click node_spa_entry "https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/frontend/src/main.tsx"
click node_app_shell "https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/frontend/src/components/Layout/AppLayout.tsx"
click node_role_dashboards "https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/frontend/src/pages/dashboards/DashboardRouter.tsx"
click node_client_auth "https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/frontend/src/auth/LoginFlow.tsx"
click node_api_clients "https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/frontend/src/api/client.ts"
click node_copilot_ui "https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/frontend/src/copilot/CopilotDock.tsx"
click node_intel_visuals "https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/frontend/src/pages/GeoCommandPage.tsx"
click node_api_entry "https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/backend/api/main.py"
click node_operational_routes "https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/backend/api/routes/cases.py"
click node_cp_routes "https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/backend/api/routes/cp.py"
click node_copilot_route "https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/backend/api/routes/copilot.py"
click node_copilot_auth "https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/backend/api/copilot/auth.py"
click node_chat_pipeline "https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/backend/api/copilot/chat_pipeline.py"
click node_reasoning_orchestrator "https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/backend/pipeline/orchestrator.py"
click node_reasoning_stages "https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/backend/pipeline/stage_1_generation.py"
click node_evidence_cache "https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/backend/pipeline/evidence_verifier.py"
click node_model_provider "https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/backend/ai/providers/quickml.py"
click node_data_sources "https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/backend/ksp_demo.db"
click node_catalyst_runtime "https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/functions/neural-justice-backend/main.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_spa_entry,node_app_shell,node_role_dashboards,node_client_auth,node_api_clients,node_copilot_ui,node_intel_visuals toneBlue
class node_api_entry,node_operational_routes,node_cp_routes,node_copilot_route,node_copilot_auth toneAmber
class node_chat_pipeline,node_reasoning_orchestrator,node_reasoning_stages,node_evidence_cache,node_model_provider toneMint
class node_data_sources,node_catalyst_runtime toneRose
```

## Components

### React SPA

- [SPA entry & routing](https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/frontend/src/main.tsx): React bootstrap · `frontend/src/main.tsx`
- [App shell & navigation](https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/frontend/src/components/Layout/AppLayout.tsx): UI shell · Jurisdiction-aware layout and role navigation. · `frontend/src/components/Layout/AppLayout.tsx`
- [Role dashboards](https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/frontend/src/pages/dashboards/DashboardRouter.tsx): dashboard router · Selects CP, SP, PI, PSI, and PC workflows. · `frontend/src/pages/dashboards/DashboardRouter.tsx`
- [Login, MFA & auth state](https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/frontend/src/auth/LoginFlow.tsx): client auth · `frontend/src/auth/LoginFlow.tsx`
- [API clients](https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/frontend/src/api/client.ts): request boundary · Includes FIR and copilot clients. · `frontend/src/api/client.ts`
- [Copilot dock & state](https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/frontend/src/copilot/CopilotDock.tsx): AI interaction · `frontend/src/copilot/CopilotDock.tsx`
- [Maps & network visuals](https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/frontend/src/pages/GeoCommandPage.tsx): visualization · Geo command, map provider, and criminal network canvas. · `frontend/src/pages/GeoCommandPage.tsx`

### FastAPI Service

- [FastAPI composition](https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/backend/api/main.py): API entrypoint · `backend/api/main.py`
- [Operational domain routes](https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/backend/api/routes/cases.py): REST endpoints · Cases, dashboards, stations, patrol, profiles, notifications, and patterns. · `backend/api/routes/cases.py`
- [CP views API](https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/backend/api/routes/cp.py): REST endpoints · `backend/api/routes/cp.py`
- [Copilot HTTP boundary](https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/backend/api/routes/copilot.py): REST endpoint · `backend/api/routes/copilot.py`
- [Copilot authorization](https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/backend/api/copilot/auth.py): JWT/RBAC guard · Applies authentication and jurisdictional access. · `backend/api/copilot/auth.py`

### AI & Reasoning

- [Chat intent & execution](https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/backend/api/copilot/chat_pipeline.py): copilot pipeline · Detects intent, retrieves context, executes queries, and formats answers. · `backend/api/copilot/chat_pipeline.py`
- [Evidence reasoning orchestration](https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/backend/pipeline/orchestrator.py): pipeline coordinator · Routes multi-stage evidence-oriented reasoning. · `backend/pipeline/orchestrator.py`
- [Generation through final assembly](https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/backend/pipeline/stage_1_generation.py): reasoning stages · Critical review, deep reasoning, consistency checks, and final engine. · `backend/pipeline/stage_1_generation.py`
- [Evidence verification & cache](https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/backend/pipeline/evidence_verifier.py): grounding controls · `backend/pipeline/evidence_verifier.py`
- [QuickML provider](https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/backend/ai/providers/quickml.py): model integration · Provider abstraction backed by QuickML service. · `backend/ai/providers/quickml.py`

### Data & Deployment

- [Case databases & FIR CSVs](https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/backend/ksp_demo.db): SQLite and raw data · SQLite operational data is seeded from raw FIR datasets. · `backend/ksp_demo.db`
- [Catalyst serverless deployment](https://github.com/gokulthiyagarajan/neural-justice-ksp-datathon/blob/main/functions/neural-justice-backend/main.py): production runtime · Hosts static frontend and alternate serverless backend handler. · `functions/neural-justice-backend/main.py`

## Connections

- SPA entry & routing → App shell & navigation: renders
- SPA entry & routing → Role dashboards: routes to
- Login, MFA & auth state → Role dashboards: scopes access
- App shell & navigation → Maps & network visuals: hosts
- API clients → FastAPI composition: HTTP requests
- Role dashboards → API clients: loads data through
- Copilot dock & state → API clients: submits prompts
- FastAPI composition → Operational domain routes: mounts
- FastAPI composition → CP views API: mounts
- FastAPI composition → Copilot HTTP boundary: mounts
- Operational domain routes → Case databases & FIR CSVs: reads and writes
- CP views API → Case databases & FIR CSVs: queries
- Copilot HTTP boundary → Copilot authorization: authenticates
- Copilot authorization → Chat intent & execution: permits request
- Chat intent & execution → Case databases & FIR CSVs: retrieves context
- Chat intent & execution → Evidence reasoning orchestration: invokes reasoning
- Evidence reasoning orchestration → Generation through final assembly: runs stages
- Generation through final assembly → Evidence verification & cache: verifies output
- Generation through final assembly → QuickML provider: uses models
- Catalyst serverless deployment → FastAPI composition: alternate deployment
