# karankarpe22/ai-agriculture-disease-detection-assistant architecture

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

- Interactive diagram: https://gitdiagram.com/karankarpe22/ai-agriculture-disease-detection-assistant
- Repository: https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant

## Overview

Krishi Sahayyak is an agricultural decision-support application. A farmer submits a leaf image or question through the web interface; the FastAPI backend invokes a LangGraph workflow, which can validate and classify images, gather weather, soil, and agronomic evidence, and synthesize bilingual advice. The result is returned to the interface, with speech synthesis available separately. The graph reflects documented workflow stages and sampled service calls; several frontend/API and internal workflow links rely on README documentation because their implementation excerpts were incomplete.

Main entry points: [`src/graph/nodes.py`](https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/src/graph/nodes.py) (Workflow Nodes), [`backend/main.py`](https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/backend/main.py) (FastAPI API), [`src/graph/workflow.py`](https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/src/graph/workflow.py) (StateGraph Workflow), [`src/prediction/predict.py`](https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/src/prediction/predict.py) (Disease Prediction)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User Interface"]
  node_web["Web Interface<br/>[app.js]"]
end

subgraph group_orchestration["API &amp; Orchestration"]
  node_api["FastAPI API<br/>[main.py]"]
  node_workflow["StateGraph Workflow<br/>[workflow.py]"]
  node_state["Workflow State<br/>[state.py]"]
  node_nodes["Workflow Nodes<br/>[nodes.py]"]
end

subgraph group_diagnosis["Leaf Diagnosis"]
  node_quality["Image Quality Check<br/>[quality_check.py]"]
  node_prediction["Disease Prediction<br/>[predict.py]"]
  node_model["MobileNetV3 Model<br/>[model.py]"]
  node_transforms["Image Transforms<br/>[transforms.py]"]
end

subgraph group_context["Agronomic Context"]
  node_weather["Weather Risk<br/>[weather_service.py]"]
  node_weather_api["Weather Providers"]
  node_soil["Soil Profile<br/>[soil_service.py]"]
  node_soil_data[("Soil Records")]
  node_rag["Evidence Retrieval<br/>[vector_store.py]"]
  node_knowledge["Agronomy Knowledge"]
  node_rag_index[("FAISS Index<br/>[rag_index.faiss]")]
end

subgraph group_advisory["Advice &amp; Access"]
  node_guidance["Gemini Guidance"]
  node_gemini["Google Gemini"]
  node_localization["English-Marathi Localization<br/>[localization.py]"]
  node_voice["Voice Synthesis<br/>[voice_service.py]"]
  node_tts["Speech Providers"]
end

node_farmer(("Farmer"))

node_farmer -->|"submits request"| node_web
node_web -.->|"calls API"| node_api
node_api -->|"runs workflow"| node_workflow
node_workflow -->|"dispatches stages"| node_nodes
node_workflow -->|"shares state"| node_state
node_nodes -->|"checks image"| node_quality
node_nodes -->|"requests prediction"| node_prediction
node_prediction -->|"checks quality"| node_quality
node_prediction -->|"applies transforms"| node_transforms
node_prediction -->|"runs inference"| node_model
node_nodes -->|"fetches weather"| node_weather
node_weather -->|"queries providers"| node_weather_api
node_nodes -->|"requests profile"| node_soil
node_soil -->|"loads records"| node_soil_data
node_nodes -->|"retrieves evidence"| node_rag
node_rag -->|"grounds retrieval"| node_knowledge
node_rag -->|"searches index"| node_rag_index
node_nodes -->|"requests synthesis"| node_guidance
node_guidance -->|"generates advice"| node_gemini
node_workflow -->|"uses translations"| node_localization
node_api -->|"generates speech"| node_voice
node_voice -->|"synthesizes audio"| node_tts
node_api -->|"serves interface"| node_web
node_api -->|"formats response"| node_state
node_api -->|"serves weather"| node_weather

