# nikhilll-dev-code/kosh-drishti architecture

> Architecture diagram of the GitHub repository nikhilll-dev-code/kosh-drishti, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nikhilll-dev-code/kosh-drishti
- Repository: https://github.com/nikhilll-dev-code/kosh-drishti

## Overview

Kosh-Drishti screens MPLADS constituency and work records for unusual financial patterns, then gives auditors a prioritized investigation queue with evidence-based explanations. The backend ingests data, applies R1–R6 rules and Isolation Forest signals, computes composite risk, and creates or updates cases; auditors review and act through the dashboard. The README documents the Python ML service and major analytics capabilities; source excerpts are incomplete, so unsampled UI-to-endpoint relationships are not asserted.

Main entry points: [`backend/src/controllers/apiControllers.js`](https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/backend/src/controllers/apiControllers.js) (API handlers), [`frontend/src/App.jsx`](https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/frontend/src/App.jsx) (Application router), [`backend/src/services/ruleEngineService.js`](https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/backend/src/services/ruleEngineService.js) (Rules and scoring), [`backend/src/models/store.js`](https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/backend/src/models/store.js) (JSON data store)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Auditor dashboard"]
  node_app["Application router<br/>[App.jsx]"]
  node_home["Dashboard<br/>[Home.jsx]"]
  node_state["State analytics<br/>[StateView.jsx]"]
  node_mp["MP profile<br/>[MPProfile.jsx]"]
  node_works["Works browser<br/>[WorksList.jsx]"]
  node_work["Work investigation<br/>[WorkDetail.jsx]"]
  node_queue["Case queue<br/>[CaseQueue.jsx]"]
  node_admin["Data administration<br/>[AdminPanel.jsx]"]
  node_authcontext["Session context<br/>[AuthContext.jsx]"]
  node_topbar["Navigation<br/>[TopBar.jsx]"]
end

subgraph group_api["API and governance"]
  node_routes["REST routes<br/>[apiRoutes.js]"]
  node_controllers["API handlers<br/>[apiControllers.js]"]
  node_auth["Access control<br/>[auth.js]"]
end

subgraph group_risk["Risk analysis"]
  node_rules["Rules and scoring"]
  node_features["Feature extraction"]
  node_duplicates["Duplicate matching"]
  node_explanation["Risk explanation<br/>[groqService.js]"]
  node_mlclient["ML HTTP client<br/>[mlService.js]"]
end

subgraph group_data["Data and persistence"]
  node_ingest["CSV ingestion<br/>[ingestService.js]"]
  node_store[("JSON data store<br/>[store.js]")]
  node_seed["Demo seeding<br/>[seedData.js]"]
end

subgraph group_ml["ML service"]
  node_mlapi["Scoring API<br/>[main.py]"]
  node_forest["Isolation Forest"]
  node_explainer["Python explainer<br/>[explainer.py]"]
end

node_auditor(("Auditor"))

node_app -->|"routes to"| node_home
node_app -->|"routes to"| node_state
node_app -->|"routes to"| node_mp
node_app -->|"routes to"| node_works
node_app -->|"routes to"| node_work
node_app -->|"routes to"| node_queue
node_app -->|"routes to"| node_admin
node_app -->|"provides"| node_authcontext
node_app -->|"renders"| node_topbar
node_auditor -.->|"uses"| node_app
node_routes -->|"dispatches"| node_controllers
node_routes -->|"guards"| node_auth
node_controllers -->|"reads and writes"| node_store
node_controllers -->|"runs scoring"| node_rules
node_controllers -->|"imports data"| node_ingest
node_controllers -->|"requests explanation"| node_explanation
node_auth -->|"looks up users"| node_store
node_seed -->|"seeds records"| node_store
node_seed -->|"uses scoring"| node_rules
node_ingest -->|"saves records"| node_store
node_rules -->|"reads and updates"| node_store
node_rules -->|"extracts features"| node_features
node_rules -->|"checks duplicates"| node_duplicates
node_rules -->|"requests scores"| node_mlclient
node_mlclient -.->|"sends features"| node_mlapi
node_mlapi -->|"scores vectors"| node_forest
node_mlapi -->|"generates text"| node_explainer
node_rules -.->|"prepares evidence"| node_explanation
node_rules -->|"creates cases"| node_store
node_auditor -.->|"investigates"| node_queue
node_admin -->|"calls REST API"| node_controllers
node_home -.->|"loads analytics"| node_controllers
node_state -.->|"loads state data"| node_controllers
node_mp -.->|"loads MP data"| node_controllers
node_works -.->|"loads work data"| node_controllers
node_work -.->|"loads work detail"| node_controllers
node_queue -.->|"loads cases"| node_controllers

