# sambitji/krishidrishti architecture

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

- Interactive diagram: https://gitdiagram.com/sambitji/krishidrishti
- Repository: https://github.com/sambitji/krishidrishti

## Overview

KrishiDrishti AI is a farmer-facing crop-disease screening and incident-triage system. Farmers submit a leaf image or case report through the web UI/API; the API routes diagnosis through crop-specific inference, optionally adds satellite screening, and combines evidence into an explainable risk score before case management and guidance. WhatsApp and voice provide additional farmer communication paths. The README documents expert review and follow-up as case capabilities, but their exact implementation links are not fully shown in the excerpts; those links are therefore omitted. Edges reflect excerpted source references or explicit README descriptions.

Main entry points: [`src/krishidrishti_ai/api.py`](https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/api.py) (FastAPI routes), [`src/krishidrishti_ai/services/inference.py`](https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/services/inference.py) (Leaf inference), [`src/krishidrishti_ai/communication/farmer_flow.py`](https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/communication/farmer_flow.py) (Farmer conversation flow), [`src/krishidrishti_ai/communication/webhook.py`](https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/communication/webhook.py) (WhatsApp webhook)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Farmer access"]
  node_webui["Farmer web UI<br/>[index.html]"]
  node_wa_ui["WhatsApp demo UI<br/>[whatsapp.html]"]
  node_api["FastAPI routes<br/>[api.py]"]
end

subgraph group_diagnosis["Leaf diagnosis"]
  node_registry["Crop registry<br/>[registry.py]"]
  node_inference["Leaf inference<br/>[inference.py]"]
  node_quality["Image quality gate<br/>[quality.py]"]
  node_classifier["Classifier models<br/>[classifier.py]"]
  node_transforms["Image transforms<br/>[transforms.py]"]
  node_calibration["Confidence calibration<br/>[calibration.py]"]
  node_metrics["Prediction metrics<br/>[metrics.py]"]
  node_knowledge["Disease knowledge<br/>[knowledge.py]"]
end

subgraph group_field["Field risk"]
  node_satellite["Satellite screening<br/>[satellite.py]"]
  node_gee["Earth Engine adapter<br/>[gee_api.py]"]
  node_fusion["Risk fusion<br/>[fusion.py]"]
end

subgraph group_cases["Case workflow"]
  node_cases_service["Case workflow<br/>[cases.py]"]
  node_case_store[("WhatsApp case store<br/>[case_store.py]")]
  node_notifications["Notifications<br/>[notifications.py]"]
end

subgraph group_comms["Farmer communications"]
  node_webhook["WhatsApp webhook<br/>[webhook.py]"]
  node_farmer_flow["Farmer conversation flow<br/>[farmer_flow.py]"]
  node_voice["Voice processing<br/>[voice_service.py]"]
  node_whatsapp["WhatsApp client<br/>[whatsapp_client.py]"]
end

node_farmer(("Farmer"))
node_expert(("KVK expert"))
node_earth_engine[("Google Earth Engine")]
node_meta["Meta WhatsApp API"]

node_farmer -->|"submits photo"| node_webui
node_webui -->|"sends requests"| node_api
node_farmer -->|"reports case"| node_api
node_api -->|"routes crop"| node_registry
node_registry -->|"provides service"| node_inference
node_inference -->|"checks image"| node_quality
node_inference -->|"runs model"| node_classifier
node_inference -->|"transforms image"| node_transforms
node_inference -->|"calibrates scores"| node_calibration
node_inference -->|"uses uncertainty"| node_metrics
node_inference -->|"gets display names"| node_knowledge
node_api -->|"gets advice"| node_knowledge
node_api -->|"requests screening"| node_satellite
node_satellite -->|"delegates analysis"| node_gee
node_gee -.->|"queries imagery"| node_earth_engine
node_api -->|"combines evidence"| node_fusion
node_api -->|"creates case"| node_cases_service
node_api -->|"diagnoses photo"| node_inference
node_api -->|"exposes routes"| node_webhook
node_webhook -->|"dispatches message"| node_farmer_flow
node_farmer_flow -->|"uses case data"| node_case_store
node_farmer_flow -->|"processes voice"| node_voice
node_farmer_flow -->|"sends replies"| node_whatsapp
node_webhook -->|"checks provider"| node_whatsapp
node_whatsapp -.->|"sends messages"| node_meta
node_farmer -.->|"opens channel"| node_wa_ui
node_api -.->|"dispatches alerts"| node_notifications
node_expert -.->|"reviews cases"| node_cases_service