click node_web "https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/frontend/app.js"
click node_api "https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/backend/main.py"
click node_workflow "https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/src/graph/workflow.py"
click node_state "https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/src/graph/state.py"
click node_nodes "https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/src/graph/nodes.py"
click node_quality "https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/src/preprocessing/quality_check.py"
click node_prediction "https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/src/prediction/predict.py"
click node_model "https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/src/training/model.py"
click node_transforms "https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/src/preprocessing/transforms.py"
click node_weather "https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/src/weather/weather_service.py"
click node_soil "https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/src/soil/soil_service.py"
click node_soil_data "https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/data/soil/synthetic_soil_records.json"
click node_rag "https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/src/rag/vector_store.py"
click node_knowledge "https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/tree/main/knowledge_base"
click node_rag_index "https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/models/rag_index.faiss"
click node_guidance "https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/src/gemini/guidance_service.py"
click node_localization "https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/src/utils/localization.py"
click node_voice "https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/src/utils/voice_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_web toneBlue
class node_api,node_workflow,node_state,node_nodes toneAmber
class node_quality,node_prediction,node_model,node_transforms toneMint
class node_weather,node_weather_api,node_soil,node_soil_data,node_rag,node_knowledge,node_rag_index toneRose
class node_guidance,node_gemini,node_localization,node_voice,node_tts,node_farmer toneIndigo
```

## Components

### User Interface

- [Web Interface](https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/frontend/app.js): `frontend/app.js`

### API & Orchestration

- [FastAPI API](https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/backend/main.py): `backend/main.py`
- [StateGraph Workflow](https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/src/graph/workflow.py): `src/graph/workflow.py`
- [Workflow State](https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/src/graph/state.py): `src/graph/state.py`
- [Workflow Nodes](https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/src/graph/nodes.py): `src/graph/nodes.py`

### Leaf Diagnosis

- [Image Quality Check](https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/src/preprocessing/quality_check.py): `src/preprocessing/quality_check.py`
- [Disease Prediction](https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/src/prediction/predict.py): `src/prediction/predict.py`
- [MobileNetV3 Model](https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/src/training/model.py): `src/training/model.py`
- [Image Transforms](https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/src/preprocessing/transforms.py): `src/preprocessing/transforms.py`

### Agronomic Context

- [Weather Risk](https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/src/weather/weather_service.py): `src/weather/weather_service.py`
- **Weather Providers**
- [Soil Profile](https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/src/soil/soil_service.py): `src/soil/soil_service.py`
- [Soil Records](https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/data/soil/synthetic_soil_records.json): `data/soil/synthetic_soil_records.json`
- [Evidence Retrieval](https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/src/rag/vector_store.py): `src/rag/vector_store.py`
- [Agronomy Knowledge](https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/tree/main/knowledge_base): `knowledge_base`
- [FAISS Index](https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/models/rag_index.faiss): `models/rag_index.faiss`

### Advice & Access

- [Gemini Guidance](https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/src/gemini/guidance_service.py): `src/gemini/guidance_service.py`
- **Google Gemini**
- [English-Marathi Localization](https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/src/utils/localization.py): `src/utils/localization.py`
- [Voice Synthesis](https://github.com/karankarpe22/ai-agriculture-disease-detection-assistant/blob/main/src/utils/voice_service.py): `src/utils/voice_service.py`
- **Speech Providers**

### Other components

- **Farmer**

## Connections

- Farmer → Web Interface: submits request (evidence: `README.md`)
- Web Interface → FastAPI API: calls API
- FastAPI API → StateGraph Workflow: runs workflow (evidence: `backend/main.py`)
- StateGraph Workflow → Workflow Nodes: dispatches stages (evidence: `README.md`)
- StateGraph Workflow → Workflow State: shares state (evidence: `README.md`)
- Workflow Nodes → Image Quality Check: checks image (evidence: `src/graph/nodes.py`)
- Workflow Nodes → Disease Prediction: requests prediction (evidence: `src/graph/nodes.py`)
- Disease Prediction → Image Quality Check: checks quality (evidence: `src/prediction/predict.py`)
- Disease Prediction → Image Transforms: applies transforms (evidence: `src/prediction/predict.py`)
- Disease Prediction → MobileNetV3 Model: runs inference (evidence: `src/prediction/predict.py`)
- Workflow Nodes → Weather Risk: fetches weather (evidence: `src/graph/nodes.py`)
- Weather Risk → Weather Providers: queries providers (evidence: `src/weather/weather_service.py`)
- Workflow Nodes → Soil Profile: requests profile (evidence: `src/graph/nodes.py`)
- Soil Profile → Soil Records: loads records (evidence: `src/soil/soil_service.py`)
- Workflow Nodes → Evidence Retrieval: retrieves evidence (evidence: `src/graph/nodes.py`)
- Evidence Retrieval → Agronomy Knowledge: grounds retrieval (evidence: `README.md`)
- Evidence Retrieval → FAISS Index: searches index (evidence: `README.md`)
- Workflow Nodes → Gemini Guidance: requests synthesis (evidence: `src/graph/nodes.py`)
- Gemini Guidance → Google Gemini: generates advice (evidence: `README.md`)
- StateGraph Workflow → English-Marathi Localization: uses translations (evidence: `src/graph/workflow.py`)
- FastAPI API → Voice Synthesis: generates speech (evidence: `backend/main.py`)
- Voice Synthesis → Speech Providers: synthesizes audio (evidence: `README.md`)
- FastAPI API → Web Interface: serves interface (evidence: `backend/main.py`)
- FastAPI API → Workflow State: formats response (evidence: `backend/main.py`)
- FastAPI API → Weather Risk: serves weather (evidence: `backend/main.py`)
