# nandani1512/tvs architecture

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

- Interactive diagram: https://gitdiagram.com/nandani1512/tvs
- Repository: https://github.com/nandani1512/tvs

## Overview

This is a farmer-loan application and credit decision platform, with staff review and administration. Farmers enter profile and plot details, submit an application, and receive a score and offer; staff review applications and manage users and roles. The map also preserves consent, assistant, monitoring, offline/PWA, and geospatial scoring capabilities visible in the tree. Edges follow excerpted calls or SOURCE INDEX references; unsampled routes and integrations are shown only where those references support the connection.

Main entry points: [`app/api/applications/route.ts`](https://github.com/nandani1512/tvs/blob/main/app/api/applications/route.ts) (Application API), [`app/(farmer)/apply/page.tsx`](https://github.com/nandani1512/tvs/blob/main/app/(farmer)/apply/page.tsx) (Loan application), [`app/(staff)/scoring/ScoringClient.tsx`](https://github.com/nandani1512/tvs/blob/main/app/(staff)/scoring/ScoringClient.tsx) (Score review), [`app/api/ml-score/route.ts`](https://github.com/nandani1512/tvs/blob/main/app/api/ml-score/route.ts) (ML score API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_farmer["Farmer experience"]
  node_apply["Loan application<br/>[page.tsx]"]
  node_plot_map["Plot capture<br/>[PlotCaptureMap.tsx]"]
  node_farmer_assistant["Farmer assistant<br/>[page.tsx]"]
  node_voice["Voice input<br/>[VoiceButtons.tsx]"]
  node_consent["Consent<br/>[ConsentClient.tsx]"]
  node_kfs["Key fact statement<br/>[page.tsx]"]
end

subgraph group_staff["Staff operations"]
  node_staff_scoring["Score review<br/>[ScoringClient.tsx]"]
  node_monitoring["Monitoring"]
  node_role_admin["Role administration"]
  node_staff_management["Staff management<br/>[StaffClient.tsx]"]
end

subgraph group_api["Application services"]
  node_application_api["Application API<br/>[route.ts]"]
  node_consent_api["Consent API<br/>[route.ts]"]
  node_assistant_api["Assistant API<br/>[route.ts]"]
  node_ml_api["ML score API<br/>[route.ts]"]
  node_geospatial_ml["Geospatial ML service<br/>[service.py]"]
  node_weather["Weather telemetry<br/>[weather.ts]"]
  node_satellite["Satellite vegetation<br/>[copernicus.ts]"]
  node_soil["Soil profile<br/>[soil.ts]"]
  node_market["Mandi data<br/>[mandi.ts]"]
  node_scoring_engine["Credit scoring engine<br/>[ml-scoring.ts]"]
end

subgraph group_data["Identity and data"]
  node_auth_dal["Session and authorization<br/>[dal.ts]"]
  node_roles["Role model<br/>[roles.ts]"]
  node_database[("Application database<br/>[index.ts]")]
end

subgraph group_platform["Supporting capabilities"]
  node_pwa_nav["Navigation and PWA controls<br/>[Navbar.tsx]"]
  node_connectivity["Connectivity handling<br/>[connectivity.ts]"]
  node_offline_drafts["Offline drafts<br/>[drafts.ts]"]
  node_push_client["Push client<br/>[client.ts]"]
  node_push_server["Push delivery<br/>[server.ts]"]
  node_gemini["Assistant model integration<br/>[gemini.ts]"]
  node_data_monitor["Monitoring data access<br/>[data.ts]"]
end

node_farmer(("Farmer"))
node_staff_actor(("Staff"))

node_farmer -->|"enters details"| node_apply
node_apply -->|"captures boundary"| node_plot_map
node_apply -->|"offers voice input"| node_voice
node_apply -->|"clears draft"| node_offline_drafts
node_apply -->|"submits application"| node_application_api
node_application_api -->|"authorizes request"| node_auth_dal
node_application_api -->|"reads and writes"| node_database
node_application_api -->|"fetches telemetry"| node_weather
node_application_api -->|"computes vegetation"| node_satellite
node_application_api -->|"fetches profile"| node_soil
node_application_api -->|"uses market data"| node_market
node_application_api -->|"computes decision"| node_scoring_engine
node_application_api -->|"sends decision alert"| node_push_server
node_staff_actor -->|"reviews score"| node_staff_scoring
node_staff_scoring -->|"fetches application"| node_application_api
node_staff_actor -->|"views monitoring"| node_monitoring
node_monitoring -->|"loads monitoring data"| node_data_monitor
node_staff_actor -->|"manages roles"| node_role_admin
node_role_admin -->|"uses role model"| node_roles
node_staff_actor -->|"manages staff"| node_staff_management
node_staff_management -->|"uses role model"| node_roles
node_farmer -->|"records consent"| node_consent
node_consent -.->|"submits consent"| node_consent_api
node_consent_api -->|"stores consent"| node_database
node_farmer -->|"asks for help"| node_farmer_assistant
node_farmer_assistant -.->|"sends prompt"| node_assistant_api
node_assistant_api -->|"requests response"| node_gemini
node_staff_scoring -.->|"requests score"| node_ml_api
node_ml_api -->|"proxies scoring request"| node_geospatial_ml
node_ml_api -->|"uses fallback engine"| node_scoring_engine
node_pwa_nav -->|"controls notifications"| node_push_client
node_pwa_nav -->|"clears user draft"| node_offline_drafts
node_apply -->|"checks connectivity"| node_connectivity
node_push_client -.->|"registers subscription"| node_push_server

click node_apply "https://github.com/nandani1512/tvs/blob/main/app/(farmer)/apply/page.tsx"
click node_plot_map "https://github.com/nandani1512/tvs/blob/main/app/(farmer)/apply/PlotCaptureMap.tsx"
click node_farmer_assistant "https://github.com/nandani1512/tvs/blob/main/app/(farmer)/assistant/page.tsx"
click node_voice "https://github.com/nandani1512/tvs/blob/main/app/components/voice/VoiceButtons.tsx"
click node_consent "https://github.com/nandani1512/tvs/blob/main/app/(farmer)/consent/ConsentClient.tsx"
click node_kfs "https://github.com/nandani1512/tvs/blob/main/app/(farmer)/kfs/%5Bid%5D/page.tsx"
click node_staff_scoring "https://github.com/nandani1512/tvs/blob/main/app/(staff)/scoring/ScoringClient.tsx"
click node_monitoring "https://github.com/nandani1512/tvs/blob/main/app/(staff)/monitoring/MonitoringClient.tsx"
click node_role_admin "https://github.com/nandani1512/tvs/blob/main/app/(staff)/admin/roles/AdminRolesClient.tsx"
click node_staff_management "https://github.com/nandani1512/tvs/blob/main/app/(staff)/staff/StaffClient.tsx"
click node_application_api "https://github.com/nandani1512/tvs/blob/main/app/api/applications/route.ts"
click node_consent_api "https://github.com/nandani1512/tvs/blob/main/app/api/consents/route.ts"
click node_assistant_api "https://github.com/nandani1512/tvs/blob/main/app/api/assistant/route.ts"
click node_ml_api "https://github.com/nandani1512/tvs/blob/main/app/api/ml-score/route.ts"
click node_geospatial_ml "https://github.com/nandani1512/tvs/blob/main/geo-ml/service.py"
click node_weather "https://github.com/nandani1512/tvs/blob/main/app/lib/services/weather.ts"
click node_satellite "https://github.com/nandani1512/tvs/blob/main/app/lib/services/copernicus.ts"
click node_soil "https://github.com/nandani1512/tvs/blob/main/app/lib/services/soil.ts"
click node_market "https://github.com/nandani1512/tvs/blob/main/app/lib/services/mandi.ts"
click node_scoring_engine "https://github.com/nandani1512/tvs/blob/main/app/lib/services/ml-scoring.ts"
click node_auth_dal "https://github.com/nandani1512/tvs/blob/main/app/lib/dal.ts"
click node_roles "https://github.com/nandani1512/tvs/blob/main/app/lib/roles.ts"
click node_database "https://github.com/nandani1512/tvs/blob/main/app/lib/db/index.ts"
click node_pwa_nav "https://github.com/nandani1512/tvs/blob/main/app/components/Navbar.tsx"
click node_connectivity "https://github.com/nandani1512/tvs/blob/main/app/components/pwa/connectivity.ts"
click node_offline_drafts "https://github.com/nandani1512/tvs/blob/main/app/lib/offline/drafts.ts"
click node_push_client "https://github.com/nandani1512/tvs/blob/main/app/lib/push/client.ts"
click node_push_server "https://github.com/nandani1512/tvs/blob/main/app/lib/push/server.ts"
click node_gemini "https://github.com/nandani1512/tvs/blob/main/app/lib/services/gemini.ts"
click node_data_monitor "https://github.com/nandani1512/tvs/blob/main/app/lib/data.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_apply,node_plot_map,node_farmer_assistant,node_voice,node_consent,node_kfs toneBlue
class node_staff_scoring,node_monitoring,node_role_admin,node_staff_management toneAmber
class node_application_api,node_consent_api,node_assistant_api,node_ml_api,node_geospatial_ml,node_weather,node_satellite,node_soil,node_market,node_scoring_engine toneMint
class node_auth_dal,node_roles,node_database toneRose
class node_pwa_nav,node_connectivity,node_offline_drafts,node_push_client,node_push_server,node_gemini,node_data_monitor,node_farmer,node_staff_actor toneIndigo
```

## Components

### Farmer experience

- [Loan application](https://github.com/nandani1512/tvs/blob/main/app/(farmer)/apply/page.tsx): `app/(farmer)/apply/page.tsx`
- [Plot capture](https://github.com/nandani1512/tvs/blob/main/app/(farmer)/apply/PlotCaptureMap.tsx): `app/(farmer)/apply/PlotCaptureMap.tsx`
- [Farmer assistant](https://github.com/nandani1512/tvs/blob/main/app/(farmer)/assistant/page.tsx): `app/(farmer)/assistant/page.tsx`
- [Voice input](https://github.com/nandani1512/tvs/blob/main/app/components/voice/VoiceButtons.tsx): `app/components/voice/VoiceButtons.tsx`
- [Consent](https://github.com/nandani1512/tvs/blob/main/app/(farmer)/consent/ConsentClient.tsx): `app/(farmer)/consent/ConsentClient.tsx`
- [Key fact statement](https://github.com/nandani1512/tvs/blob/main/app/(farmer)/kfs/%5Bid%5D/page.tsx): `app/(farmer)/kfs/[id]/page.tsx`

### Staff operations

- [Score review](https://github.com/nandani1512/tvs/blob/main/app/(staff)/scoring/ScoringClient.tsx): `app/(staff)/scoring/ScoringClient.tsx`
- [Monitoring](https://github.com/nandani1512/tvs/blob/main/app/(staff)/monitoring/MonitoringClient.tsx): `app/(staff)/monitoring/MonitoringClient.tsx`
- [Role administration](https://github.com/nandani1512/tvs/blob/main/app/(staff)/admin/roles/AdminRolesClient.tsx): `app/(staff)/admin/roles/AdminRolesClient.tsx`
- [Staff management](https://github.com/nandani1512/tvs/blob/main/app/(staff)/staff/StaffClient.tsx): `app/(staff)/staff/StaffClient.tsx`

### Application services

- [Application API](https://github.com/nandani1512/tvs/blob/main/app/api/applications/route.ts): `app/api/applications/route.ts`
- [Consent API](https://github.com/nandani1512/tvs/blob/main/app/api/consents/route.ts): `app/api/consents/route.ts`
- [Assistant API](https://github.com/nandani1512/tvs/blob/main/app/api/assistant/route.ts): `app/api/assistant/route.ts`
- [ML score API](https://github.com/nandani1512/tvs/blob/main/app/api/ml-score/route.ts): `app/api/ml-score/route.ts`
- [Geospatial ML service](https://github.com/nandani1512/tvs/blob/main/geo-ml/service.py): `geo-ml/service.py`
- [Weather telemetry](https://github.com/nandani1512/tvs/blob/main/app/lib/services/weather.ts): `app/lib/services/weather.ts`
- [Satellite vegetation](https://github.com/nandani1512/tvs/blob/main/app/lib/services/copernicus.ts): `app/lib/services/copernicus.ts`
- [Soil profile](https://github.com/nandani1512/tvs/blob/main/app/lib/services/soil.ts): `app/lib/services/soil.ts`
- [Mandi data](https://github.com/nandani1512/tvs/blob/main/app/lib/services/mandi.ts): `app/lib/services/mandi.ts`
- [Credit scoring engine](https://github.com/nandani1512/tvs/blob/main/app/lib/services/ml-scoring.ts): `app/lib/services/ml-scoring.ts`

### Identity and data

- [Session and authorization](https://github.com/nandani1512/tvs/blob/main/app/lib/dal.ts): `app/lib/dal.ts`
- [Role model](https://github.com/nandani1512/tvs/blob/main/app/lib/roles.ts): `app/lib/roles.ts`
- [Application database](https://github.com/nandani1512/tvs/blob/main/app/lib/db/index.ts): `app/lib/db/index.ts`

### Supporting capabilities

- [Navigation and PWA controls](https://github.com/nandani1512/tvs/blob/main/app/components/Navbar.tsx): `app/components/Navbar.tsx`
- [Connectivity handling](https://github.com/nandani1512/tvs/blob/main/app/components/pwa/connectivity.ts): `app/components/pwa/connectivity.ts`
- [Offline drafts](https://github.com/nandani1512/tvs/blob/main/app/lib/offline/drafts.ts): `app/lib/offline/drafts.ts`
- [Push client](https://github.com/nandani1512/tvs/blob/main/app/lib/push/client.ts): `app/lib/push/client.ts`
- [Push delivery](https://github.com/nandani1512/tvs/blob/main/app/lib/push/server.ts): `app/lib/push/server.ts`
- [Assistant model integration](https://github.com/nandani1512/tvs/blob/main/app/lib/services/gemini.ts): `app/lib/services/gemini.ts`
- [Monitoring data access](https://github.com/nandani1512/tvs/blob/main/app/lib/data.ts): `app/lib/data.ts`

### Other components

- **Farmer**
- **Staff**

## Connections

- Farmer → Loan application: enters details (evidence: `app/(farmer)/apply/page.tsx`)
- Loan application → Plot capture: captures boundary (evidence: `app/(farmer)/apply/page.tsx`)
- Loan application → Voice input: offers voice input (evidence: `app/(farmer)/apply/page.tsx`)
- Loan application → Offline drafts: clears draft (evidence: `app/(farmer)/apply/page.tsx`)
- Loan application → Application API: submits application (evidence: `app/(farmer)/apply/page.tsx`)
- Application API → Session and authorization: authorizes request (evidence: `app/api/applications/route.ts`)
- Application API → Application database: reads and writes (evidence: `app/api/applications/route.ts`)
- Application API → Weather telemetry: fetches telemetry (evidence: `app/api/applications/route.ts`)
- Application API → Satellite vegetation: computes vegetation (evidence: `app/api/applications/route.ts`)
- Application API → Soil profile: fetches profile (evidence: `app/api/applications/route.ts`)
- Application API → Mandi data: uses market data (evidence: `app/api/applications/route.ts`)
- Application API → Credit scoring engine: computes decision (evidence: `app/api/applications/route.ts`)
- Application API → Push delivery: sends decision alert (evidence: `app/api/applications/route.ts`)
- Staff → Score review: reviews score (evidence: `app/(staff)/scoring/ScoringClient.tsx`)
- Score review → Application API: fetches application (evidence: `app/(staff)/scoring/ScoringClient.tsx`)
- Staff → Monitoring: views monitoring (evidence: `app/(staff)/monitoring/MonitoringClient.tsx`)
- Monitoring → Monitoring data access: loads monitoring data (evidence: `app/(staff)/monitoring/MonitoringClient.tsx`)
- Staff → Role administration: manages roles (evidence: `app/(staff)/admin/roles/AdminRolesClient.tsx`)
- Role administration → Role model: uses role model (evidence: `app/(staff)/admin/roles/AdminRolesClient.tsx`)
- Staff → Staff management: manages staff (evidence: `app/(staff)/staff/StaffClient.tsx`)
- Staff management → Role model: uses role model (evidence: `app/(staff)/staff/StaffClient.tsx`)
- Farmer → Consent: records consent (evidence: `app/(farmer)/consent/ConsentClient.tsx`)
- Consent → Consent API: submits consent
- Consent API → Application database: stores consent (evidence: `app/api/consents/route.ts`)
- Farmer → Farmer assistant: asks for help (evidence: `app/(farmer)/assistant/page.tsx`)
- Farmer assistant → Assistant API: sends prompt
- Assistant API → Assistant model integration: requests response (evidence: `app/api/assistant/route.ts`)
- Score review → ML score API: requests score
- ML score API → Geospatial ML service: proxies scoring request (evidence: `app/api/ml-score/route.ts`)
- ML score API → Credit scoring engine: uses fallback engine (evidence: `app/api/ml-score/route.ts`)
- Navigation and PWA controls → Push client: controls notifications (evidence: `app/components/Navbar.tsx`)
- Navigation and PWA controls → Offline drafts: clears user draft (evidence: `app/components/Navbar.tsx`)
- Loan application → Connectivity handling: checks connectivity (evidence: `app/(farmer)/apply/page.tsx`)
- Push client → Push delivery: registers subscription
