# darshanthelucifer-png/krishimitra-ai architecture

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

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

## Overview

AgriSaarthi AI is a multilingual agricultural advisory product delivered through a React/Capacitor client and FastAPI backend. Farmers use chat or voice for grounded crop guidance, and can access disease diagnosis, weather, mandi prices, and land/soil planning. The main advisory path runs through the chat route and RAG service, which retrieves and reranks agricultural references before generating a response; low-confidence cases have agronomy and web-search fallback capabilities. Several feature services are represented from the tree and README, but their internal calls are not shown in the sampled source.

Main entry points: [`backend/app/services/rag_service.py`](https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/services/rag_service.py) (RAG orchestrator), [`frontend/src/App.tsx`](https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/frontend/src/App.tsx) (Web and mobile app), [`backend/app/main.py`](https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/main.py) (FastAPI gateway), [`frontend/src/pages/Chat.tsx`](https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/frontend/src/pages/Chat.tsx) (Chat interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Farmer client"]
  node_app["Web and mobile app<br/>[App.tsx]"]
  node_chatui["Chat interface<br/>[Chat.tsx]"]
  node_diseaseui["Disease check<br/>[DiseaseCheck.tsx]"]
  node_landui["Land planner<br/>[LandVisualizer.tsx]"]
  node_clientapi["API client<br/>[api.ts]"]
  node_authstate["Auth state<br/>[useAuth.tsx]"]
  node_authsvc["Auth client service<br/>[authService.ts]"]
end

subgraph group_gateway["API and identity"]
  node_backend["FastAPI gateway<br/>[main.py]"]
  node_authroute["Authentication routes<br/>[auth.py]"]
  node_chatroute["Chat route<br/>[chat.py]"]
  node_diseaseroute["Disease route<br/>[disease.py]"]
end

subgraph group_intelligence["Advisory intelligence"]
  node_rag["RAG orchestrator<br/>[rag_service.py]"]
  node_hybrid["Hybrid retrieval"]
  node_vector["Vector retrieval<br/>[retriever.py]"]
  node_embeddings["Embedding service<br/>[embeddings.py]"]
  node_agronomy["Agronomy reasoning"]
  node_llm["Language model<br/>[llm.py]"]
  node_agents["Agent workflow<br/>[graph.py]"]
end

subgraph group_field["Field services"]
  node_disease["Disease diagnostics<br/>[disease_service.py]"]
  node_land["Land blueprint"]
  node_weather["Weather advisory<br/>[weather_service.py]"]
  node_market["Mandi intelligence<br/>[mandi_service.py]"]
  node_voice["Voice services<br/>[voice_service.py]"]
  node_translation["Translation"]
end

node_farmer(("Farmer"))
node_soilgrids["SoilGrids"]
node_websearch["Agricultural web sources"]
node_chroma[("Chroma vector store")]

node_farmer -->|"uses"| node_app
node_app -->|"renders"| node_chatui
node_app -->|"renders"| node_diseaseui
node_app -->|"renders"| node_landui
node_chatui -->|"requests through"| node_clientapi
node_chatui -->|"uses voice client"| node_voice
node_app -->|"provides auth"| node_authstate
node_authstate -->|"calls"| node_authsvc
node_authsvc -->|"sends auth requests"| node_clientapi
node_clientapi -->|"sends REST requests"| node_backend
node_backend -->|"registers"| node_authroute
node_backend -->|"registers"| node_chatroute
node_backend -->|"registers"| node_diseaseroute
node_chatroute -->|"calls"| node_rag
node_diseaseroute -->|"calls"| node_disease
node_rag -->|"retrieves with"| node_hybrid
node_rag -->|"generates with"| node_llm
node_rag -->|"falls back to"| node_agronomy
node_rag -->|"routes price intent"| node_market
node_rag -->|"searches fallback"| node_websearch
node_hybrid -->|"queries dense channel"| node_vector
node_vector -->|"embeds queries"| node_embeddings
node_vector -->|"queries vectors"| node_chroma
node_hybrid -->|"loads indexed records"| node_chroma
node_rag -.->|"orchestrates agents"| node_agents
node_farmer -->|"submits crop photo"| node_diseaseui
node_farmer -->|"requests farm plan"| node_landui
node_land -->|"fetches soil profiles"| node_soilgrids
node_farmer -.->|"requests weather"| node_weather
node_farmer -.->|"requests translation"| node_translation
node_farmer -->|"uses voice loop"| node_voice

click node_app "https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/frontend/src/App.tsx"
click node_chatui "https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/frontend/src/pages/Chat.tsx"
click node_diseaseui "https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/frontend/src/pages/DiseaseCheck.tsx"
click node_landui "https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/frontend/src/pages/LandVisualizer.tsx"
click node_clientapi "https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/frontend/src/services/api.ts"
click node_authstate "https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/frontend/src/hooks/useAuth.tsx"
click node_authsvc "https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/frontend/src/services/authService.ts"
click node_backend "https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/main.py"
click node_authroute "https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/api/routes/auth.py"
click node_chatroute "https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/api/routes/chat.py"
click node_diseaseroute "https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/api/routes/disease.py"
click node_rag "https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/services/rag_service.py"
click node_hybrid "https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/ai/hybrid_retriever.py"
click node_vector "https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/ai/retriever.py"
click node_embeddings "https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/ai/embeddings.py"
click node_agronomy "https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/services/agronomy_reasoning_engine.py"
click node_llm "https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/ai/llm.py"
click node_agents "https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/ai/agents/graph.py"
click node_disease "https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/services/disease_service.py"
click node_land "https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/services/land_visualizer_service.py"
click node_weather "https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/services/weather_service.py"
click node_market "https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/services/mandi_service.py"
click node_voice "https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/services/voice_service.py"
click node_translation "https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/services/translation_service.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_chatui,node_diseaseui,node_landui,node_clientapi,node_authstate,node_authsvc toneBlue
class node_backend,node_authroute,node_chatroute,node_diseaseroute,node_chroma toneAmber
class node_rag,node_hybrid,node_vector,node_embeddings,node_agronomy,node_llm,node_agents toneMint
class node_disease,node_land,node_weather,node_market,node_voice,node_translation toneRose
class node_farmer,node_soilgrids,node_websearch toneIndigo
```

## Components

### Farmer client

- [Web and mobile app](https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Chat interface](https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/frontend/src/pages/Chat.tsx): `frontend/src/pages/Chat.tsx`
- [Disease check](https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/frontend/src/pages/DiseaseCheck.tsx): `frontend/src/pages/DiseaseCheck.tsx`
- [Land planner](https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/frontend/src/pages/LandVisualizer.tsx): `frontend/src/pages/LandVisualizer.tsx`
- [API client](https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/frontend/src/services/api.ts): `frontend/src/services/api.ts`
- [Auth state](https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/frontend/src/hooks/useAuth.tsx): `frontend/src/hooks/useAuth.tsx`
- [Auth client service](https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/frontend/src/services/authService.ts): `frontend/src/services/authService.ts`

### API and identity

- [FastAPI gateway](https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/main.py): `backend/app/main.py`
- [Authentication routes](https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/api/routes/auth.py): `backend/app/api/routes/auth.py`
- [Chat route](https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/api/routes/chat.py): `backend/app/api/routes/chat.py`
- [Disease route](https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/api/routes/disease.py): `backend/app/api/routes/disease.py`

### Advisory intelligence

- [RAG orchestrator](https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/services/rag_service.py): `backend/app/services/rag_service.py`
- [Hybrid retrieval](https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/ai/hybrid_retriever.py): `backend/app/ai/hybrid_retriever.py`
- [Vector retrieval](https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/ai/retriever.py): `backend/app/ai/retriever.py`
- [Embedding service](https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/ai/embeddings.py): `backend/app/ai/embeddings.py`
- [Agronomy reasoning](https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/services/agronomy_reasoning_engine.py): `backend/app/services/agronomy_reasoning_engine.py`
- [Language model](https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/ai/llm.py): `backend/app/ai/llm.py`
- [Agent workflow](https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/ai/agents/graph.py): `backend/app/ai/agents/graph.py`

### Field services

- [Disease diagnostics](https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/services/disease_service.py): `backend/app/services/disease_service.py`
- [Land blueprint](https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/services/land_visualizer_service.py): `backend/app/services/land_visualizer_service.py`
- [Weather advisory](https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/services/weather_service.py): `backend/app/services/weather_service.py`
- [Mandi intelligence](https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/services/mandi_service.py): `backend/app/services/mandi_service.py`
- [Voice services](https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/services/voice_service.py): `backend/app/services/voice_service.py`
- [Translation](https://github.com/darshanthelucifer-png/krishimitra-ai/blob/main/backend/app/services/translation_service.py): `backend/app/services/translation_service.py`

### Other components

- **Farmer**
- **SoilGrids**
- **Agricultural web sources**
- **Chroma vector store**

## Connections

- Farmer → Web and mobile app: uses (evidence: `README.md`)
- Web and mobile app → Chat interface: renders (evidence: `frontend/src/App.tsx`)
- Web and mobile app → Disease check: renders (evidence: `frontend/src/App.tsx`)
- Web and mobile app → Land planner: renders (evidence: `frontend/src/App.tsx`)
- Chat interface → API client: requests through (evidence: `frontend/src/pages/Chat.tsx`)
- Chat interface → Voice services: uses voice client
- Web and mobile app → Auth state: provides auth (evidence: `frontend/src/App.tsx`)
- Auth state → Auth client service: calls (evidence: `frontend/src/hooks/useAuth.tsx`)
- Auth client service → API client: sends auth requests (evidence: `frontend/src/services/authService.ts`)
- API client → FastAPI gateway: sends REST requests (evidence: `README.md`)
- FastAPI gateway → Authentication routes: registers (evidence: `backend/app/main.py`)
- FastAPI gateway → Chat route: registers (evidence: `backend/app/main.py`)
- FastAPI gateway → Disease route: registers (evidence: `backend/app/main.py`)
- Chat route → RAG orchestrator: calls (evidence: `backend/app/api/routes/chat.py`)
- Disease route → Disease diagnostics: calls (evidence: `backend/app/api/routes/disease.py`)
- RAG orchestrator → Hybrid retrieval: retrieves with (evidence: `backend/app/services/rag_service.py`)
- RAG orchestrator → Language model: generates with (evidence: `backend/app/services/rag_service.py`)
- RAG orchestrator → Agronomy reasoning: falls back to (evidence: `README.md`)
- RAG orchestrator → Mandi intelligence: routes price intent (evidence: `backend/app/services/rag_service.py`)
- RAG orchestrator → Agricultural web sources: searches fallback
- Hybrid retrieval → Vector retrieval: queries dense channel (evidence: `backend/app/ai/hybrid_retriever.py`)
- Vector retrieval → Embedding service: embeds queries (evidence: `backend/app/ai/retriever.py`)
- Vector retrieval → Chroma vector store: queries vectors (evidence: `backend/app/ai/retriever.py`)
- Hybrid retrieval → Chroma vector store: loads indexed records (evidence: `backend/app/ai/hybrid_retriever.py`)
- RAG orchestrator → Agent workflow: orchestrates agents (evidence: `README.md`)
- Farmer → Disease check: submits crop photo (evidence: `README.md`)
- Farmer → Land planner: requests farm plan (evidence: `README.md`)
- Land blueprint → SoilGrids: fetches soil profiles (evidence: `README.md`)
- Farmer → Weather advisory: requests weather
- Farmer → Translation: requests translation
- Farmer → Voice services: uses voice loop (evidence: `README.md`)
