# kulkarniparth30/kisansetu architecture

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

- Interactive diagram: https://gitdiagram.com/kulkarniparth30/kisansetu
- Repository: https://github.com/kulkarniparth30/kisansetu

## Overview

KisanSetu is a multilingual agriculture platform for farmers. Signed-in users reach diagnosis, remedy chat, markets, weather, crop calendar, history, soil-health, farmer, and hotspot features through the React app; the pages call a FastAPI backend. The central diagnostic path accepts a leaf image, uses Gemini with a ResNet fallback, and can provide ICAR-grounded follow-up guidance. Other documented capabilities include nearby disease alerts and voice IVR. The route registration and selected service calls are evidenced in excerpts; several feature internals were not sampled, so their implementation links are omitted.

Main entry points: [`backend/app/main.py`](https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/main.py) (FastAPI app), [`frontend/src/App.jsx`](https://github.com/kulkarniparth30/kisansetu/blob/main/frontend/src/App.jsx) (App routing), [`frontend/src/services/api.js`](https://github.com/kulkarniparth30/kisansetu/blob/main/frontend/src/services/api.js) (API client), [`backend/app/supabase_client.py`](https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/supabase_client.py) (Supabase access)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Farmer app"]
  node_app["App routing<br/>[App.jsx]"]
  node_diagnosis_ui["Diagnosis page<br/>[DiagnosisPage.jsx]"]
  node_chat_ui["Chat page<br/>[ChatPage.jsx]"]
  node_dashboard_ui["Hotspot dashboard<br/>[DashboardPage.jsx]"]
  node_calendar_ui["Crop calendar<br/>[CalendarPage.jsx]"]
  node_history_ui["Diagnosis history<br/>[HistoryPage.jsx]"]
  node_mandi_ui["Mandi prices<br/>[MandiPage.jsx]"]
  node_weather_ui["Weather risk<br/>[WeatherPage.jsx]"]
  node_farmer_ui["Farmer network<br/>[FarmerPage.jsx]"]
  node_api_client["API client<br/>[api.js]"]
end

subgraph group_api["API routes"]
  node_backend["FastAPI app<br/>[main.py]"]
  node_predict["Disease route<br/>[predict.py]"]
  node_remedy["Remedy route<br/>[remedy.py]"]
  node_heatmap["Heatmap route<br/>[heatmap.py]"]
  node_calendar["Calendar route<br/>[calendar.py]"]
  node_history["History route<br/>[history.py]"]
  node_mandi["Market route<br/>[mandi.py]"]
  node_weather["Weather route<br/>[weather.py]"]
  node_farmers["Farmers route<br/>[farmers.py]"]
  node_alerts["Alert route<br/>[alerts.py]"]
  node_soil["Soil health route<br/>[soil.py]"]
  node_ivr["Voice IVR route<br/>[ivr.py]"]
end

subgraph group_intelligence["Diagnosis and advice"]
  node_gemini["Gemini diagnosis and chat<br/>[gemini_service.py]"]
  node_resnet["ResNet inference<br/>[resnet_service.py]"]
  node_rag[("ICAR knowledge retrieval<br/>[rag_service.py]")]
end

subgraph group_field["Farm operations"]
  node_store[("Supabase access<br/>[supabase_client.py]")]
  node_alert_service["Nearby SMS alerts<br/>[alert_service.py]"]
  node_distance["Nearby farmer distance<br/>[haversine.py]"]
  node_report["Soil PDF reports<br/>[report_service.py]"]
  node_weather_service["Weather risk service<br/>[weather_service.py]"]
  node_market_data["Market data service<br/>[config.py]"]
end

node_farmer(("Farmer"))
node_external_ai{{"Gemini API"}}
node_twilio{{"Twilio SMS"}}

node_farmer -->|"uses"| node_app
node_app -->|"routes to"| node_diagnosis_ui
node_app -->|"routes to"| node_chat_ui
node_app -->|"routes to"| node_dashboard_ui
node_app -->|"routes to"| node_calendar_ui
node_app -->|"routes to"| node_history_ui
node_app -->|"routes to"| node_mandi_ui
node_app -->|"routes to"| node_weather_ui
node_app -->|"routes to"| node_farmer_ui
node_diagnosis_ui -->|"requests"| node_api_client
node_chat_ui -->|"requests"| node_api_client
node_dashboard_ui -->|"requests"| node_api_client
node_calendar_ui -->|"requests"| node_api_client
node_history_ui -->|"requests"| node_api_client
node_mandi_ui -->|"requests"| node_api_client
node_weather_ui -->|"requests"| node_api_client
node_api_client -.->|"calls API"| node_backend
node_backend -->|"registers route"| node_predict
node_backend -->|"registers route"| node_remedy
node_backend -->|"registers route"| node_heatmap
node_backend -->|"registers route"| node_calendar
node_backend -->|"registers route"| node_history
node_backend -->|"registers route"| node_mandi
node_backend -->|"registers route"| node_weather
node_backend -->|"registers route"| node_farmers
node_backend -->|"registers route"| node_alerts
node_backend -->|"registers route"| node_soil
node_backend -->|"registers route"| node_ivr
node_predict -->|"calls diagnosis"| node_gemini
node_predict -->|"uses fallback"| node_resnet
node_predict -->|"persists results"| node_store
node_remedy -->|"requests advice"| node_gemini
node_gemini -->|"queries context"| node_rag
node_gemini -.->|"generates with"| node_external_ai
node_farmers -->|"reads farmers"| node_store
node_farmers -->|"calculates proximity"| node_distance
node_alerts -->|"dispatches"| node_alert_service
node_alert_service -->|"loads farmers"| node_store
node_alert_service -->|"finds nearby"| node_distance
node_alert_service -.->|"sends SMS"| node_twilio
node_heatmap -->|"reads detections"| node_store
node_soil -->|"stores usage"| node_store
node_soil -->|"creates reports"| node_report
node_weather -.->|"uses risk data"| node_weather_service
node_market_data -.->|"configures API"| node_mandi

click node_app "https://github.com/kulkarniparth30/kisansetu/blob/main/frontend/src/App.jsx"
click node_diagnosis_ui "https://github.com/kulkarniparth30/kisansetu/blob/main/frontend/src/pages/DiagnosisPage.jsx"
click node_chat_ui "https://github.com/kulkarniparth30/kisansetu/blob/main/frontend/src/pages/ChatPage.jsx"
click node_dashboard_ui "https://github.com/kulkarniparth30/kisansetu/blob/main/frontend/src/pages/DashboardPage.jsx"
click node_calendar_ui "https://github.com/kulkarniparth30/kisansetu/blob/main/frontend/src/pages/CalendarPage.jsx"
click node_history_ui "https://github.com/kulkarniparth30/kisansetu/blob/main/frontend/src/pages/HistoryPage.jsx"
click node_mandi_ui "https://github.com/kulkarniparth30/kisansetu/blob/main/frontend/src/pages/MandiPage.jsx"
click node_weather_ui "https://github.com/kulkarniparth30/kisansetu/blob/main/frontend/src/pages/WeatherPage.jsx"
click node_farmer_ui "https://github.com/kulkarniparth30/kisansetu/blob/main/frontend/src/pages/FarmerPage.jsx"
click node_api_client "https://github.com/kulkarniparth30/kisansetu/blob/main/frontend/src/services/api.js"
click node_backend "https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/main.py"
click node_predict "https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/api/predict.py"
click node_remedy "https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/api/remedy.py"
click node_heatmap "https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/api/heatmap.py"
click node_calendar "https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/api/calendar.py"
click node_history "https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/api/history.py"
click node_mandi "https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/api/mandi.py"
click node_weather "https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/api/weather.py"
click node_farmers "https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/api/farmers.py"
click node_alerts "https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/api/alerts.py"
click node_soil "https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/api/soil.py"
click node_ivr "https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/api/ivr.py"
click node_gemini "https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/services/gemini_service.py"
click node_resnet "https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/services/resnet_service.py"
click node_rag "https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/services/rag_service.py"
click node_store "https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/supabase_client.py"
click node_alert_service "https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/services/alert_service.py"
click node_distance "https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/utils/haversine.py"
click node_report "https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/services/report_service.py"
click node_weather_service "https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/services/weather_service.py"
click node_market_data "https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/config.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_diagnosis_ui,node_chat_ui,node_dashboard_ui,node_calendar_ui,node_history_ui,node_mandi_ui,node_weather_ui,node_farmer_ui,node_api_client toneBlue
class node_backend,node_predict,node_remedy,node_heatmap,node_calendar,node_history,node_mandi,node_weather,node_farmers,node_alerts,node_soil,node_ivr toneAmber
class node_gemini,node_resnet,node_rag,node_external_ai toneMint
class node_store,node_alert_service,node_distance,node_report,node_weather_service,node_market_data toneRose
class node_farmer,node_twilio toneIndigo
```

## Components

### Farmer app

- [App routing](https://github.com/kulkarniparth30/kisansetu/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Diagnosis page](https://github.com/kulkarniparth30/kisansetu/blob/main/frontend/src/pages/DiagnosisPage.jsx): `frontend/src/pages/DiagnosisPage.jsx`
- [Chat page](https://github.com/kulkarniparth30/kisansetu/blob/main/frontend/src/pages/ChatPage.jsx): `frontend/src/pages/ChatPage.jsx`
- [Hotspot dashboard](https://github.com/kulkarniparth30/kisansetu/blob/main/frontend/src/pages/DashboardPage.jsx): `frontend/src/pages/DashboardPage.jsx`
- [Crop calendar](https://github.com/kulkarniparth30/kisansetu/blob/main/frontend/src/pages/CalendarPage.jsx): `frontend/src/pages/CalendarPage.jsx`
- [Diagnosis history](https://github.com/kulkarniparth30/kisansetu/blob/main/frontend/src/pages/HistoryPage.jsx): `frontend/src/pages/HistoryPage.jsx`
- [Mandi prices](https://github.com/kulkarniparth30/kisansetu/blob/main/frontend/src/pages/MandiPage.jsx): `frontend/src/pages/MandiPage.jsx`
- [Weather risk](https://github.com/kulkarniparth30/kisansetu/blob/main/frontend/src/pages/WeatherPage.jsx): `frontend/src/pages/WeatherPage.jsx`
- [Farmer network](https://github.com/kulkarniparth30/kisansetu/blob/main/frontend/src/pages/FarmerPage.jsx): `frontend/src/pages/FarmerPage.jsx`
- [API client](https://github.com/kulkarniparth30/kisansetu/blob/main/frontend/src/services/api.js): `frontend/src/services/api.js`

### API routes

- [FastAPI app](https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/main.py): `backend/app/main.py`
- [Disease route](https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/api/predict.py): `backend/app/api/predict.py`
- [Remedy route](https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/api/remedy.py): `backend/app/api/remedy.py`
- [Heatmap route](https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/api/heatmap.py): `backend/app/api/heatmap.py`
- [Calendar route](https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/api/calendar.py): `backend/app/api/calendar.py`
- [History route](https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/api/history.py): `backend/app/api/history.py`
- [Market route](https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/api/mandi.py): `backend/app/api/mandi.py`
- [Weather route](https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/api/weather.py): `backend/app/api/weather.py`
- [Farmers route](https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/api/farmers.py): `backend/app/api/farmers.py`
- [Alert route](https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/api/alerts.py): `backend/app/api/alerts.py`
- [Soil health route](https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/api/soil.py): `backend/app/api/soil.py`
- [Voice IVR route](https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/api/ivr.py): `backend/app/api/ivr.py`

### Diagnosis and advice

- [Gemini diagnosis and chat](https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/services/gemini_service.py): `backend/app/services/gemini_service.py`
- [ResNet inference](https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/services/resnet_service.py): `backend/app/services/resnet_service.py`
- [ICAR knowledge retrieval](https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/services/rag_service.py): `backend/app/services/rag_service.py`

### Farm operations

- [Supabase access](https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/supabase_client.py): `backend/app/supabase_client.py`
- [Nearby SMS alerts](https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/services/alert_service.py): `backend/app/services/alert_service.py`
- [Nearby farmer distance](https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/utils/haversine.py): `backend/app/utils/haversine.py`
- [Soil PDF reports](https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/services/report_service.py): `backend/app/services/report_service.py`
- [Weather risk service](https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/services/weather_service.py): `backend/app/services/weather_service.py`
- [Market data service](https://github.com/kulkarniparth30/kisansetu/blob/main/backend/app/config.py): `backend/app/config.py`

### Other components

- **Farmer**
- **Gemini API**
- **Twilio SMS**

## Connections

- Farmer → App routing: uses (evidence: `frontend/src/App.jsx`)
- App routing → Diagnosis page: routes to (evidence: `frontend/src/App.jsx`)
- App routing → Chat page: routes to (evidence: `frontend/src/App.jsx`)
- App routing → Hotspot dashboard: routes to (evidence: `frontend/src/App.jsx`)
- App routing → Crop calendar: routes to (evidence: `frontend/src/App.jsx`)
- App routing → Diagnosis history: routes to (evidence: `frontend/src/App.jsx`)
- App routing → Mandi prices: routes to (evidence: `frontend/src/App.jsx`)
- App routing → Weather risk: routes to (evidence: `frontend/src/App.jsx`)
- App routing → Farmer network: routes to (evidence: `frontend/src/App.jsx`)
- Diagnosis page → API client: requests (evidence: `frontend/src/pages/DiagnosisPage.jsx`)
- Chat page → API client: requests (evidence: `frontend/src/pages/ChatPage.jsx`)
- Hotspot dashboard → API client: requests (evidence: `frontend/src/pages/DashboardPage.jsx`)
- Crop calendar → API client: requests (evidence: `frontend/src/pages/CalendarPage.jsx`)
- Diagnosis history → API client: requests (evidence: `frontend/src/pages/HistoryPage.jsx`)
- Mandi prices → API client: requests (evidence: `frontend/src/pages/MandiPage.jsx`)
- Weather risk → API client: requests (evidence: `frontend/src/pages/WeatherPage.jsx`)
- API client → FastAPI app: calls API
- FastAPI app → Disease route: registers route (evidence: `backend/app/main.py`)
- FastAPI app → Remedy route: registers route (evidence: `backend/app/main.py`)
- FastAPI app → Heatmap route: registers route (evidence: `backend/app/main.py`)
- FastAPI app → Calendar route: registers route (evidence: `backend/app/main.py`)
- FastAPI app → History route: registers route (evidence: `backend/app/main.py`)
- FastAPI app → Market route: registers route (evidence: `backend/app/main.py`)
- FastAPI app → Weather route: registers route (evidence: `backend/app/main.py`)
- FastAPI app → Farmers route: registers route (evidence: `backend/app/main.py`)
- FastAPI app → Alert route: registers route (evidence: `backend/app/main.py`)
- FastAPI app → Soil health route: registers route (evidence: `backend/app/main.py`)
- FastAPI app → Voice IVR route: registers route (evidence: `backend/app/main.py`)
- Disease route → Gemini diagnosis and chat: calls diagnosis (evidence: `backend/app/api/predict.py`)
- Disease route → ResNet inference: uses fallback (evidence: `backend/app/api/predict.py`)
- Disease route → Supabase access: persists results (evidence: `backend/app/api/predict.py`)
- Remedy route → Gemini diagnosis and chat: requests advice (evidence: `backend/app/api/remedy.py`)
- Gemini diagnosis and chat → ICAR knowledge retrieval: queries context (evidence: `backend/app/services/gemini_service.py`)
- Gemini diagnosis and chat → Gemini API: generates with
- Farmers route → Supabase access: reads farmers (evidence: `backend/app/api/farmers.py`)
- Farmers route → Nearby farmer distance: calculates proximity (evidence: `backend/app/api/farmers.py`)
- Alert route → Nearby SMS alerts: dispatches (evidence: `backend/app/api/alerts.py`)
- Nearby SMS alerts → Supabase access: loads farmers (evidence: `backend/app/services/alert_service.py`)
- Nearby SMS alerts → Nearby farmer distance: finds nearby (evidence: `backend/app/services/alert_service.py`)
- Nearby SMS alerts → Twilio SMS: sends SMS
- Heatmap route → Supabase access: reads detections (evidence: `backend/app/api/heatmap.py`)
- Soil health route → Supabase access: stores usage (evidence: `backend/app/api/soil.py`)
- Soil health route → Soil PDF reports: creates reports (evidence: `backend/app/api/soil.py`)
- Weather route → Weather risk service: uses risk data
- Market data service → Market route: configures API (evidence: `backend/app/api/mandi.py`)