click node_webui "https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/static/index.html"
click node_wa_ui "https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/static/whatsapp.html"
click node_api "https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/api.py"
click node_registry "https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/services/registry.py"
click node_inference "https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/services/inference.py"
click node_quality "https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/services/quality.py"
click node_classifier "https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/models/classifier.py"
click node_transforms "https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/data/transforms.py"
click node_calibration "https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/calibration.py"
click node_metrics "https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/metrics.py"
click node_knowledge "https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/services/knowledge.py"
click node_satellite "https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/services/satellite.py"
click node_gee "https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/gee_api.py"
click node_fusion "https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/services/fusion.py"
click node_cases_service "https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/services/cases.py"
click node_case_store "https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/communication/case_store.py"
click node_notifications "https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/services/notifications.py"
click node_webhook "https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/communication/webhook.py"
click node_farmer_flow "https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/communication/farmer_flow.py"
click node_voice "https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/communication/voice_service.py"
click node_whatsapp "https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/communication/whatsapp_client.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_webui,node_wa_ui,node_api toneBlue
class node_registry,node_inference,node_quality,node_classifier,node_transforms,node_calibration,node_metrics,node_knowledge,node_earth_engine toneAmber
class node_satellite,node_gee,node_fusion,node_meta toneMint
class node_cases_service,node_case_store,node_notifications toneRose
class node_webhook,node_farmer_flow,node_voice,node_whatsapp,node_farmer,node_expert toneIndigo
```

## Components

### Farmer access

- [Farmer web UI](https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/static/index.html): `src/krishidrishti_ai/static/index.html`
- [WhatsApp demo UI](https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/static/whatsapp.html): `src/krishidrishti_ai/static/whatsapp.html`
- [FastAPI routes](https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/api.py): `src/krishidrishti_ai/api.py`

### Leaf diagnosis

- [Crop registry](https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/services/registry.py): `src/krishidrishti_ai/services/registry.py`
- [Leaf inference](https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/services/inference.py): `src/krishidrishti_ai/services/inference.py`
- [Image quality gate](https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/services/quality.py): `src/krishidrishti_ai/services/quality.py`
- [Classifier models](https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/models/classifier.py): `src/krishidrishti_ai/models/classifier.py`
- [Image transforms](https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/data/transforms.py): `src/krishidrishti_ai/data/transforms.py`
- [Confidence calibration](https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/calibration.py): `src/krishidrishti_ai/calibration.py`
- [Prediction metrics](https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/metrics.py): `src/krishidrishti_ai/metrics.py`
- [Disease knowledge](https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/services/knowledge.py): `src/krishidrishti_ai/services/knowledge.py`

### Field risk

- [Satellite screening](https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/services/satellite.py): `src/krishidrishti_ai/services/satellite.py`
- [Earth Engine adapter](https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/gee_api.py): `src/krishidrishti_ai/gee_api.py`
- [Risk fusion](https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/services/fusion.py): `src/krishidrishti_ai/services/fusion.py`

### Case workflow

- [Case workflow](https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/services/cases.py): `src/krishidrishti_ai/services/cases.py`
- [WhatsApp case store](https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/communication/case_store.py): `src/krishidrishti_ai/communication/case_store.py`
- [Notifications](https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/services/notifications.py): `src/krishidrishti_ai/services/notifications.py`

### Farmer communications

- [WhatsApp webhook](https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/communication/webhook.py): `src/krishidrishti_ai/communication/webhook.py`
- [Farmer conversation flow](https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/communication/farmer_flow.py): `src/krishidrishti_ai/communication/farmer_flow.py`
- [Voice processing](https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/communication/voice_service.py): `src/krishidrishti_ai/communication/voice_service.py`
- [WhatsApp client](https://github.com/sambitji/krishidrishti/blob/main/src/krishidrishti_ai/communication/whatsapp_client.py): `src/krishidrishti_ai/communication/whatsapp_client.py`

### Other components

- **Farmer**
- **KVK expert**
- **Google Earth Engine**
- **Meta WhatsApp API**

## Connections

- Farmer → Farmer web UI: submits photo (evidence: `README.md`)
- Farmer web UI → FastAPI routes: sends requests (evidence: `README.md`)
- Farmer → FastAPI routes: reports case (evidence: `README.md`)
- FastAPI routes → Crop registry: routes crop (evidence: `src/krishidrishti_ai/api.py`)
- Crop registry → Leaf inference: provides service (evidence: `src/krishidrishti_ai/services/registry.py`)
- Leaf inference → Image quality gate: checks image (evidence: `src/krishidrishti_ai/services/inference.py`)
- Leaf inference → Classifier models: runs model (evidence: `src/krishidrishti_ai/services/inference.py`)
- Leaf inference → Image transforms: transforms image (evidence: `src/krishidrishti_ai/services/inference.py`)
- Leaf inference → Confidence calibration: calibrates scores (evidence: `src/krishidrishti_ai/services/inference.py`)
- Leaf inference → Prediction metrics: uses uncertainty (evidence: `src/krishidrishti_ai/services/inference.py`)
- Leaf inference → Disease knowledge: gets display names (evidence: `src/krishidrishti_ai/services/inference.py`)
- FastAPI routes → Disease knowledge: gets advice (evidence: `src/krishidrishti_ai/api.py`)
- FastAPI routes → Satellite screening: requests screening (evidence: `src/krishidrishti_ai/api.py`)
- Satellite screening → Earth Engine adapter: delegates analysis (evidence: `src/krishidrishti_ai/services/satellite.py`)
- Earth Engine adapter → Google Earth Engine: queries imagery
- FastAPI routes → Risk fusion: combines evidence (evidence: `README.md`)
- FastAPI routes → Case workflow: creates case (evidence: `src/krishidrishti_ai/api.py`)
- FastAPI routes → Leaf inference: diagnoses photo (evidence: `src/krishidrishti_ai/api.py`)
- FastAPI routes → WhatsApp webhook: exposes routes (evidence: `src/krishidrishti_ai/api.py`)
- WhatsApp webhook → Farmer conversation flow: dispatches message (evidence: `src/krishidrishti_ai/communication/webhook.py`)
- Farmer conversation flow → WhatsApp case store: uses case data (evidence: `src/krishidrishti_ai/communication/farmer_flow.py`)
- Farmer conversation flow → Voice processing: processes voice (evidence: `src/krishidrishti_ai/communication/farmer_flow.py`)
- Farmer conversation flow → WhatsApp client: sends replies (evidence: `src/krishidrishti_ai/communication/farmer_flow.py`)
- WhatsApp webhook → WhatsApp client: checks provider (evidence: `src/krishidrishti_ai/communication/webhook.py`)
- WhatsApp client → Meta WhatsApp API: sends messages
- Farmer → WhatsApp demo UI: opens channel
- FastAPI routes → Notifications: dispatches alerts (evidence: `src/krishidrishti_ai/api.py`)
- KVK expert → Case workflow: reviews cases (evidence: `README.md`)
