# sthasus/tomato_leaf_disease_detection architecture

> Architecture diagram of the GitHub repository sthasus/tomato_leaf_disease_detection, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sthasus/tomato_leaf_disease_detection
- Repository: https://github.com/sthasus/tomato_leaf_disease_detection

## Overview

Tomato Leaf Disease Detector is a Django application for account-based tomato-leaf diagnosis. A user signs up or logs in, uploads a JPG/PNG leaf image, and receives a predicted class, confidence, care guidance, and optionally an explanation; logged-in users can revisit saved predictions, while model metrics are public. Separately, the documented training workflow produces the model and metrics consumed by the app. The request and inference paths are shown from excerpts; training-to-artifact links follow README documentation, since the notebook was not sampled.

Main entry points: [`detector/views.py`](https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/detector/views.py) (Upload handler), [`detector/urls.py`](https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/detector/urls.py) (Detector routes), [`detector/inference.py`](https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/detector/inference.py) (Image inference), [`ml_model/train.ipynb`](https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/ml_model/train.ipynb) (Model training)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_detector_routes["Detector routes<br/>[urls.py]"]
  node_landing["Landing page<br/>[views.py]"]
  node_upload_view["Upload handler<br/>[views.py]"]
  node_image_form["Image validation<br/>[forms.py]"]
  node_history_view["Prediction history<br/>[views.py]"]
  node_performance_view["Metrics page<br/>[views.py]"]
  node_prediction_records[("Prediction records<br/>[models.py]")]
  node_uploaded_images[("Uploaded images")]
end

subgraph group_accounts["Accounts"]
  node_signup_routes["Account routes<br/>[urls.py]"]
  node_signup_view["Signup handler<br/>[views.py]"]
  node_signup_form["Signup validation<br/>[forms.py]"]
end

subgraph group_inference["Diagnosis"]
  node_inference["Image inference<br/>[inference.py]"]
  node_explanation["LIME explanation<br/>[explain.py]"]
  node_disease_guidance["Disease guidance<br/>[disease_info.py]"]
end

subgraph group_training["Model lifecycle"]
  node_training["Model training<br/>[train.ipynb]"]
  node_model_weights["Model weights"]
  node_class_labels["Class labels<br/>[class_names.json]"]
  node_model_metrics["Model metrics<br/>[metrics.json]"]
end

node_visitor(("Visitor"))

node_visitor -->|"requests pages"| node_detector_routes
node_detector_routes -->|"routes to"| node_landing
node_detector_routes -->|"routes to"| node_upload_view
node_detector_routes -->|"routes to"| node_history_view
node_detector_routes -->|"routes to"| node_performance_view
node_visitor -->|"requests account"| node_signup_routes
node_signup_routes -->|"routes to"| node_signup_view
node_signup_view -->|"uses form"| node_signup_form
node_upload_view -->|"validates upload"| node_image_form
node_upload_view -->|"saves image"| node_uploaded_images
node_upload_view -->|"predicts image"| node_inference
node_inference -.->|"loads weights"| node_model_weights
node_inference -.->|"loads labels"| node_class_labels
node_upload_view -->|"gets care tips"| node_disease_guidance
node_upload_view -->|"saves result"| node_prediction_records
node_upload_view -->|"optionally explains"| node_explanation
node_explanation -->|"reuses model"| node_inference
node_history_view -->|"reads history"| node_prediction_records
node_history_view -->|"gets care tips"| node_disease_guidance
node_performance_view -->|"reads metrics"| node_model_metrics
node_performance_view -->|"formats labels"| node_disease_guidance
node_training -.->|"exports weights"| node_model_weights
node_training -.->|"exports labels"| node_class_labels
node_training -.->|"exports metrics"| node_model_metrics

