# jayanthmb14/forthepeople architecture

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

- Interactive diagram: https://gitdiagram.com/jayanthmb14/forthepeople
- Repository: https://github.com/jayanthmb14/forthepeople

## Overview

#### Purpose and Runtime
ForThePeople.in is a district-level Indian civic-transparency platform: public government data is normalized into citizen dashboards, national modules, tender views, and community/support features. It runs as a TypeScript Next.js App Router application, with Prisma-backed PostgreSQL, Redis caching, and a separate scraper runtime/container.
- `src/app/page.tsx`
- `src/app/[locale]/[state]/[district]/page.tsx`
- `Dockerfile.scraper`

#### Public Routing and Presentation
The principal public entry is locale-aware routing, followed by state/district/taluk/village drill-down. A district layout establishes shared navigation/context while module pages render domain dashboards. The national “India” area is a parallel module hierarchy rather than a district module.
- `src/app/[locale]/[state]/[district]/layout.tsx`
- `src/app/[locale]/[state]/[district]/[taluk]/page.tsx`
- `src/app/[locale]/india/[moduleSlug]/page.tsx`

#### Data Model and Geographic Foundation
Prisma is the system-of-record boundary for 45+ domain models: district hierarchy, dashboard data, content, subscriptions, tenders, audit/admin state, and generated insights. Seeds bootstrap and expand district/national records. Static GeoJSON supplies client map boundaries, separate from operational data in PostgreSQL.
- `prisma/schema.prisma`
- `prisma/seed.ts`
- `public/geo/india-states.json`

#### Read APIs, Caching, and Client Consumption
Server route handlers expose module-oriented data APIs to dashboard components and hooks. The generic module endpoint is the primary abstraction for district data retrieval, with dedicated endpoints for cross-cutting computed views such as health, freshness, insights, and public district data. Redis provides the cache boundary; database access is centralized in the DB library.
- `src/app/api/data/[module]/route.ts`
- `src/hooks/useDistrictData.ts`
- `src/lib/db.ts`
- `src/lib/redis.ts`

#### Ingestion, Scheduling, and AI Enrichment
A scraper subsystem runs scheduled jobs for government/RSS-derived datasets and writes normalized records. Tender ingestion is a specialized orchestration pipeline over portal-specific engines, PDF parsing, red-flag computation, alerts, and AI enrichment. Next cron routes expose scheduled triggers for scraping, news intelligence, and insight generation; the scraper runtime is intended for Railway.
- `src/scraper/scheduler.ts`
- `src/scraper/tender-orchestrator.ts`
- `src/scraper/engines/nicgep-engine.ts`
- `src/app/api/cron/news-intelligence/route.ts`

#### Administration, Trust, and Operations
An authenticated admin surface controls content, review, data verification, operational health, AI settings, feedback, supporters, vault access, and scraper actions. Security includes admin authentication, TOTP/2FA API flows, encrypted vault data, session controls, audit logging, and rate limiting. Sentry and Plausible are integrated for errors and analytics; Resend supports alerts.
- `src/app/[locale]/admin/page.tsx`
- `src/app/api/admin/verify-data/route.ts`
- `src/lib/admin-auth.ts`
- `src/lib/audit-log.ts`

#### Contributions and External Services
Supporter checkout creates and verifies Razorpay orders/subscriptions; Razorpay webhooks reconcile payment events into persisted supporter/subscription state. AI uses an OpenRouter-oriented provider abstraction with fallback support for classification and generated analyses. Production infrastructure targets Vercel for the web/API runtime, Neon PostgreSQL, Upstash Redis, Railway scraping, Razorpay, Sentry, Plausible, and Resend.
- `src/app/api/payment/create-order/route.ts`
- `src/app/api/webhooks/razorpay/route.ts`
- `src/lib/razorpay.ts`
- `src/lib/ai-provider.ts`

