# saribx/plant-disease-detection-aihws architecture

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

- Interactive diagram: https://gitdiagram.com/saribx/plant-disease-detection-aihws
- Repository: https://github.com/saribx/plant-disease-detection-aihws

## Overview

1. **Repository purpose**
   - This is a plant disease detection system for potato leaves.
   - It combines an ML training/evaluation pipeline with a FastAPI-based inference web app.

2. **Main architectural split**
   - The repo is divided into two clear paths:
     - **Offline ML workflows**: dataset loading, model training, and evaluation.
     - **Online serving/UI**: the web app that accepts an image and returns a prediction.
   - The saved `.keras` model files in `models/` are the handoff point between these two worlds.

3. **Modeling approach**
   - The project maintains **three separate CNN models** for different input modalities:
     - `model_color.keras`
     - `model_grayscale.keras`
     - `model_segmented.keras`
   - This implies the inference layer selects a model based on how the uploaded leaf image is represented or preprocessed.

4. **Data layer**
   - The dataset is organized under `data/` into three parallel variants:
     - `plant_color/`
     - `plant_grayscale/`
     - `plant_segmented/`
   - Each variant contains the same class folders:
     - `Potato___Early_blight`
     - `Potato___Late_blight`
     - `Potato___healthy`
   - This structure is important because it shows the training pipeline is class-based and modality-specific.

5. **Training subsystem**
   - `src/train.py` is the offline entry point for building the models.
   - `src/data_loader.py` likely centralizes dataset ingestion and preprocessing.
   - `src/model.py` likely defines the CNN architecture used for all or most modalities.
   - `src/utils.py` probably contains shared helpers used across training and evaluation.

6. **Evaluation subsystem**
   - `src/evaluate.py` is a separate offline step for measuring model performance.
   - The presence of `evaluation_results.pdf` indicates evaluation outputs are generated as a report artifact, not just printed to console.
   - This makes evaluation a distinct batch process from serving.

7. **Web application layer**
   - `src/app.py` is the runtime server entry point.
   - `src/templates/index.html` plus files in `src/static/` indicate a server-rendered UI with client-side enhancement.
   - `script.js`, `history.js`, and `style.css` are the browser-facing pieces of the app.

8. **Client/server interaction**
   - The browser likely handles image preview locally before upload, while the server handles actual inference.
   - The README says the history sidebar uses `LocalStorage`, so user history is kept on the client rather than in a backend database.
   - There is no evidence of a persistent application database or external storage service.

9. **Inference/runtime boundary**
   - The app serves predictions from pre-trained Keras models rather than training on demand.
   - The README describes lazy-loading models by modality, which suggests the server loads model files only when needed to reduce startup and memory overhead.
   - That makes the inference path lightweight compared with the training path.

10. **Technology stack that matters**
   - **FastAPI** is the web runtime.
   - **Keras/TensorFlow** is the model format/runtime implied by the `.keras` files.
   - **uv** is used for dependency management and launching the app, which affects reproducibility and local setup.
   - The UI is plain HTML/CSS/JavaScript rather than a heavyweight frontend framework.

11. **Operational flow**
   - Typical lifecycle is:
     1. prepare dependencies,
     2. train the CNNs from `data/`,
     3. evaluate and generate the PDF report,
     4. run the FastAPI app using the saved models.
   - The trained artifacts in `models/` are the production inputs for the serving layer.

12. **Key architecture boundaries for a diagram**
   - Draw three boxes: **dataset + preprocessing**, **training/evaluation**, and **web inference UI/server**.
   - Show the `models/` directory as the artifact bridge between training and serving.
   - Show `LocalStorage` as a browser-side store separate from any server persistence.
   - Show the static/templates assets as part of the web UI boundary, not the ML pipeline.

