# tusm11/crop-disease-detection-and-fertilizer-recommendation-system architecture

> Architecture diagram of the GitHub repository tusm11/crop-disease-detection-and-fertilizer-recommendation-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system
- Repository: https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system

## Overview

This is a Streamlit crop-health application with two user-facing workflows: leaf-image disease diagnosis and soil/crop-based fertilizer recommendation. The app coordinates image preprocessing and CNN inference, then uses the predicted crop and selected soil type for fertilizer prediction and SHAP explanations. The README also documents disease-indicator heatmaps. Some UI and heatmap implementation lines were not sampled, so those capabilities are represented from README documentation rather than inferred source calls.

Main entry points: [`app.py`](https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/blob/main/app.py) (Fertilizer prediction), [`soil_lookup.py`](https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/blob/main/soil_lookup.py) (Soil-crop values), [`models/fertilizer_ada_model.pkl`](https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/blob/main/models/fertilizer_ada_model.pkl) (AdaBoost model), [`models/plant_cnn_model.keras`](https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/blob/main/models/plant_cnn_model.keras) (CNN model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Streamlit application"]
  node_app["Application UI<br/>[app.py]"]
  node_image_upload["Image upload<br/>[app.py]"]
  node_fertilizer_ui["Soil selection<br/>[app.py]"]
end

subgraph group_disease["Disease diagnosis"]
  node_disease_inference["CNN inference<br/>[app.py]"]
  node_disease_result["Disease diagnosis<br/>[app.py]"]
  node_impact_map["Feature impact map<br/>[app.py]"]
end

subgraph group_fertilizer["Fertilizer recommendation"]
  node_soil_lookup["Soil-crop values<br/>[soil_lookup.py]"]
  node_fertilizer_prediction["Fertilizer prediction<br/>[app.py]"]
  node_shap_explanation["SHAP explanation<br/>[app.py]"]
end

subgraph group_assets["Data and models"]
  node_cnn_model["CNN model"]
  node_class_labels["Disease labels<br/>[class_names.json]"]
  node_recommendation_data[("Recommendation data")]
  node_ada_model["AdaBoost model"]
  node_model_inputs["Encoders and scaler"]
end

node_farmer(("Grower"))

node_farmer -->|"uses"| node_app
node_app -->|"offers upload"| node_image_upload
node_image_upload -->|"provides image"| node_disease_inference
node_disease_inference -->|"loads model"| node_cnn_model
node_disease_inference -.->|"uses labels"| node_class_labels
node_disease_inference -->|"predicts class"| node_disease_result
node_disease_result -.->|"visualizes indicators"| node_impact_map
node_app -->|"offers selection"| node_fertilizer_ui
node_fertilizer_ui -->|"requests recommendation"| node_fertilizer_prediction
node_fertilizer_prediction -->|"gets values"| node_soil_lookup
node_soil_lookup -->|"samples rows"| node_recommendation_data
node_fertilizer_prediction -->|"predicts fertilizer"| node_ada_model
node_fertilizer_prediction -->|"uses encoders"| node_model_inputs
node_fertilizer_prediction -->|"computes attribution"| node_shap_explanation
node_shap_explanation -->|"explains prediction"| node_ada_model
node_disease_result -->|"shows diagnosis"| node_farmer
node_fertilizer_prediction -->|"shows recommendation"| node_farmer
node_shap_explanation -->|"shows rationale"| node_farmer

click node_app "https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/blob/main/app.py"
click node_image_upload "https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/blob/main/app.py"
click node_disease_inference "https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/blob/main/app.py"
click node_disease_result "https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/blob/main/app.py"
click node_impact_map "https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/blob/main/app.py"
click node_cnn_model "https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/blob/main/models/plant_cnn_model.keras"
click node_class_labels "https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/blob/main/models/class_names.json"
click node_fertilizer_ui "https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/blob/main/app.py"
click node_soil_lookup "https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/blob/main/soil_lookup.py"
click node_recommendation_data "https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/blob/main/fertilizer_recommendation.csv"
click node_ada_model "https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/blob/main/models/fertilizer_ada_model.pkl"
click node_model_inputs "https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/tree/main/models"
click node_fertilizer_prediction "https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/blob/main/app.py"
click node_shap_explanation "https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/blob/main/app.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_image_upload,node_fertilizer_ui toneBlue
class node_disease_inference,node_disease_result,node_impact_map toneAmber
class node_soil_lookup,node_fertilizer_prediction,node_shap_explanation toneMint
class node_cnn_model,node_class_labels,node_recommendation_data,node_ada_model,node_model_inputs toneRose
class node_farmer toneIndigo
```

## Components

### Streamlit application

- [Application UI](https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/blob/main/app.py): `app.py`
- [Image upload](https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/blob/main/app.py): `app.py`
- [Soil selection](https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/blob/main/app.py): `app.py`

### Disease diagnosis

- [CNN inference](https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/blob/main/app.py): `app.py`
- [Disease diagnosis](https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/blob/main/app.py): `app.py`
- [Feature impact map](https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/blob/main/app.py): `app.py`

### Fertilizer recommendation

- [Soil-crop values](https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/blob/main/soil_lookup.py): `soil_lookup.py`
- [Fertilizer prediction](https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/blob/main/app.py): `app.py`
- [SHAP explanation](https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/blob/main/app.py): `app.py`

### Data and models

- [CNN model](https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/blob/main/models/plant_cnn_model.keras): `models/plant_cnn_model.keras`
- [Disease labels](https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/blob/main/models/class_names.json): `models/class_names.json`
- [Recommendation data](https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/blob/main/fertilizer_recommendation.csv): `fertilizer_recommendation.csv`
- [AdaBoost model](https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/blob/main/models/fertilizer_ada_model.pkl): `models/fertilizer_ada_model.pkl`
- [Encoders and scaler](https://github.com/tusm11/crop-disease-detection-and-fertilizer-recommendation-system/tree/main/models): `models`

### Other components

- **Grower**

## Connections

- Grower → Application UI: uses (evidence: `README.md`)
- Application UI → Image upload: offers upload (evidence: `app.py`)
- Image upload → CNN inference: provides image (evidence: `app.py`)
- CNN inference → CNN model: loads model (evidence: `app.py`)
- CNN inference → Disease labels: uses labels (evidence: `README.md`)
- CNN inference → Disease diagnosis: predicts class (evidence: `README.md`)
- Disease diagnosis → Feature impact map: visualizes indicators (evidence: `README.md`)
- Application UI → Soil selection: offers selection (evidence: `app.py`)
- Soil selection → Fertilizer prediction: requests recommendation (evidence: `app.py`)
- Fertilizer prediction → Soil-crop values: gets values (evidence: `app.py`)
- Soil-crop values → Recommendation data: samples rows (evidence: `soil_lookup.py`)
- Fertilizer prediction → AdaBoost model: predicts fertilizer (evidence: `app.py`)
- Fertilizer prediction → Encoders and scaler: uses encoders (evidence: `app.py`)
- Fertilizer prediction → SHAP explanation: computes attribution (evidence: `app.py`)
- SHAP explanation → AdaBoost model: explains prediction (evidence: `app.py`)
- Disease diagnosis → Grower: shows diagnosis (evidence: `README.md`)
- Fertilizer prediction → Grower: shows recommendation (evidence: `README.md`)
- SHAP explanation → Grower: shows rationale (evidence: `README.md`)