Main entry points: [`prisma/schema.prisma`](https://github.com/jayanthmb14/forthepeople/blob/main/prisma/schema.prisma) (PostgreSQL system of record), [`src/app/[locale]/[state]/[district]/page.tsx`](https://github.com/jayanthmb14/forthepeople/blob/main/src/app/%5Blocale%5D/%5Bstate%5D/%5Bdistrict%5D/page.tsx) (District drill-down), [`src/app/api/data/[module]/route.ts`](https://github.com/jayanthmb14/forthepeople/blob/main/src/app/api/data/%5Bmodule%5D/route.ts) (Module data API), [`src/scraper/scheduler.ts`](https://github.com/jayanthmb14/forthepeople/blob/main/src/scraper/scheduler.ts) (Scraper scheduler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public["Public experience"]
  node_home["Public entry<br/>Next.js page<br/>[page.tsx]"]
  node_district_routes["District drill-down<br/>App Router pages<br/>[page.tsx]"]
  node_district_layout["District shared layout<br/>App Router layout<br/>[layout.tsx]"]
  node_india_modules["India modules<br/>App Router pages<br/>[page.tsx]"]
  node_client_data["Dashboard data hook<br/>React hook<br/>[useDistrictData.ts]"]
end

subgraph group_data["Data foundation"]
  node_api_modules{{"Module data API<br/>Next.js route handler<br/>[route.ts]"}}
  node_db_library["Database access<br/>Prisma DB library<br/>[db.ts]"]
  node_postgres[("PostgreSQL system of record<br/>Neon PostgreSQL<br/>[schema.prisma]")]
  node_seeds["Data bootstrap seeds<br/>Prisma seed<br/>[seed.ts]"]
  node_redis[("Redis cache<br/>Upstash Redis<br/>[redis.ts]")]
  node_geojson["India map boundaries<br/>Static GeoJSON<br/>[india-states.json]"]
end

subgraph group_ingestion["Ingestion &amp; intelligence"]
  node_scraper_scheduler["Scraper scheduler<br/>Scraper runtime<br/>[scheduler.ts]"]
  node_tender_pipeline["Tender orchestration<br/>Scraper pipeline"]
  node_nicgep["NICGeP tender engine<br/>Portal scraper<br/>[nicgep-engine.ts]"]
  node_news_cron{{"News intelligence cron<br/>Next.js cron route<br/>[route.ts]"}}
  node_ai_provider["AI provider abstraction<br/>OpenRouter provider<br/>[ai-provider.ts]"]
  node_scraper_container["Railway scraper container<br/>Docker runtime<br/>[Dockerfile.scraper]"]
end

subgraph group_admin["Administration &amp; trust"]
  node_admin["Admin operations<br/>Authenticated admin surface<br/>[page.tsx]"]
  node_admin_verify{{"Data verification API<br/>Admin route handler<br/>[route.ts]"}}
  node_admin_auth["Admin authentication<br/>Security library<br/>[admin-auth.ts]"]
  node_audit_log["Audit logging<br/>Trust library<br/>[audit-log.ts]"]
end

subgraph group_external["Production services"]
  node_payments{{"Supporter checkout<br/>Payment route<br/>[route.ts]"}}
  node_razorpay_webhook{{"Razorpay reconciliation<br/>Webhook route<br/>[route.ts]"}}
  node_razorpay["Razorpay client<br/>Payment library<br/>[razorpay.ts]"]
  node_razorpay_service(("Razorpay<br/>External payment service"))
end

node_home -->|"enters locality"| node_district_routes
node_district_routes -->|"shares context"| node_district_layout
node_district_routes -->|"renders dashboards"| node_client_data
node_india_modules -->|"loads module data"| node_client_data
node_client_data -->|"fetches"| node_api_modules
node_api_modules -->|"reads/writes cache"| node_redis
node_api_modules -->|"queries"| node_db_library
node_db_library -->|"persists"| node_postgres
node_seeds -->|"bootstraps"| node_postgres
node_district_routes -.->|"map boundaries"| node_geojson
node_scraper_container -->|"runs"| node_scraper_scheduler
node_scraper_scheduler -->|"schedules"| node_tender_pipeline
node_tender_pipeline -->|"uses portal engine"| node_nicgep
node_tender_pipeline -->|"enriches"| node_ai_provider
node_scraper_scheduler -->|"writes normalized records"| node_postgres
node_news_cron -->|"generates intelligence"| node_ai_provider
node_news_cron -->|"stores insights"| node_postgres
node_admin -->|"authenticates"| node_admin_auth
node_admin -->|"verifies data"| node_admin_verify
node_admin_verify -->|"updates records"| node_db_library
node_admin_verify -->|"records action"| node_audit_log
node_audit_log -->|"persists"| node_postgres
node_payments -->|"creates order"| node_razorpay
node_razorpay -->|"calls"| node_razorpay_service
node_razorpay_service -->|"payment event"| node_razorpay_webhook
node_razorpay_webhook -->|"reconciles state"| node_postgres

click node_home "https://github.com/jayanthmb14/forthepeople/blob/main/src/app/page.tsx"
click node_district_routes "https://github.com/jayanthmb14/forthepeople/blob/main/src/app/%5Blocale%5D/%5Bstate%5D/%5Bdistrict%5D/page.tsx"
click node_district_layout "https://github.com/jayanthmb14/forthepeople/blob/main/src/app/%5Blocale%5D/%5Bstate%5D/%5Bdistrict%5D/layout.tsx"
click node_india_modules "https://github.com/jayanthmb14/forthepeople/blob/main/src/app/%5Blocale%5D/india/%5BmoduleSlug%5D/page.tsx"
click node_client_data "https://github.com/jayanthmb14/forthepeople/blob/main/src/hooks/useDistrictData.ts"
click node_api_modules "https://github.com/jayanthmb14/forthepeople/blob/main/src/app/api/data/%5Bmodule%5D/route.ts"
click node_db_library "https://github.com/jayanthmb14/forthepeople/blob/main/src/lib/db.ts"
click node_postgres "https://github.com/jayanthmb14/forthepeople/blob/main/prisma/schema.prisma"
click node_seeds "https://github.com/jayanthmb14/forthepeople/blob/main/prisma/seed.ts"
click node_redis "https://github.com/jayanthmb14/forthepeople/blob/main/src/lib/redis.ts"
click node_geojson "https://github.com/jayanthmb14/forthepeople/blob/main/public/geo/india-states.json"
click node_scraper_scheduler "https://github.com/jayanthmb14/forthepeople/blob/main/src/scraper/scheduler.ts"
click node_tender_pipeline "https://github.com/jayanthmb14/forthepeople/blob/main/src/scraper/tender-orchestrator.ts"
click node_nicgep "https://github.com/jayanthmb14/forthepeople/blob/main/src/scraper/engines/nicgep-engine.ts"
click node_news_cron "https://github.com/jayanthmb14/forthepeople/blob/main/src/app/api/cron/news-intelligence/route.ts"
click node_ai_provider "https://github.com/jayanthmb14/forthepeople/blob/main/src/lib/ai-provider.ts"
click node_admin "https://github.com/jayanthmb14/forthepeople/blob/main/src/app/%5Blocale%5D/admin/page.tsx"
click node_admin_verify "https://github.com/jayanthmb14/forthepeople/blob/main/src/app/api/admin/verify-data/route.ts"
click node_admin_auth "https://github.com/jayanthmb14/forthepeople/blob/main/src/lib/admin-auth.ts"
click node_audit_log "https://github.com/jayanthmb14/forthepeople/blob/main/src/lib/audit-log.ts"
click node_payments "https://github.com/jayanthmb14/forthepeople/blob/main/src/app/api/payment/create-order/route.ts"
click node_razorpay_webhook "https://github.com/jayanthmb14/forthepeople/blob/main/src/app/api/webhooks/razorpay/route.ts"
click node_razorpay "https://github.com/jayanthmb14/forthepeople/blob/main/src/lib/razorpay.ts"
click node_scraper_container "https://github.com/jayanthmb14/forthepeople/blob/main/Dockerfile.scraper"

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_home,node_district_routes,node_district_layout,node_india_modules,node_client_data toneBlue
class node_api_modules,node_db_library,node_postgres,node_seeds,node_redis,node_geojson toneAmber
class node_scraper_scheduler,node_tender_pipeline,node_nicgep,node_news_cron,node_ai_provider,node_scraper_container toneMint
class node_admin,node_admin_verify,node_admin_auth,node_audit_log toneRose
class node_payments,node_razorpay_webhook,node_razorpay,node_razorpay_service toneIndigo
```

## Components

### Public experience

- [Public entry](https://github.com/jayanthmb14/forthepeople/blob/main/src/app/page.tsx): Next.js page · `src/app/page.tsx`
- [District drill-down](https://github.com/jayanthmb14/forthepeople/blob/main/src/app/%5Blocale%5D/%5Bstate%5D/%5Bdistrict%5D/page.tsx): App Router pages · Locale, state, district, taluk, and village navigation. · `src/app/[locale]/[state]/[district]/page.tsx`
- [District shared layout](https://github.com/jayanthmb14/forthepeople/blob/main/src/app/%5Blocale%5D/%5Bstate%5D/%5Bdistrict%5D/layout.tsx): App Router layout · `src/app/[locale]/[state]/[district]/layout.tsx`
- [India modules](https://github.com/jayanthmb14/forthepeople/blob/main/src/app/%5Blocale%5D/india/%5BmoduleSlug%5D/page.tsx): App Router pages · Parallel national dashboard hierarchy. · `src/app/[locale]/india/[moduleSlug]/page.tsx`
- [Dashboard data hook](https://github.com/jayanthmb14/forthepeople/blob/main/src/hooks/useDistrictData.ts): React hook · `src/hooks/useDistrictData.ts`

### Data foundation

- [Module data API](https://github.com/jayanthmb14/forthepeople/blob/main/src/app/api/data/%5Bmodule%5D/route.ts): Next.js route handler · Primary district module retrieval abstraction. · `src/app/api/data/[module]/route.ts`
- [Database access](https://github.com/jayanthmb14/forthepeople/blob/main/src/lib/db.ts): Prisma DB library · Centralized application database access. · `src/lib/db.ts`
- [PostgreSQL system of record](https://github.com/jayanthmb14/forthepeople/blob/main/prisma/schema.prisma): Neon PostgreSQL · District hierarchy, dashboards, content, tenders, subscriptions, audit state, and insights. · `prisma/schema.prisma`
- [Data bootstrap seeds](https://github.com/jayanthmb14/forthepeople/blob/main/prisma/seed.ts): Prisma seed · `prisma/seed.ts`
- [Redis cache](https://github.com/jayanthmb14/forthepeople/blob/main/src/lib/redis.ts): Upstash Redis · `src/lib/redis.ts`
- [India map boundaries](https://github.com/jayanthmb14/forthepeople/blob/main/public/geo/india-states.json): Static GeoJSON · Client map geometry is separate from operational records. · `public/geo/india-states.json`

### Ingestion & intelligence

- [Scraper scheduler](https://github.com/jayanthmb14/forthepeople/blob/main/src/scraper/scheduler.ts): Scraper runtime · Scheduled government and RSS dataset ingestion. · `src/scraper/scheduler.ts`
- [Tender orchestration](https://github.com/jayanthmb14/forthepeople/blob/main/src/scraper/tender-orchestrator.ts): Scraper pipeline · Portal engines, PDF parsing, red flags, alerts, and AI enrichment. · `src/scraper/tender-orchestrator.ts`
- [NICGeP tender engine](https://github.com/jayanthmb14/forthepeople/blob/main/src/scraper/engines/nicgep-engine.ts): Portal scraper · `src/scraper/engines/nicgep-engine.ts`
- [News intelligence cron](https://github.com/jayanthmb14/forthepeople/blob/main/src/app/api/cron/news-intelligence/route.ts): Next.js cron route · `src/app/api/cron/news-intelligence/route.ts`
- [AI provider abstraction](https://github.com/jayanthmb14/forthepeople/blob/main/src/lib/ai-provider.ts): OpenRouter provider · Classification and generated analysis with fallback support. · `src/lib/ai-provider.ts`
- [Railway scraper container](https://github.com/jayanthmb14/forthepeople/blob/main/Dockerfile.scraper): Docker runtime · Separate scraper deployment runtime. · `Dockerfile.scraper`

### Administration & trust

- [Admin operations](https://github.com/jayanthmb14/forthepeople/blob/main/src/app/%5Blocale%5D/admin/page.tsx): Authenticated admin surface · Content, review, verification, health, feedback, supporters, vault, and scraper controls. · `src/app/[locale]/admin/page.tsx`
- [Data verification API](https://github.com/jayanthmb14/forthepeople/blob/main/src/app/api/admin/verify-data/route.ts): Admin route handler · `src/app/api/admin/verify-data/route.ts`
- [Admin authentication](https://github.com/jayanthmb14/forthepeople/blob/main/src/lib/admin-auth.ts): Security library · Admin sessions and TOTP/2FA controls. · `src/lib/admin-auth.ts`
- [Audit logging](https://github.com/jayanthmb14/forthepeople/blob/main/src/lib/audit-log.ts): Trust library · `src/lib/audit-log.ts`

### Production services

- [Supporter checkout](https://github.com/jayanthmb14/forthepeople/blob/main/src/app/api/payment/create-order/route.ts): Payment route · Creates Razorpay orders and subscriptions. · `src/app/api/payment/create-order/route.ts`
- [Razorpay reconciliation](https://github.com/jayanthmb14/forthepeople/blob/main/src/app/api/webhooks/razorpay/route.ts): Webhook route · Persists reconciled payment events. · `src/app/api/webhooks/razorpay/route.ts`
- [Razorpay client](https://github.com/jayanthmb14/forthepeople/blob/main/src/lib/razorpay.ts): Payment library · `src/lib/razorpay.ts`
- **Razorpay**: External payment service

## Connections

- Public entry → District drill-down: enters locality
- District drill-down → District shared layout: shares context
- District drill-down → Dashboard data hook: renders dashboards
- India modules → Dashboard data hook: loads module data
- Dashboard data hook → Module data API: fetches
- Module data API → Redis cache: reads/writes cache
- Module data API → Database access: queries
- Database access → PostgreSQL system of record: persists
- Data bootstrap seeds → PostgreSQL system of record: bootstraps
- District drill-down → India map boundaries: map boundaries
- Railway scraper container → Scraper scheduler: runs
- Scraper scheduler → Tender orchestration: schedules
- Tender orchestration → NICGeP tender engine: uses portal engine
- Tender orchestration → AI provider abstraction: enriches
- Scraper scheduler → PostgreSQL system of record: writes normalized records
- News intelligence cron → AI provider abstraction: generates intelligence
- News intelligence cron → PostgreSQL system of record: stores insights
- Admin operations → Admin authentication: authenticates
- Admin operations → Data verification API: verifies data
- Data verification API → Database access: updates records
- Data verification API → Audit logging: records action
- Audit logging → PostgreSQL system of record: persists
- Supporter checkout → Razorpay client: creates order
- Razorpay client → Razorpay: calls
- Razorpay → Razorpay reconciliation: payment event
- Razorpay reconciliation → PostgreSQL system of record: reconciles state
