# achuabhijith2003/ai-based-crop-disease-detection architecture

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

- Interactive diagram: https://gitdiagram.com/achuabhijith2003/ai-based-crop-disease-detection
- Repository: https://github.com/achuabhijith2003/ai-based-crop-disease-detection

## Overview

1. This repository is a small Flask-based plant disease recognition app with a supporting machine-learning workflow. The runtime app is in `app.py`, while model training/testing logic lives under `core/` and the UI is rendered from `templates/`.

2. The main user-facing boundary is the Flask web layer:
   - `templates/index.html` and `templates/dashboard.html` define the pages.
   - `templates/static/scripts.js` and `templates/static/style.css` provide client-side behavior and styling.
   - The README hints at a camera/photo interaction flow, so the UI likely supports uploading or capturing a plant image and then showing a diagnosis/result.

3. The application entrypoint is `app.py`. It is the central orchestration layer that connects:
   - HTTP requests from the browser,
   - template rendering,
   - image/disease prediction logic,
   - and disease detail lookup/storage.

4. The ML subsystem is split into two parts:
   - `core/train_plant_disease.py` for training the disease classification model,
   - `core/test_plant.py` for running inference on new plant images.
   The Jupyter notebooks `Train_plant_disease.ipynb` and `Test_Plant_Disease.ipynb` appear to be exploratory or interactive versions of those same workflows.

5. The dependency set in `req.txt` shows the system is built around:
   - Flask for the web server,
   - TensorFlow and NumPy for model inference/training,
   - OpenCV for image handling,
   - pandas and openpyxl for tabular/Excel-based disease metadata,
   - matplotlib likely for training visualization or notebook analysis.

6. Disease knowledge is stored separately from the model:
   - `disease_details.xlsx` exists at the repository root,
   - and there is another copy under `DB/`.
   This suggests the app uses an external disease-reference dataset to map predicted classes to human-readable treatment or symptom details.

7. There is a small persistence layer under `core/db_operation.py`, backed by `DB/Treatment.db`. This indicates the app is not purely stateless; it likely reads and/or writes treatment or disease records to SQLite for lookup, history, or metadata management.

8. The data flow is probably:
   - user loads the dashboard,
   - captures or uploads a plant image,
   - Flask receives the request,
   - `core/test_plant.py` classifies the image,
   - the predicted disease label is matched against Excel/SQLite disease details,
   - the result is rendered back into the dashboard template.

9. The repository also contains the training assets needed to reproduce or update the classifier. That makes the architecture two-phase:
   - offline model development/training via notebook or `core/train_plant_disease.py`,
   - online inference via the Flask app and `core/test_plant.py`.
   The deployed web app depends on the output of the training pipeline, even if the exact model artifact file is not listed here.

10. The `DB/` folder is an important boundary: it separates application code from persisted data assets. In an architecture diagram, this would sit alongside the ML model artifact and disease metadata as external resources consumed by the Flask app rather than part of the request-handling code itself.

11. The README’s Flask setup instructions imply a local development deployment, not a cloud-native service. The system appears to run as a single-process local web app with filesystem-backed assets, rather than a distributed architecture.

12. Overall, the repository is best drawn as four layers:
   - browser/UI,
   - Flask application/controller layer,
   - ML inference + disease lookup layer,
   - persistent assets/data layer (model-related files, SQLite DB, Excel metadata).
   The key integration point is `app.py`, which coordinates all of them.

Main entry points: [`app.py`](https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/app.py) (Flask app), [`core/test_plant.py`](https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/core/test_plant.py) (Inference), [`core/train_plant_disease.py`](https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/core/train_plant_disease.py) (Training), [`templates/index.html`](https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/templates/index.html) (Home page)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_ui["Browser UI"]
  node_user(("User<br/>actor"))
  node_index_tpl["Home page<br/>template<br/>[index.html]"]
  node_dashboard_tpl["Dashboard<br/>template<br/>[dashboard.html]"]
  node_scripts_js["Client script<br/>frontend<br/>[scripts.js]"]
  node_style_css["Stylesheet<br/>frontend<br/>[style.css]"]
end

subgraph group_group_app["Flask App"]
  node_app_py["Flask app<br/>controller<br/>[app.py]"]
  node_db_ops["DB ops<br/>storage access<br/>[db_operation.py]"]
end

subgraph group_group_ml["ML Pipeline"]
  node_test_plant["Inference<br/>[test_plant.py]"]
  node_train_plant["Training"]
  node_train_nb["Train notebook"]
  node_test_nb["Test notebook"]
end

subgraph group_group_data["Persistent Data"]
  node_disease_xlsx_root[("Disease sheet<br/>reference data")]
  node_disease_xlsx_db[("DB sheet<br/>reference data")]
  node_treatment_db[("Treatment DB<br/>sqlite database<br/>[Treatment.db]")]
  node_model_artifact{{"Model assets<br/>trained model"}}
  node_requirements["Dependencies<br/>env spec<br/>[req.txt]"]
end

