# shivamr021/krishimitra-ai architecture

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

- Interactive diagram: https://gitdiagram.com/shivamr021/krishimitra-ai
- Repository: https://github.com/shivamr021/krishimitra-ai

## Overview

KrishiMitra is a farmer-facing agricultural assistant delivered primarily through WhatsApp, with a frontend demo site. A chat request is interpreted by Gemini, dispatched to weather or mandi-price handlers, or answered conversationally; incoming plant images go through local disease classification and use Gemini Vision when confidence is low. The README documents multilingual support and these capabilities. Frontend component wiring beyond the sampled app entry points is not established by the excerpts, so its showcase sections are represented without inferred call edges.

Main entry points: [`backend/api/webhook_router.py`](https://github.com/shivamr021/krishimitra-ai/blob/master/backend/api/webhook_router.py) (Chat webhook), [`backend/utils/ai_processor.py`](https://github.com/shivamr021/krishimitra-ai/blob/master/backend/utils/ai_processor.py) (Query interpretation), [`backend/core/config.py`](https://github.com/shivamr021/krishimitra-ai/blob/master/backend/core/config.py) (Runtime settings), [`backend/core/router.py`](https://github.com/shivamr021/krishimitra-ai/blob/master/backend/core/router.py) (Tool dispatch)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_channel["User channels"]
end

subgraph group_backend["WhatsApp backend"]
  node_main["API application<br/>[main.py]"]
  node_webhook["Chat webhook<br/>[webhook_router.py]"]
  node_sessions[("Language sessions<br/>[webhook_router.py]")]
  node_tools["Tool dispatch<br/>[router.py]"]
  node_config["Runtime settings<br/>[config.py]"]
end

subgraph group_intelligence["Agricultural intelligence"]
  node_intent["Query interpretation<br/>[ai_processor.py]"]
  node_vision["Plant diagnosis"]
  node_market["Mandi prices"]
  node_weather["Weather advice<br/>[weather_agent.py]"]
end

subgraph group_frontend["Frontend showcase"]
  node_frontend["Frontend app<br/>[App.tsx]"]
  node_landing["Landing page<br/>[Index.tsx]"]
  node_notfound["Not-found page<br/>[NotFound.tsx]"]
  node_features["Feature showcase<br/>[Features.tsx]"]
  node_workflow["How it works<br/>[HowItWorks.tsx]"]
  node_channels["WhatsApp rationale<br/>[WhyWhatsApp.tsx]"]
end

node_farmer(("Farmer"))
node_whatsapp{{"WhatsApp / Twilio"}}
node_gemini{{"Google Gemini"}}
node_weatherapi{{"OpenWeather API"}}

node_farmer -->|"sends query or image"| node_whatsapp
node_whatsapp -->|"posts message"| node_webhook
node_main -->|"mounts route"| node_webhook
node_webhook -->|"interprets text"| node_intent
node_webhook -->|"diagnoses image"| node_vision
node_webhook -->|"dispatches tool"| node_tools
node_webhook -->|"stores language"| node_sessions
node_webhook -->|"returns reply"| node_whatsapp
node_tools -->|"gets price"| node_market
node_tools -->|"gets forecast"| node_weather
node_intent -->|"requests interpretation"| node_gemini
node_intent -->|"translates reply"| node_gemini
node_vision -->|"uses low-confidence fallback"| node_gemini
node_market -->|"requests price answer"| node_gemini
node_weather -->|"fetches conditions"| node_weatherapi
node_intent -->|"reads credentials"| node_config
node_vision -->|"reads model and credentials"| node_config
node_market -->|"reads credentials"| node_config
node_weather -->|"reads API key"| node_config
node_frontend -->|"routes home"| node_landing
node_frontend -->|"routes unmatched paths"| node_notfound

click node_main "https://github.com/shivamr021/krishimitra-ai/blob/master/backend/main.py"
click node_webhook "https://github.com/shivamr021/krishimitra-ai/blob/master/backend/api/webhook_router.py"
click node_sessions "https://github.com/shivamr021/krishimitra-ai/blob/master/backend/api/webhook_router.py"
click node_intent "https://github.com/shivamr021/krishimitra-ai/blob/master/backend/utils/ai_processor.py"
click node_vision "https://github.com/shivamr021/krishimitra-ai/blob/master/backend/agents/pest_detection_agent.py"
click node_tools "https://github.com/shivamr021/krishimitra-ai/blob/master/backend/core/router.py"
click node_market "https://github.com/shivamr021/krishimitra-ai/blob/master/backend/agents/market_price_agent.py"
click node_weather "https://github.com/shivamr021/krishimitra-ai/blob/master/backend/agents/weather_agent.py"
click node_config "https://github.com/shivamr021/krishimitra-ai/blob/master/backend/core/config.py"
click node_frontend "https://github.com/shivamr021/krishimitra-ai/blob/master/frontend/src/App.tsx"
click node_landing "https://github.com/shivamr021/krishimitra-ai/blob/master/frontend/src/pages/Index.tsx"
click node_notfound "https://github.com/shivamr021/krishimitra-ai/blob/master/frontend/src/pages/NotFound.tsx"
click node_features "https://github.com/shivamr021/krishimitra-ai/blob/master/frontend/src/components/Features.tsx"
click node_workflow "https://github.com/shivamr021/krishimitra-ai/blob/master/frontend/src/components/HowItWorks.tsx"
click node_channels "https://github.com/shivamr021/krishimitra-ai/blob/master/frontend/src/components/WhyWhatsApp.tsx"

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_main,node_webhook,node_sessions,node_tools,node_config toneAmber
class node_intent,node_vision,node_market,node_weather,node_weatherapi toneMint
class node_frontend,node_landing,node_notfound,node_features,node_workflow,node_channels toneRose
class node_farmer,node_whatsapp,node_gemini toneIndigo
```

## Components

### WhatsApp backend

- [API application](https://github.com/shivamr021/krishimitra-ai/blob/master/backend/main.py): `backend/main.py`
- [Chat webhook](https://github.com/shivamr021/krishimitra-ai/blob/master/backend/api/webhook_router.py): `backend/api/webhook_router.py`
- [Language sessions](https://github.com/shivamr021/krishimitra-ai/blob/master/backend/api/webhook_router.py): `backend/api/webhook_router.py`
- [Tool dispatch](https://github.com/shivamr021/krishimitra-ai/blob/master/backend/core/router.py): `backend/core/router.py`
- [Runtime settings](https://github.com/shivamr021/krishimitra-ai/blob/master/backend/core/config.py): `backend/core/config.py`

### Agricultural intelligence

- [Query interpretation](https://github.com/shivamr021/krishimitra-ai/blob/master/backend/utils/ai_processor.py): `backend/utils/ai_processor.py`
- [Plant diagnosis](https://github.com/shivamr021/krishimitra-ai/blob/master/backend/agents/pest_detection_agent.py): `backend/agents/pest_detection_agent.py`
- [Mandi prices](https://github.com/shivamr021/krishimitra-ai/blob/master/backend/agents/market_price_agent.py): `backend/agents/market_price_agent.py`
- [Weather advice](https://github.com/shivamr021/krishimitra-ai/blob/master/backend/agents/weather_agent.py): `backend/agents/weather_agent.py`

### Frontend showcase

- [Frontend app](https://github.com/shivamr021/krishimitra-ai/blob/master/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Landing page](https://github.com/shivamr021/krishimitra-ai/blob/master/frontend/src/pages/Index.tsx): `frontend/src/pages/Index.tsx`
- [Not-found page](https://github.com/shivamr021/krishimitra-ai/blob/master/frontend/src/pages/NotFound.tsx): `frontend/src/pages/NotFound.tsx`
- [Feature showcase](https://github.com/shivamr021/krishimitra-ai/blob/master/frontend/src/components/Features.tsx): `frontend/src/components/Features.tsx`
- [How it works](https://github.com/shivamr021/krishimitra-ai/blob/master/frontend/src/components/HowItWorks.tsx): `frontend/src/components/HowItWorks.tsx`
- [WhatsApp rationale](https://github.com/shivamr021/krishimitra-ai/blob/master/frontend/src/components/WhyWhatsApp.tsx): `frontend/src/components/WhyWhatsApp.tsx`

### Other components

- **Farmer**
- **WhatsApp / Twilio**
- **Google Gemini**
- **OpenWeather API**

## Connections

- Farmer → WhatsApp / Twilio: sends query or image (evidence: `README.md`)
- WhatsApp / Twilio → Chat webhook: posts message (evidence: `README.md`)
- API application → Chat webhook: mounts route (evidence: `backend/main.py`)
- Chat webhook → Query interpretation: interprets text (evidence: `backend/api/webhook_router.py`)
- Chat webhook → Plant diagnosis: diagnoses image (evidence: `backend/api/webhook_router.py`)
- Chat webhook → Tool dispatch: dispatches tool (evidence: `backend/api/webhook_router.py`)
- Chat webhook → Language sessions: stores language (evidence: `backend/api/webhook_router.py`)
- Chat webhook → WhatsApp / Twilio: returns reply (evidence: `backend/api/webhook_router.py`)
- Tool dispatch → Mandi prices: gets price (evidence: `backend/core/router.py`)
- Tool dispatch → Weather advice: gets forecast (evidence: `backend/core/router.py`)
- Query interpretation → Google Gemini: requests interpretation (evidence: `backend/utils/ai_processor.py`)
- Query interpretation → Google Gemini: translates reply (evidence: `backend/utils/ai_processor.py`)
- Plant diagnosis → Google Gemini: uses low-confidence fallback (evidence: `backend/agents/pest_detection_agent.py`)
- Mandi prices → Google Gemini: requests price answer (evidence: `backend/agents/market_price_agent.py`)
- Weather advice → OpenWeather API: fetches conditions (evidence: `backend/agents/weather_agent.py`)
- Query interpretation → Runtime settings: reads credentials (evidence: `backend/utils/ai_processor.py`)
- Plant diagnosis → Runtime settings: reads model and credentials (evidence: `backend/agents/pest_detection_agent.py`)
- Mandi prices → Runtime settings: reads credentials (evidence: `backend/agents/market_price_agent.py`)
- Weather advice → Runtime settings: reads API key (evidence: `backend/agents/weather_agent.py`)
- Frontend app → Landing page: routes home (evidence: `frontend/src/App.tsx`)
- Frontend app → Not-found page: routes unmatched paths (evidence: `frontend/src/App.tsx`)
