# harshayalagani29/crop-disease-ai architecture

> Architecture diagram of the GitHub repository harshayalagani29/crop-disease-ai, 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/harshayalagani29/crop-disease-ai
- Repository: https://github.com/harshayalagani29/crop-disease-ai

## Overview

This MVP lets a farmer submit a leaf image and location, then returns a disease classification, risk assessment, recommendation, and optional weather context; a history view retrieves prior predictions. The API coordinates inference, weather lookup, scoring, guidance, and SQLite persistence. Separately, the ML scripts prepare data, train the MobileNetV2 model, and evaluate it. The README documents those capabilities, while the shown API and UI excerpts provide direct evidence for the main runtime calls; some training-to-runtime links are documented rather than visible in source.

Main entry points: [`backend/main.py`](https://github.com/harshayalagani29/crop-disease-ai/blob/main/backend/main.py) (FastAPI endpoints), [`frontend/src/App.jsx`](https://github.com/harshayalagani29/crop-disease-ai/blob/main/frontend/src/App.jsx) (Detection and history UI), [`ml/train.py`](https://github.com/harshayalagani29/crop-disease-ai/blob/main/ml/train.py) (MobileNetV2 training), [`ml/split_dataset.py`](https://github.com/harshayalagani29/crop-disease-ai/blob/main/ml/split_dataset.py) (Dataset splitting)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Farmer interface"]
  node_web_app["Detection and history UI<br/>[App.jsx]"]
  node_translations["English and Kannada<br/>[i18n.js]"]
  node_web_entry["React entry<br/>[main.jsx]"]
end

subgraph group_backend["Decision API"]
  node_api["FastAPI endpoints<br/>[main.py]"]
  node_inference["Image inference<br/>[model_service.py]"]
  node_risk["Risk scoring<br/>[risk_engine.py]"]
  node_guidance["Recommendations<br/>[recommendations.py]"]
end

subgraph group_storage["Persistence and services"]
  node_weather_service["Weather API"]
  node_sqlite[("SQLite database<br/>[db.py]")]
end

subgraph group_ml["Model lifecycle"]
  node_class_extraction["Class extraction<br/>[extract_classes.py]"]
  node_dataset_split["Dataset splitting<br/>[split_dataset.py]"]
  node_training["MobileNetV2 training<br/>[train.py]"]
  node_evaluation["Model evaluation<br/>[evaluate.py]"]
end

node_farmer(("Farmer"))

node_farmer -->|"uses"| node_web_app
node_web_entry -->|"renders"| node_web_app
node_web_app -->|"uses labels"| node_translations
node_web_app -->|"requests predictions and history"| node_api
node_api -->|"runs inference"| node_inference
node_api -->|"fetches weather"| node_weather_service
node_api -->|"assesses risk"| node_risk
node_api -->|"gets recommendation"| node_guidance
node_api -->|"initializes and reads/writes"| node_sqlite
node_class_extraction -.->|"prepares source images"| node_dataset_split
node_dataset_split -.->|"prepares training data"| node_training
node_training -.->|"provides trained model"| node_evaluation
node_training -.->|"supplies model for inference"| node_inference

click node_web_app "https://github.com/harshayalagani29/crop-disease-ai/blob/main/frontend/src/App.jsx"
click node_translations "https://github.com/harshayalagani29/crop-disease-ai/blob/main/frontend/src/i18n.js"
click node_web_entry "https://github.com/harshayalagani29/crop-disease-ai/blob/main/frontend/src/main.jsx"
click node_api "https://github.com/harshayalagani29/crop-disease-ai/blob/main/backend/main.py"
click node_inference "https://github.com/harshayalagani29/crop-disease-ai/blob/main/backend/model_service.py"
click node_risk "https://github.com/harshayalagani29/crop-disease-ai/blob/main/backend/risk_engine.py"
click node_guidance "https://github.com/harshayalagani29/crop-disease-ai/blob/main/backend/recommendations.py"
click node_sqlite "https://github.com/harshayalagani29/crop-disease-ai/blob/main/backend/db.py"
click node_class_extraction "https://github.com/harshayalagani29/crop-disease-ai/blob/main/ml/extract_classes.py"
click node_dataset_split "https://github.com/harshayalagani29/crop-disease-ai/blob/main/ml/split_dataset.py"
click node_training "https://github.com/harshayalagani29/crop-disease-ai/blob/main/ml/train.py"
click node_evaluation "https://github.com/harshayalagani29/crop-disease-ai/blob/main/ml/evaluate.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_app,node_translations,node_web_entry toneBlue
class node_api,node_inference,node_risk,node_guidance toneAmber
class node_weather_service,node_sqlite toneMint
class node_class_extraction,node_dataset_split,node_training,node_evaluation toneRose
class node_farmer toneIndigo
```

## Components

### Farmer interface

- [Detection and history UI](https://github.com/harshayalagani29/crop-disease-ai/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [English and Kannada](https://github.com/harshayalagani29/crop-disease-ai/blob/main/frontend/src/i18n.js): `frontend/src/i18n.js`
- [React entry](https://github.com/harshayalagani29/crop-disease-ai/blob/main/frontend/src/main.jsx): `frontend/src/main.jsx`

### Decision API

- [FastAPI endpoints](https://github.com/harshayalagani29/crop-disease-ai/blob/main/backend/main.py): `backend/main.py`
- [Image inference](https://github.com/harshayalagani29/crop-disease-ai/blob/main/backend/model_service.py): `backend/model_service.py`
- [Risk scoring](https://github.com/harshayalagani29/crop-disease-ai/blob/main/backend/risk_engine.py): `backend/risk_engine.py`
- [Recommendations](https://github.com/harshayalagani29/crop-disease-ai/blob/main/backend/recommendations.py): `backend/recommendations.py`

### Persistence and services

- **Weather API**
- [SQLite database](https://github.com/harshayalagani29/crop-disease-ai/blob/main/backend/db.py): `backend/db.py`

### Model lifecycle

- [Class extraction](https://github.com/harshayalagani29/crop-disease-ai/blob/main/ml/extract_classes.py): `ml/extract_classes.py`
- [Dataset splitting](https://github.com/harshayalagani29/crop-disease-ai/blob/main/ml/split_dataset.py): `ml/split_dataset.py`
- [MobileNetV2 training](https://github.com/harshayalagani29/crop-disease-ai/blob/main/ml/train.py): `ml/train.py`
- [Model evaluation](https://github.com/harshayalagani29/crop-disease-ai/blob/main/ml/evaluate.py): `ml/evaluate.py`

### Other components

- **Farmer**

## Connections

- Farmer → Detection and history UI: uses (evidence: `README.md`)
- React entry → Detection and history UI: renders (evidence: `frontend/src/main.jsx`)
- Detection and history UI → English and Kannada: uses labels (evidence: `frontend/src/App.jsx`)
- Detection and history UI → FastAPI endpoints: requests predictions and history (evidence: `frontend/src/App.jsx`)
- FastAPI endpoints → Image inference: runs inference (evidence: `backend/main.py`)
- FastAPI endpoints → Weather API: fetches weather (evidence: `backend/main.py`)
- FastAPI endpoints → Risk scoring: assesses risk (evidence: `backend/main.py`)
- FastAPI endpoints → Recommendations: gets recommendation (evidence: `backend/main.py`)
- FastAPI endpoints → SQLite database: initializes and reads/writes (evidence: `backend/main.py`)
- Class extraction → Dataset splitting: prepares source images
- Dataset splitting → MobileNetV2 training: prepares training data (evidence: `README.md`)
- MobileNetV2 training → Model evaluation: provides trained model (evidence: `README.md`)
- MobileNetV2 training → Image inference: supplies model for inference (evidence: `README.md`)