click node_detector_routes "https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/detector/urls.py"
click node_landing "https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/detector/views.py"
click node_upload_view "https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/detector/views.py"
click node_image_form "https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/detector/forms.py"
click node_history_view "https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/detector/views.py"
click node_performance_view "https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/detector/views.py"
click node_signup_routes "https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/accounts/urls.py"
click node_signup_view "https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/accounts/views.py"
click node_signup_form "https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/accounts/forms.py"
click node_inference "https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/detector/inference.py"
click node_explanation "https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/detector/explain.py"
click node_disease_guidance "https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/detector/disease_info.py"
click node_prediction_records "https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/detector/models.py"
click node_uploaded_images "https://github.com/sthasus/tomato_leaf_disease_detection/tree/main/media/uploads"
click node_training "https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/ml_model/train.ipynb"
click node_model_weights "https://github.com/sthasus/tomato_leaf_disease_detection/tree/main/ml_model/saved_model"
click node_class_labels "https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/ml_model/class_names.json"
click node_model_metrics "https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/ml_model/metrics.json"

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_detector_routes,node_landing,node_upload_view,node_image_form,node_history_view,node_performance_view,node_prediction_records,node_uploaded_images toneBlue
class node_signup_routes,node_signup_view,node_signup_form toneAmber
class node_inference,node_explanation,node_disease_guidance toneMint
class node_training,node_model_weights,node_class_labels,node_model_metrics toneRose
class node_visitor toneIndigo
```

## Components

### Web application

- [Detector routes](https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/detector/urls.py): `detector/urls.py`
- [Landing page](https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/detector/views.py): `detector/views.py`
- [Upload handler](https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/detector/views.py): `detector/views.py`
- [Image validation](https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/detector/forms.py): `detector/forms.py`
- [Prediction history](https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/detector/views.py): `detector/views.py`
- [Metrics page](https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/detector/views.py): `detector/views.py`
- [Prediction records](https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/detector/models.py): `detector/models.py`
- [Uploaded images](https://github.com/sthasus/tomato_leaf_disease_detection/tree/main/media/uploads): `media/uploads`

### Accounts

- [Account routes](https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/accounts/urls.py): `accounts/urls.py`
- [Signup handler](https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/accounts/views.py): `accounts/views.py`
- [Signup validation](https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/accounts/forms.py): `accounts/forms.py`

### Diagnosis

- [Image inference](https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/detector/inference.py): `detector/inference.py`
- [LIME explanation](https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/detector/explain.py): `detector/explain.py`
- [Disease guidance](https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/detector/disease_info.py): `detector/disease_info.py`

### Model lifecycle

- [Model training](https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/ml_model/train.ipynb): `ml_model/train.ipynb`
- [Model weights](https://github.com/sthasus/tomato_leaf_disease_detection/tree/main/ml_model/saved_model): `ml_model/saved_model`
- [Class labels](https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/ml_model/class_names.json): `ml_model/class_names.json`
- [Model metrics](https://github.com/sthasus/tomato_leaf_disease_detection/blob/main/ml_model/metrics.json): `ml_model/metrics.json`

### Other components

- **Visitor**

## Connections

- Visitor → Detector routes: requests pages (evidence: `detector/urls.py`)
- Detector routes → Landing page: routes to (evidence: `detector/urls.py`)
- Detector routes → Upload handler: routes to (evidence: `detector/urls.py`)
- Detector routes → Prediction history: routes to (evidence: `detector/urls.py`)
- Detector routes → Metrics page: routes to (evidence: `detector/urls.py`)
- Visitor → Account routes: requests account (evidence: `accounts/urls.py`)
- Account routes → Signup handler: routes to (evidence: `accounts/urls.py`)
- Signup handler → Signup validation: uses form (evidence: `accounts/views.py`)
- Upload handler → Image validation: validates upload (evidence: `detector/views.py`)
- Upload handler → Uploaded images: saves image (evidence: `detector/views.py`)
- Upload handler → Image inference: predicts image (evidence: `detector/views.py`)
- Image inference → Model weights: loads weights (evidence: `README.md`)
- Image inference → Class labels: loads labels (evidence: `README.md`)
- Upload handler → Disease guidance: gets care tips (evidence: `detector/views.py`)
- Upload handler → Prediction records: saves result (evidence: `detector/views.py`)
- Upload handler → LIME explanation: optionally explains (evidence: `detector/views.py`)
- LIME explanation → Image inference: reuses model (evidence: `detector/inference.py`)
- Prediction history → Prediction records: reads history (evidence: `detector/views.py`)
- Prediction history → Disease guidance: gets care tips (evidence: `detector/views.py`)
- Metrics page → Model metrics: reads metrics (evidence: `README.md`)
- Metrics page → Disease guidance: formats labels (evidence: `detector/views.py`)
- Model training → Model weights: exports weights (evidence: `README.md`)
- Model training → Class labels: exports labels (evidence: `README.md`)
- Model training → Model metrics: exports metrics (evidence: `README.md`)