click node_app "https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/frontend/src/App.jsx"
click node_home "https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/frontend/src/pages/Home.jsx"
click node_state "https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/frontend/src/pages/StateView.jsx"
click node_mp "https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/frontend/src/pages/MPProfile.jsx"
click node_works "https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/frontend/src/pages/WorksList.jsx"
click node_work "https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/frontend/src/pages/WorkDetail.jsx"
click node_queue "https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/frontend/src/pages/CaseQueue.jsx"
click node_admin "https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/frontend/src/pages/AdminPanel.jsx"
click node_authcontext "https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/frontend/src/context/AuthContext.jsx"
click node_topbar "https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/frontend/src/components/TopBar.jsx"
click node_routes "https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/backend/src/routes/apiRoutes.js"
click node_controllers "https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/backend/src/controllers/apiControllers.js"
click node_auth "https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/backend/src/middleware/auth.js"
click node_ingest "https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/backend/src/services/ingestService.js"
click node_store "https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/backend/src/models/store.js"
click node_seed "https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/backend/src/seed/seedData.js"
click node_rules "https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/backend/src/services/ruleEngineService.js"
click node_features "https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/backend/src/services/featureExtractor.js"
click node_duplicates "https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/backend/src/services/duplicateDetectionService.js"
click node_explanation "https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/backend/src/services/groqService.js"
click node_mlclient "https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/backend/src/services/mlService.js"
click node_mlapi "https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/ml_service/app/main.py"
click node_forest "https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/ml_service/app/isolation_forest.py"
click node_explainer "https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/ml_service/app/explainer.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_app,node_home,node_state,node_mp,node_works,node_work,node_queue,node_admin,node_authcontext,node_topbar toneBlue
class node_routes,node_controllers,node_auth toneAmber
class node_rules,node_features,node_duplicates,node_explanation,node_mlclient toneMint
class node_ingest,node_store,node_seed toneRose
class node_mlapi,node_forest,node_explainer,node_auditor toneIndigo
```

## Components

### Auditor dashboard

- [Application router](https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Dashboard](https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/frontend/src/pages/Home.jsx): `frontend/src/pages/Home.jsx`
- [State analytics](https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/frontend/src/pages/StateView.jsx): `frontend/src/pages/StateView.jsx`
- [MP profile](https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/frontend/src/pages/MPProfile.jsx): `frontend/src/pages/MPProfile.jsx`
- [Works browser](https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/frontend/src/pages/WorksList.jsx): `frontend/src/pages/WorksList.jsx`
- [Work investigation](https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/frontend/src/pages/WorkDetail.jsx): `frontend/src/pages/WorkDetail.jsx`
- [Case queue](https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/frontend/src/pages/CaseQueue.jsx): `frontend/src/pages/CaseQueue.jsx`
- [Data administration](https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/frontend/src/pages/AdminPanel.jsx): `frontend/src/pages/AdminPanel.jsx`
- [Session context](https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/frontend/src/context/AuthContext.jsx): `frontend/src/context/AuthContext.jsx`
- [Navigation](https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/frontend/src/components/TopBar.jsx): `frontend/src/components/TopBar.jsx`

### API and governance

- [REST routes](https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/backend/src/routes/apiRoutes.js): `backend/src/routes/apiRoutes.js`
- [API handlers](https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/backend/src/controllers/apiControllers.js): `backend/src/controllers/apiControllers.js`
- [Access control](https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/backend/src/middleware/auth.js): `backend/src/middleware/auth.js`

### Risk analysis

- [Rules and scoring](https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/backend/src/services/ruleEngineService.js): `backend/src/services/ruleEngineService.js`
- [Feature extraction](https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/backend/src/services/featureExtractor.js): `backend/src/services/featureExtractor.js`
- [Duplicate matching](https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/backend/src/services/duplicateDetectionService.js): `backend/src/services/duplicateDetectionService.js`
- [Risk explanation](https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/backend/src/services/groqService.js): `backend/src/services/groqService.js`
- [ML HTTP client](https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/backend/src/services/mlService.js): `backend/src/services/mlService.js`

### Data and persistence

- [CSV ingestion](https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/backend/src/services/ingestService.js): `backend/src/services/ingestService.js`
- [JSON data store](https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/backend/src/models/store.js): `backend/src/models/store.js`
- [Demo seeding](https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/backend/src/seed/seedData.js): `backend/src/seed/seedData.js`

### ML service

- [Scoring API](https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/ml_service/app/main.py): `ml_service/app/main.py`
- [Isolation Forest](https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/ml_service/app/isolation_forest.py): `ml_service/app/isolation_forest.py`
- [Python explainer](https://github.com/nikhilll-dev-code/kosh-drishti/blob/main/ml_service/app/explainer.py): `ml_service/app/explainer.py`

### Other components

- **Auditor**

## Connections

- Application router → Dashboard: routes to (evidence: `frontend/src/App.jsx`)
- Application router → State analytics: routes to (evidence: `frontend/src/App.jsx`)
- Application router → MP profile: routes to (evidence: `frontend/src/App.jsx`)
- Application router → Works browser: routes to (evidence: `frontend/src/App.jsx`)
- Application router → Work investigation: routes to (evidence: `frontend/src/App.jsx`)
- Application router → Case queue: routes to (evidence: `frontend/src/App.jsx`)
- Application router → Data administration: routes to (evidence: `frontend/src/App.jsx`)
- Application router → Session context: provides (evidence: `frontend/src/App.jsx`)
- Application router → Navigation: renders (evidence: `frontend/src/App.jsx`)
- Auditor → Application router: uses
- REST routes → API handlers: dispatches (evidence: `backend/src/routes/apiRoutes.js`)
- REST routes → Access control: guards (evidence: `backend/src/routes/apiRoutes.js`)
- API handlers → JSON data store: reads and writes (evidence: `backend/src/controllers/apiControllers.js`)
- API handlers → Rules and scoring: runs scoring (evidence: `backend/src/controllers/apiControllers.js`)
- API handlers → CSV ingestion: imports data (evidence: `backend/src/controllers/apiControllers.js`)
- API handlers → Risk explanation: requests explanation (evidence: `backend/src/controllers/apiControllers.js`)
- Access control → JSON data store: looks up users (evidence: `backend/src/middleware/auth.js`)
- Demo seeding → JSON data store: seeds records (evidence: `backend/src/seed/seedData.js`)
- Demo seeding → Rules and scoring: uses scoring (evidence: `backend/src/seed/seedData.js`)
- CSV ingestion → JSON data store: saves records (evidence: `backend/src/services/ingestService.js`)
- Rules and scoring → JSON data store: reads and updates (evidence: `backend/src/services/ruleEngineService.js`)
- Rules and scoring → Feature extraction: extracts features (evidence: `backend/src/services/ruleEngineService.js`)
- Rules and scoring → Duplicate matching: checks duplicates (evidence: `backend/src/services/ruleEngineService.js`)
- Rules and scoring → ML HTTP client: requests scores (evidence: `backend/src/services/ruleEngineService.js`)
- ML HTTP client → Scoring API: sends features (evidence: `README.md`)
- Scoring API → Isolation Forest: scores vectors (evidence: `ml_service/app/main.py`)
- Scoring API → Python explainer: generates text (evidence: `ml_service/app/main.py`)
- Rules and scoring → Risk explanation: prepares evidence
- Rules and scoring → JSON data store: creates cases (evidence: `backend/src/services/ruleEngineService.js`)
- Auditor → Case queue: investigates (evidence: `README.md`)
- Data administration → API handlers: calls REST API (evidence: `frontend/src/pages/AdminPanel.jsx`)
- Dashboard → API handlers: loads analytics
- State analytics → API handlers: loads state data
- MP profile → API handlers: loads MP data
- Works browser → API handlers: loads work data
- Work investigation → API handlers: loads work detail
- Case queue → API handlers: loads cases