Main entry points: [`src/app.py`](https://github.com/saribx/plant-disease-detection-aihws/blob/main/src/app.py) (FastAPI app), [`src/train.py`](https://github.com/saribx/plant-disease-detection-aihws/blob/main/src/train.py) (Train), [`src/evaluate.py`](https://github.com/saribx/plant-disease-detection-aihws/blob/main/src/evaluate.py) (Evaluate), [`src/data_loader.py`](https://github.com/saribx/plant-disease-detection-aihws/blob/main/src/data_loader.py) (Loader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data"]
  node_data_color[("Color data<br/>dataset")]
  node_data_gray[("Gray data<br/>dataset")]
  node_data_seg[("Segmented data<br/>dataset")]
end

subgraph group_offline["Offline ML"]
  node_loader["Loader<br/>preprocess<br/>[data_loader.py]"]
  node_model_def["CNN model<br/>architecture<br/>[model.py]"]
  node_train["Train<br/>pipeline<br/>[train.py]"]
  node_evaluate["Evaluate<br/>pipeline<br/>[evaluate.py]"]
end

subgraph group_artifacts["Artifacts"]
  node_model_color["Color model<br/>keras model<br/>[model_color.keras]"]
  node_model_gray["Gray model<br/>keras model"]
  node_model_seg["Segmented model<br/>keras model"]
  node_report["Report"]
end

subgraph group_serving["Serving UI"]
  node_app["FastAPI app<br/>server<br/>[app.py]"]
  node_template["Index page<br/>html template<br/>[index.html]"]
  node_script["Script<br/>browser js<br/>[script.js]"]
  node_history["History<br/>browser js<br/>[history.js]"]
  node_style["Styles<br/>css<br/>[style.css]"]
  node_storage[("LocalStorage<br/>browser store")]
end

node_loader -->|"reads"| node_data_color
node_loader -->|"reads"| node_data_gray
node_loader -->|"reads"| node_data_seg
node_train -->|"uses"| node_loader
node_train -->|"builds"| node_model_def
node_train -->|"writes"| node_model_color
node_train -->|"writes"| node_model_gray
node_train -->|"writes"| node_model_seg
node_evaluate -->|"loads"| node_model_color
node_evaluate -->|"loads"| node_model_gray
node_evaluate -->|"loads"| node_model_seg
node_evaluate -->|"exports"| node_report
node_app -->|"serves"| node_model_color
node_app -->|"serves"| node_model_gray
node_app -->|"serves"| node_model_seg
node_app -->|"renders"| node_template
node_app -->|"serves"| node_script
node_app -->|"serves"| node_history
node_app -->|"serves"| node_style
node_script -->|"stores"| node_storage
node_history -->|"reads"| node_storage

click node_data_color "https://github.com/saribx/plant-disease-detection-aihws/tree/main/data/plant_color"
click node_data_gray "https://github.com/saribx/plant-disease-detection-aihws/tree/main/data/plant_grayscale"
click node_data_seg "https://github.com/saribx/plant-disease-detection-aihws/tree/main/data/plant_segmented"
click node_loader "https://github.com/saribx/plant-disease-detection-aihws/blob/main/src/data_loader.py"
click node_model_def "https://github.com/saribx/plant-disease-detection-aihws/blob/main/src/model.py"
click node_train "https://github.com/saribx/plant-disease-detection-aihws/blob/main/src/train.py"
click node_evaluate "https://github.com/saribx/plant-disease-detection-aihws/blob/main/src/evaluate.py"
click node_model_color "https://github.com/saribx/plant-disease-detection-aihws/blob/main/models/model_color.keras"
click node_model_gray "https://github.com/saribx/plant-disease-detection-aihws/blob/main/models/model_grayscale.keras"
click node_model_seg "https://github.com/saribx/plant-disease-detection-aihws/blob/main/models/model_segmented.keras"
click node_report "https://github.com/saribx/plant-disease-detection-aihws/blob/main/evaluation_results.pdf"
click node_app "https://github.com/saribx/plant-disease-detection-aihws/blob/main/src/app.py"
click node_template "https://github.com/saribx/plant-disease-detection-aihws/blob/main/src/templates/index.html"
click node_script "https://github.com/saribx/plant-disease-detection-aihws/blob/main/src/static/script.js"
click node_history "https://github.com/saribx/plant-disease-detection-aihws/blob/main/src/static/history.js"
click node_style "https://github.com/saribx/plant-disease-detection-aihws/blob/main/src/static/style.css"

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_data_color,node_data_gray,node_data_seg toneBlue
class node_loader,node_model_def,node_train,node_evaluate toneAmber
class node_model_color,node_model_gray,node_model_seg,node_report toneMint
class node_app,node_template,node_script,node_history,node_style,node_storage toneRose
```

## Components

### Data

Modality-specific training datasets grouped by representation.

- [Color data](https://github.com/saribx/plant-disease-detection-aihws/tree/main/data/plant_color): dataset · Color image training set for potato leaf classes. · `data/plant_color`
- [Gray data](https://github.com/saribx/plant-disease-detection-aihws/tree/main/data/plant_grayscale): dataset · Grayscale image training set for potato leaf classes. · `data/plant_grayscale`
- [Segmented data](https://github.com/saribx/plant-disease-detection-aihws/tree/main/data/plant_segmented): dataset · Segmented leaf training set for potato leaf classes. · `data/plant_segmented`

### Offline ML

Training, model definition, and evaluation pipeline.

- [Loader](https://github.com/saribx/plant-disease-detection-aihws/blob/main/src/data_loader.py): preprocess · Central dataset ingestion and preprocessing logic. · `src/data_loader.py`
- [CNN model](https://github.com/saribx/plant-disease-detection-aihws/blob/main/src/model.py): architecture · Shared CNN definition used for the disease classifiers. · `src/model.py`
- [Train](https://github.com/saribx/plant-disease-detection-aihws/blob/main/src/train.py): pipeline · Offline training entry point for building models. · `src/train.py`
- [Evaluate](https://github.com/saribx/plant-disease-detection-aihws/blob/main/src/evaluate.py): pipeline · Offline evaluation step that measures model performance. · `src/evaluate.py`

### Artifacts

Saved models and generated evaluation outputs.

- [Color model](https://github.com/saribx/plant-disease-detection-aihws/blob/main/models/model_color.keras): keras model · Saved Keras model for the color modality. · `models/model_color.keras`
- [Gray model](https://github.com/saribx/plant-disease-detection-aihws/blob/main/models/model_grayscale.keras): keras model · Saved Keras model for the grayscale modality. · `models/model_grayscale.keras`
- [Segmented model](https://github.com/saribx/plant-disease-detection-aihws/blob/main/models/model_segmented.keras): keras model · Saved Keras model for the segmented modality. · `models/model_segmented.keras`
- [Report](https://github.com/saribx/plant-disease-detection-aihws/blob/main/evaluation_results.pdf): evaluation report · Generated evaluation output artifact. · `evaluation_results.pdf`

### Serving UI

FastAPI runtime plus browser-facing templates and static assets.

- [FastAPI app](https://github.com/saribx/plant-disease-detection-aihws/blob/main/src/app.py): server · Runtime inference entry point and HTTP API. · `src/app.py`
- [Index page](https://github.com/saribx/plant-disease-detection-aihws/blob/main/src/templates/index.html): html template · Server-rendered landing page for image upload and results. · `src/templates/index.html`
- [Script](https://github.com/saribx/plant-disease-detection-aihws/blob/main/src/static/script.js): browser js · Client-side upload, preview, and interaction logic. · `src/static/script.js`
- [History](https://github.com/saribx/plant-disease-detection-aihws/blob/main/src/static/history.js): browser js · Client-side prediction history and local persistence. · `src/static/history.js`
- [Styles](https://github.com/saribx/plant-disease-detection-aihws/blob/main/src/static/style.css): css · Presentation styling for the web UI. · `src/static/style.css`
- **LocalStorage**: browser store · Client-side history store with no backend database.

## Connections

- Loader → Color data: reads · Loads color modality training data.
- Loader → Gray data: reads · Loads grayscale modality training data.
- Loader → Segmented data: reads · Loads segmented modality training data.
- Train → Loader: uses · Training depends on centralized loading and preprocessing.
- Train → CNN model: builds · Constructs the CNN architecture for training.
- Train → Color model: writes · Produces the color model artifact.
- Train → Gray model: writes · Produces the grayscale model artifact.
- Train → Segmented model: writes · Produces the segmented model artifact.
- Evaluate → Color model: loads · Evaluates the trained color model.
- Evaluate → Gray model: loads · Evaluates the trained grayscale model.
- Evaluate → Segmented model: loads · Evaluates the trained segmented model.
- Evaluate → Report: exports · Generates the PDF evaluation report.
- FastAPI app → Color model: serves · Uses the color model for inference when needed.
- FastAPI app → Gray model: serves · Uses the grayscale model for inference when needed.
- FastAPI app → Segmented model: serves · Uses the segmented model for inference when needed.
- FastAPI app → Index page: renders · Serves the UI shell to the browser.
- FastAPI app → Script: serves · Exposes client-side interaction logic.
- FastAPI app → History: serves · Exposes prediction history behavior.
- FastAPI app → Styles: serves · Exposes UI styling assets.
- Script → LocalStorage: stores · Keeps client-side prediction history in the browser.
- History → LocalStorage: reads · Restores prior history from browser storage.