node_user -->|"opens"| node_index_tpl
node_index_tpl -->|"loads"| node_scripts_js
node_index_tpl -->|"styles"| node_style_css
node_scripts_js -->|"submit image"| node_app_py
node_user -->|"views"| node_dashboard_tpl
node_app_py -->|"renders"| node_index_tpl
node_app_py -->|"renders"| node_dashboard_tpl
node_app_py -->|"predicts"| node_test_plant
node_app_py -->|"looks up"| node_db_ops
node_test_plant -->|"loads"| node_model_artifact
node_test_plant -->|"matches"| node_disease_xlsx_root
node_test_plant -->|"matches"| node_disease_xlsx_db
node_db_ops -->|"queries"| node_treatment_db
node_train_plant -->|"produces"| node_model_artifact
node_train_plant -->|"uses data"| node_disease_xlsx_root
node_train_nb -.->|"explores"| node_train_plant
node_test_nb -.->|"explores"| node_test_plant
node_app_py -.->|"depends on"| node_requirements
node_train_plant -.->|"depends on"| node_requirements

click node_index_tpl "https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/templates/index.html"
click node_dashboard_tpl "https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/templates/dashboard.html"
click node_scripts_js "https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/templates/static/scripts.js"
click node_style_css "https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/templates/static/style.css"
click node_app_py "https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/app.py"
click node_db_ops "https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/core/db_operation.py"
click node_test_plant "https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/core/test_plant.py"
click node_train_plant "https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/core/train_plant_disease.py"
click node_train_nb "https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/Train_plant_disease.ipynb"
click node_test_nb "https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/Test_Plant_Disease.ipynb"
click node_disease_xlsx_root "https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/disease_details.xlsx"
click node_disease_xlsx_db "https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/DB/disease_details.xlsx"
click node_treatment_db "https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/DB/Treatment.db"
click node_requirements "https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/req.txt"

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_user,node_index_tpl,node_dashboard_tpl,node_scripts_js,node_style_css toneBlue
class node_app_py,node_db_ops toneAmber
class node_test_plant,node_train_plant,node_train_nb,node_test_nb toneMint
class node_disease_xlsx_root,node_disease_xlsx_db,node_treatment_db,node_model_artifact,node_requirements toneRose
```

## Components

### Browser UI

User-facing pages and client-side assets

- **User**: actor · Person using the crop disease app
- [Home page](https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/templates/index.html): template · Landing page and upload/capture entry point · `templates/index.html`
- [Dashboard](https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/templates/dashboard.html): template · Results and diagnosis view · `templates/dashboard.html`
- [Client script](https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/templates/static/scripts.js): frontend · Browser interaction and UI behavior · `templates/static/scripts.js`
- [Stylesheet](https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/templates/static/style.css): frontend · UI styling for pages · `templates/static/style.css`

### Flask App

Request handling and orchestration

- [Flask app](https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/app.py): controller · Main request router and orchestration layer · `app.py`
- [DB ops](https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/core/db_operation.py): storage access · SQLite read/write and lookup helpers · `core/db_operation.py`

### ML Pipeline

Training and inference logic

- [Inference](https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/core/test_plant.py): ml inference · Classifies plant images into disease labels · `core/test_plant.py`
- [Training](https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/core/train_plant_disease.py): ml training · Builds or updates the disease classifier · `core/train_plant_disease.py`
- [Train notebook](https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/Train_plant_disease.ipynb): notebook · Interactive training workflow · `Train_plant_disease.ipynb`
- [Test notebook](https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/Test_Plant_Disease.ipynb): notebook · Interactive inference workflow · `Test_Plant_Disease.ipynb`

### Persistent Data

Models, databases, and disease reference data

- [Disease sheet](https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/disease_details.xlsx): reference data · Excel disease metadata at repo root · `disease_details.xlsx`
- [DB sheet](https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/DB/disease_details.xlsx): reference data · Excel disease metadata copy under DB · `DB/disease_details.xlsx`
- [Treatment DB](https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/DB/Treatment.db): sqlite database · Persistent treatment or disease records · `DB/Treatment.db`
- **Model assets**: trained model · Trained classifier consumed by inference
- [Dependencies](https://github.com/achuabhijith2003/ai-based-crop-disease-detection/blob/main/req.txt): env spec · Flask, TensorFlow, OpenCV, NumPy, pandas, Excel support · `req.txt`

## Connections

- User → Home page: opens · Starts at the home page
- Home page → Client script: loads · Browser loads client behavior
- Home page → Stylesheet: styles · Browser loads page styling
- Client script → Flask app: submit image · Uploads or captures plant image to Flask
- User → Dashboard: views · Receives diagnosis results
- Flask app → Home page: renders · Serves the entry page
- Flask app → Dashboard: renders · Serves diagnosis and result page
- Flask app → Inference: predicts · Delegates image classification
- Flask app → DB ops: looks up · Fetches disease or treatment details
- Inference → Model assets: loads · Uses trained weights or model files
- Inference → Disease sheet: matches · Maps prediction to human-readable details
- Inference → DB sheet: matches · Alternative disease reference source
- DB ops → Treatment DB: queries · Reads or writes persistent records
- Training → Model assets: produces · Trains the classifier artifact
- Training → Disease sheet: uses data · Consumes labeled disease metadata or training references
- Train notebook → Training: explores · Notebook version of training workflow
- Test notebook → Inference: explores · Notebook version of inference workflow
- Flask app → Dependencies: depends on · Runtime package set for the web app
- Training → Dependencies: depends on · Training stack and scientific libraries
