# sakshamnagar2805/krishisahyog-ai architecture

> Architecture diagram of the GitHub repository sakshamnagar2805/krishisahyog-ai, 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/sakshamnagar2805/krishisahyog-ai
- Repository: https://github.com/sakshamnagar2805/krishisahyog-ai

## Overview

KrishiSahyog AI is a farmer-facing guidance kiosk, currently configured as an unauthenticated public-information shell; the README says records are demo data and verified public catalogs may be empty. The main public workflow is browsing verified schemes and policies, with separate research previews clearly marked unapproved. Other documented branches cover PMFBY, PACS, documents, grievances, and a multilingual voice assistant. The server also has source collection, extraction, review, and publication components. Edges reflect excerpts, SOURCE INDEX references, or README statements; unsampled wiring is not inferred.

Main entry points: [`src/App.tsx`](https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/src/App.tsx) (App shell), [`server/db/pool.ts`](https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/server/db/pool.ts) (PostgreSQL), [`server/ingestion/worker.ts`](https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/server/ingestion/worker.ts) (Source ingestion worker), [`server/research/previewApi.ts`](https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/server/research/previewApi.ts) (Local preview API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_farmer_ui["Farmer experience"]
  node_app["App shell<br/>[App.tsx]"]
  node_header["Navigation and voice<br/>[Header.tsx]"]
  node_sidebar["Service navigation<br/>[Sidebar.tsx]"]
  node_verified_services["Verified services"]
  node_farmer_services["PMFBY, PACS, documents, grievances"]
end

subgraph group_public_info["Public information"]
  node_content_client["Government content client"]
  node_public_api["Public content API"]
  node_content_repo["Published catalog repository<br/>[repository.ts]"]
  node_discovery_api["Scheme discovery API<br/>[api.ts]"]
  node_discovery_engine["Relevance ranking<br/>[engine.ts]"]
end

subgraph group_content_ops["Content operations"]
  node_ingestion_worker["Source ingestion worker<br/>[worker.ts]"]
  node_secure_fetch["Safe source fetching<br/>[secureFetch.ts]"]
  node_extraction["Document extraction<br/>[extract.ts]"]
  node_extract_persist["Extraction persistence<br/>[persist.ts]"]
  node_review["Content review workflow<br/>[workflow.ts]"]
end

subgraph group_research["Research preview"]
  node_research_panel["Research preview panel"]
  node_research_client["Research journey client<br/>[researchJourney.ts]"]
  node_research_api["Local preview API<br/>[previewApi.ts]"]
  node_research_model["Preview record model<br/>[model.ts]"]
end

subgraph group_assistant["Voice assistant"]
  node_voice_context["Voice assistant interface"]
  node_live_voice["Live voice session"]
  node_assistant_api["Assistant API<br/>[assistantApi.ts]"]
  node_grounded_api["Grounded answer API<br/>[groundedApi.ts]"]
end

node_farmer(("Farmer"))
node_database[("PostgreSQL<br/>[pool.ts]")]
node_gemini{{"Gemini services"}}

node_farmer -->|"uses"| node_app
node_app -->|"renders"| node_header
node_app -->|"renders"| node_sidebar
node_app -->|"loads catalogs"| node_content_client
node_app -->|"renders"| node_verified_services
node_farmer -->|"uses"| node_farmer_services
node_content_client -->|"requests catalogs"| node_public_api
node_public_api -->|"queries"| node_content_repo
node_content_repo -->|"reads"| node_database
node_discovery_api -->|"ranks candidates"| node_discovery_engine
node_discovery_api -->|"queries"| node_database
node_ingestion_worker -->|"fetches sources"| node_secure_fetch
node_ingestion_worker -->|"persists extraction"| node_extract_persist
node_extract_persist -->|"extracts documents"| node_extraction
node_ingestion_worker -->|"records runs"| node_database
node_research_panel -->|"loads previews"| node_research_client
node_research_client -.->|"requests preview"| node_research_api
node_research_api -->|"maps records"| node_research_model
node_research_api -->|"reads records"| node_database
node_header -->|"opens voice guide"| node_voice_context
node_voice_context -->|"starts session"| node_live_voice
node_live_voice -->|"fetches live token"| node_assistant_api
node_live_voice -->|"streams audio"| node_gemini
node_assistant_api -->|"uses models"| node_gemini
node_grounded_api -->|"retrieves content"| node_content_repo
node_grounded_api -->|"queries"| node_database

click node_app "https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/src/App.tsx"
click node_header "https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/src/components/layout/Header.tsx"
click node_sidebar "https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/src/components/layout/Sidebar.tsx"
click node_verified_services "https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/src/components/public/VerifiedServices.tsx"
click node_farmer_services "https://github.com/sakshamnagar2805/krishisahyog-ai/tree/main/src/pages"
click node_content_client "https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/src/services/public/governmentContentClient.ts"
click node_public_api "https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/server/publicContentApi.ts"
click node_content_repo "https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/server/publicContent/repository.ts"
click node_discovery_api "https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/server/discovery/api.ts"
click node_discovery_engine "https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/server/discovery/engine.ts"
click node_database "https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/server/db/pool.ts"
click node_ingestion_worker "https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/server/ingestion/worker.ts"
click node_secure_fetch "https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/server/ingestion/secureFetch.ts"
click node_extraction "https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/server/extraction/extract.ts"
click node_extract_persist "https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/server/extraction/persist.ts"
click node_review "https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/server/review/workflow.ts"
click node_research_panel "https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/src/components/public/ResearchPreviewPanel.tsx"
click node_research_client "https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/src/services/public/researchJourney.ts"
click node_research_api "https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/server/research/previewApi.ts"
click node_research_model "https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/server/research/model.ts"
click node_voice_context "https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/src/components/assistant/VoiceAssistantContext.tsx"
click node_live_voice "https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/src/services/assistant/liveVoiceSession.ts"
click node_assistant_api "https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/server/assistantApi.ts"
click node_grounded_api "https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/server/assistant/groundedApi.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_header,node_sidebar,node_verified_services,node_farmer_services toneBlue
class node_content_client,node_public_api,node_content_repo,node_discovery_api,node_discovery_engine,node_database toneAmber
class node_ingestion_worker,node_secure_fetch,node_extraction,node_extract_persist,node_review toneMint
class node_research_panel,node_research_client,node_research_api,node_research_model toneRose
class node_voice_context,node_live_voice,node_assistant_api,node_grounded_api,node_farmer,node_gemini toneIndigo
```

## Components

### Farmer experience

- [App shell](https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/src/App.tsx): `src/App.tsx`
- [Navigation and voice](https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/src/components/layout/Header.tsx): `src/components/layout/Header.tsx`
- [Service navigation](https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/src/components/layout/Sidebar.tsx): `src/components/layout/Sidebar.tsx`
- [Verified services](https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/src/components/public/VerifiedServices.tsx): `src/components/public/VerifiedServices.tsx`
- [PMFBY, PACS, documents, grievances](https://github.com/sakshamnagar2805/krishisahyog-ai/tree/main/src/pages): `src/pages`

### Public information

- [Government content client](https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/src/services/public/governmentContentClient.ts): `src/services/public/governmentContentClient.ts`
- [Public content API](https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/server/publicContentApi.ts): `server/publicContentApi.ts`
- [Published catalog repository](https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/server/publicContent/repository.ts): `server/publicContent/repository.ts`
- [Scheme discovery API](https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/server/discovery/api.ts): `server/discovery/api.ts`
- [Relevance ranking](https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/server/discovery/engine.ts): `server/discovery/engine.ts`

### Content operations

- [Source ingestion worker](https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/server/ingestion/worker.ts): `server/ingestion/worker.ts`
- [Safe source fetching](https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/server/ingestion/secureFetch.ts): `server/ingestion/secureFetch.ts`
- [Document extraction](https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/server/extraction/extract.ts): `server/extraction/extract.ts`
- [Extraction persistence](https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/server/extraction/persist.ts): `server/extraction/persist.ts`
- [Content review workflow](https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/server/review/workflow.ts): `server/review/workflow.ts`

### Research preview

- [Research preview panel](https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/src/components/public/ResearchPreviewPanel.tsx): `src/components/public/ResearchPreviewPanel.tsx`
- [Research journey client](https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/src/services/public/researchJourney.ts): `src/services/public/researchJourney.ts`
- [Local preview API](https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/server/research/previewApi.ts): `server/research/previewApi.ts`
- [Preview record model](https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/server/research/model.ts): `server/research/model.ts`

### Voice assistant

- [Voice assistant interface](https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/src/components/assistant/VoiceAssistantContext.tsx): `src/components/assistant/VoiceAssistantContext.tsx`
- [Live voice session](https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/src/services/assistant/liveVoiceSession.ts): `src/services/assistant/liveVoiceSession.ts`
- [Assistant API](https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/server/assistantApi.ts): `server/assistantApi.ts`
- [Grounded answer API](https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/server/assistant/groundedApi.ts): `server/assistant/groundedApi.ts`

### Other components

- **Farmer**
- [PostgreSQL](https://github.com/sakshamnagar2805/krishisahyog-ai/blob/main/server/db/pool.ts): `server/db/pool.ts`
- **Gemini services**

## Connections

- Farmer → App shell: uses (evidence: `README.md`)
- App shell → Navigation and voice: renders (evidence: `src/App.tsx`)
- App shell → Service navigation: renders (evidence: `src/App.tsx`)
- App shell → Government content client: loads catalogs (evidence: `src/App.tsx`)
- App shell → Verified services: renders (evidence: `src/App.tsx`)
- Farmer → PMFBY, PACS, documents, grievances: uses (evidence: `README.md`)
- Government content client → Public content API: requests catalogs (evidence: `README.md`)
- Public content API → Published catalog repository: queries (evidence: `server/publicContentApi.ts`)
- Published catalog repository → PostgreSQL: reads (evidence: `server/publicContent/repository.ts`)
- Scheme discovery API → Relevance ranking: ranks candidates (evidence: `server/discovery/api.ts`)
- Scheme discovery API → PostgreSQL: queries (evidence: `server/discovery/api.ts`)
- Source ingestion worker → Safe source fetching: fetches sources (evidence: `server/ingestion/worker.ts`)
- Source ingestion worker → Extraction persistence: persists extraction (evidence: `server/ingestion/worker.ts`)
- Extraction persistence → Document extraction: extracts documents (evidence: `server/extraction/persist.ts`)
- Source ingestion worker → PostgreSQL: records runs (evidence: `server/ingestion/worker.ts`)
- Research preview panel → Research journey client: loads previews (evidence: `src/components/public/ResearchPreviewPanel.tsx`)
- Research journey client → Local preview API: requests preview
- Local preview API → Preview record model: maps records (evidence: `server/research/previewApi.ts`)
- Local preview API → PostgreSQL: reads records (evidence: `server/research/previewApi.ts`)
- Navigation and voice → Voice assistant interface: opens voice guide (evidence: `README.md`)
- Voice assistant interface → Live voice session: starts session (evidence: `src/components/assistant/VoiceAssistantContext.tsx`)
- Live voice session → Assistant API: fetches live token (evidence: `src/services/assistant/liveVoiceSession.ts`)
- Live voice session → Gemini services: streams audio (evidence: `src/services/assistant/liveVoiceSession.ts`)
- Assistant API → Gemini services: uses models (evidence: `README.md`)
- Grounded answer API → Published catalog repository: retrieves content (evidence: `server/assistant/groundedApi.ts`)
- Grounded answer API → PostgreSQL: queries (evidence: `server/assistant/groundedApi.ts`)
