# varun-pahuja/sih-proto architecture

> Architecture diagram of the GitHub repository varun-pahuja/sih-proto, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/varun-pahuja/sih-proto
- Repository: https://github.com/varun-pahuja/sih-proto

## Overview

Welfare Leakage Detection is a prototype for identifying suspicious welfare beneficiaries and routing findings into officer review, while citizens can submit and track grievances. Officers sign in, inspect dashboards and beneficiary records, review flags, and use reporting and insight views; citizen grievances provide a separate feedback channel. The web app calls an Express API, which exposes auth, officer, and citizen routes with server-side controls. README capabilities are included, but unsampled endpoint wiring is shown only at the route-module level; records and scoring are documented as mock or in-memory.

Main entry points: [`welfare-leakage/apps/web/src/App.tsx`](https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/web/src/App.tsx) (Portal routing), [`welfare-leakage/apps/web/src/utils/api.ts`](https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/web/src/utils/api.ts) (API client), [`welfare-leakage/apps/api/src/routes/auth.ts`](https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/api/src/routes/auth.ts) (Authentication routes), [`welfare-leakage/apps/api/src/routes/officer.ts`](https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/api/src/routes/officer.ts) (Officer operations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_portals["Web portals"]
  node_app["Portal routing<br/>[App.tsx]"]
  node_login["Role sign-in<br/>[LoginPage.tsx]"]
  node_authstate["Session handling<br/>[useAuth.tsx]"]
  node_dashboard["Officer dashboard<br/>[Dashboard.tsx]"]
  node_beneficiaries["Beneficiary search/detail"]
  node_flags["Flag review queue<br/>[FlagQueue.tsx]"]
  node_heatmap["Leak heatmap<br/>[Heatmap.tsx]"]
  node_insights["Model insights<br/>[MLInsights.tsx]"]
  node_reports["Reports/export<br/>[Reports.tsx]"]
  node_grievance["Grievance submission"]
  node_tracking["Grievance tracking<br/>[TrackGrievance.tsx]"]
  node_clientapi["API client<br/>[api.ts]"]
end

subgraph group_api["API services"]
  node_server["HTTP API<br/>[index.ts]"]
  node_authroutes["Authentication routes<br/>[auth.ts]"]
  node_officerroutes["Officer operations<br/>[officer.ts]"]
  node_citizenroutes["Citizen operations<br/>[citizen.ts]"]
end

subgraph group_security["Access and audit"]
  node_validation["Request validation<br/>[validation.ts]"]
  node_authmw["Auth and RBAC<br/>[auth.ts]"]
  node_audit["Audit logging<br/>[audit.ts]"]
  node_jwt["JWT utilities<br/>[jwt.ts]"]
end

subgraph group_records["Mock domain data"]
  node_mockrecords[("Mock beneficiary data<br/>[officer.ts]")]
  node_grievancerecords[("Mock grievance data<br/>[citizen.ts]")]
end

node_officer(("Officer/Admin"))
node_citizen(("Citizen"))

node_officer -->|"uses portal"| node_app
node_citizen -->|"uses portal"| node_app
node_app -->|"routes login"| node_login
node_app -->|"routes officer"| node_dashboard
node_app -->|"routes search"| node_beneficiaries
node_app -->|"routes review"| node_flags
node_app -->|"routes heatmap"| node_heatmap
node_app -->|"routes insights"| node_insights
node_app -->|"routes reports"| node_reports
node_app -->|"routes submit"| node_grievance
node_app -->|"routes tracking"| node_tracking
node_login -->|"signs in"| node_authstate
node_authstate -->|"sends auth requests"| node_clientapi
node_beneficiaries -->|"fetches records"| node_clientapi
node_grievance -->|"submits grievance"| node_clientapi
node_tracking -->|"looks up status"| node_clientapi
node_clientapi -->|"HTTP requests"| node_server
node_server -->|"dispatches auth"| node_authroutes
node_server -->|"dispatches officer"| node_officerroutes
node_server -->|"dispatches citizen"| node_citizenroutes
node_authroutes -->|"validates credentials"| node_validation
node_officerroutes -->|"validates requests"| node_validation
node_citizenroutes -->|"validates requests"| node_validation
node_authroutes -->|"issues tokens"| node_jwt
node_authroutes -->|"checks session"| node_authmw
node_authroutes -->|"records actions"| node_audit
node_officerroutes -->|"enforces access"| node_authmw
node_officerroutes -->|"records actions"| node_audit
node_citizenroutes -->|"reads/writes"| node_grievancerecords
node_officerroutes -->|"reads/writes"| node_mockrecords
node_dashboard -->|"loads KPIs"| node_clientapi
node_flags -->|"loads flags"| node_clientapi
node_heatmap -->|"loads metrics"| node_clientapi
node_insights -->|"loads model data"| node_clientapi
node_reports -->|"requests export"| node_clientapi

click node_app "https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/web/src/App.tsx"
click node_login "https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/web/src/pages/LoginPage.tsx"
click node_authstate "https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/web/src/hooks/useAuth.tsx"
click node_dashboard "https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/web/src/pages/officer/Dashboard.tsx"
click node_beneficiaries "https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/web/src/pages/officer/BeneficiarySearch.tsx"
click node_flags "https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/web/src/pages/officer/FlagQueue.tsx"
click node_heatmap "https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/web/src/pages/officer/Heatmap.tsx"
click node_insights "https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/web/src/pages/officer/MLInsights.tsx"
click node_reports "https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/web/src/pages/officer/Reports.tsx"
click node_grievance "https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/web/src/pages/citizen/SubmitGrievance.tsx"
click node_tracking "https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/web/src/pages/citizen/TrackGrievance.tsx"
click node_clientapi "https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/web/src/utils/api.ts"
click node_server "https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/api/src/index.ts"
click node_authroutes "https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/api/src/routes/auth.ts"
click node_officerroutes "https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/api/src/routes/officer.ts"
click node_citizenroutes "https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/api/src/routes/citizen.ts"
click node_validation "https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/api/src/routes/validation.ts"
click node_authmw "https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/api/src/middleware/auth.ts"
click node_audit "https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/api/src/middleware/audit.ts"
click node_jwt "https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/api/src/utils/jwt.ts"
click node_mockrecords "https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/api/src/routes/officer.ts"
click node_grievancerecords "https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/api/src/routes/citizen.ts"

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_login,node_authstate,node_dashboard,node_beneficiaries,node_flags,node_heatmap,node_insights,node_reports,node_grievance,node_tracking,node_clientapi toneBlue
class node_server,node_authroutes,node_officerroutes,node_citizenroutes toneAmber
class node_validation,node_authmw,node_audit,node_jwt toneMint
class node_mockrecords,node_grievancerecords toneRose
class node_officer,node_citizen toneIndigo
```

## Components

### Web portals

- [Portal routing](https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/web/src/App.tsx): `welfare-leakage/apps/web/src/App.tsx`
- [Role sign-in](https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/web/src/pages/LoginPage.tsx): `welfare-leakage/apps/web/src/pages/LoginPage.tsx`
- [Session handling](https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/web/src/hooks/useAuth.tsx): `welfare-leakage/apps/web/src/hooks/useAuth.tsx`
- [Officer dashboard](https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/web/src/pages/officer/Dashboard.tsx): `welfare-leakage/apps/web/src/pages/officer/Dashboard.tsx`
- [Beneficiary search/detail](https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/web/src/pages/officer/BeneficiarySearch.tsx): `welfare-leakage/apps/web/src/pages/officer/BeneficiarySearch.tsx`
- [Flag review queue](https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/web/src/pages/officer/FlagQueue.tsx): `welfare-leakage/apps/web/src/pages/officer/FlagQueue.tsx`
- [Leak heatmap](https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/web/src/pages/officer/Heatmap.tsx): `welfare-leakage/apps/web/src/pages/officer/Heatmap.tsx`
- [Model insights](https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/web/src/pages/officer/MLInsights.tsx): `welfare-leakage/apps/web/src/pages/officer/MLInsights.tsx`
- [Reports/export](https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/web/src/pages/officer/Reports.tsx): `welfare-leakage/apps/web/src/pages/officer/Reports.tsx`
- [Grievance submission](https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/web/src/pages/citizen/SubmitGrievance.tsx): `welfare-leakage/apps/web/src/pages/citizen/SubmitGrievance.tsx`
- [Grievance tracking](https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/web/src/pages/citizen/TrackGrievance.tsx): `welfare-leakage/apps/web/src/pages/citizen/TrackGrievance.tsx`
- [API client](https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/web/src/utils/api.ts): `welfare-leakage/apps/web/src/utils/api.ts`

### API services

- [HTTP API](https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/api/src/index.ts): `welfare-leakage/apps/api/src/index.ts`
- [Authentication routes](https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/api/src/routes/auth.ts): `welfare-leakage/apps/api/src/routes/auth.ts`
- [Officer operations](https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/api/src/routes/officer.ts): `welfare-leakage/apps/api/src/routes/officer.ts`
- [Citizen operations](https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/api/src/routes/citizen.ts): `welfare-leakage/apps/api/src/routes/citizen.ts`

### Access and audit

- [Request validation](https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/api/src/routes/validation.ts): `welfare-leakage/apps/api/src/routes/validation.ts`
- [Auth and RBAC](https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/api/src/middleware/auth.ts): `welfare-leakage/apps/api/src/middleware/auth.ts`
- [Audit logging](https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/api/src/middleware/audit.ts): `welfare-leakage/apps/api/src/middleware/audit.ts`
- [JWT utilities](https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/api/src/utils/jwt.ts): `welfare-leakage/apps/api/src/utils/jwt.ts`

### Mock domain data

- [Mock beneficiary data](https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/api/src/routes/officer.ts): `welfare-leakage/apps/api/src/routes/officer.ts`
- [Mock grievance data](https://github.com/varun-pahuja/sih-proto/blob/main/welfare-leakage/apps/api/src/routes/citizen.ts): `welfare-leakage/apps/api/src/routes/citizen.ts`

### Other components

- **Officer/Admin**
- **Citizen**

## Connections

- Officer/Admin → Portal routing: uses portal
- Citizen → Portal routing: uses portal
- Portal routing → Role sign-in: routes login
- Portal routing → Officer dashboard: routes officer
- Portal routing → Beneficiary search/detail: routes search
- Portal routing → Flag review queue: routes review
- Portal routing → Leak heatmap: routes heatmap
- Portal routing → Model insights: routes insights
- Portal routing → Reports/export: routes reports
- Portal routing → Grievance submission: routes submit
- Portal routing → Grievance tracking: routes tracking
- Role sign-in → Session handling: signs in
- Session handling → API client: sends auth requests
- Beneficiary search/detail → API client: fetches records
- Grievance submission → API client: submits grievance
- Grievance tracking → API client: looks up status
- API client → HTTP API: HTTP requests
- HTTP API → Authentication routes: dispatches auth
- HTTP API → Officer operations: dispatches officer
- HTTP API → Citizen operations: dispatches citizen
- Authentication routes → Request validation: validates credentials
- Officer operations → Request validation: validates requests
- Citizen operations → Request validation: validates requests
- Authentication routes → JWT utilities: issues tokens
- Authentication routes → Auth and RBAC: checks session
- Authentication routes → Audit logging: records actions
- Officer operations → Auth and RBAC: enforces access
- Officer operations → Audit logging: records actions
- Citizen operations → Mock grievance data: reads/writes
- Officer operations → Mock beneficiary data: reads/writes
- Officer dashboard → API client: loads KPIs
- Flag review queue → API client: loads flags
- Leak heatmap → API client: loads metrics
- Model insights → API client: loads model data
- Reports/export → API client: requests export
