How gokulthiyagarajan/neural-justice-ksp-datathon works
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.
Components 19
React SPA
- SPA entry & routing
frontend/src/main.tsx - App shell & navigation · Jurisdiction-aware layout and role navigation.
frontend/src/components/Layout/AppLayout.tsx - Role dashboards · Selects CP, SP, PI, PSI, and PC workflows.
frontend/src/pages/dashboards/DashboardRouter.tsx - Login, MFA & auth state
frontend/src/auth/LoginFlow.tsx - API clients · Includes FIR and copilot clients.
frontend/src/api/client.ts - Copilot dock & state
frontend/src/copilot/CopilotDock.tsx - Maps & network visuals · Geo command, map provider, and criminal network canvas.
frontend/src/pages/GeoCommandPage.tsx
FastAPI Service
- FastAPI composition
backend/api/main.py - Operational domain routes · Cases, dashboards, stations, patrol, profiles, notifications, and patterns.
backend/api/routes/cases.py - CP views API
backend/api/routes/cp.py - Copilot HTTP boundary
backend/api/routes/copilot.py - Copilot authorization · Applies authentication and jurisdictional access.
backend/api/copilot/auth.py
AI & Reasoning
- Chat intent & execution · Detects intent, retrieves context, executes queries, and formats answers.
backend/api/copilot/chat_pipeline.py - Evidence reasoning orchestration · Routes multi-stage evidence-oriented reasoning.
backend/pipeline/orchestrator.py - Generation through final assembly · Critical review, deep reasoning, consistency checks, and final engine.
backend/pipeline/stage_1_generation.py - Evidence verification & cache
backend/pipeline/evidence_verifier.py - QuickML provider · Provider abstraction backed by QuickML service.
backend/ai/providers/quickml.py
Data & Deployment
- Case databases & FIR CSVs · SQLite operational data is seeded from raw FIR datasets.
backend/ksp_demo.db - Catalyst serverless deployment · Hosts static frontend and alternate serverless backend handler.
functions/neural-justice-backend/main.py
Connections 20
- 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