# nishigandhachoudhury/tomato-quality-detection architecture

> Architecture diagram of the GitHub repository nishigandhachoudhury/tomato-quality-detection, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nishigandhachoudhury/tomato-quality-detection
- Repository: https://github.com/nishigandhachoudhury/tomato-quality-detection

## Overview

Red or Ripe is a tomato-quality grading application with a four-class image classifier and damage scoring. Users submit a photo through either the Gradio interface or the alternate Flask app; the Gradio workflow validates the image, preprocesses it, predicts a class, and returns confidence and damage details. A separate training workflow builds and evaluates a MobileNetV2 model. The graph includes documented capabilities and sampled relationships; the excerpts do not establish the Gradio model artifact path or the Flask app’s artifact wiring.

Main entry points: [`train_complete.py`](https://github.com/nishigandhachoudhury/tomato-quality-detection/blob/main/train_complete.py) (Model training), [`app.py`](https://github.com/nishigandhachoudhury/tomato-quality-detection/blob/main/app.py) (Gradio interface), [`app_simple.py`](https://github.com/nishigandhachoudhury/tomato-quality-detection/blob/main/app_simple.py) (Flask interface), [`models/class_names.json`](https://github.com/nishigandhachoudhury/tomato-quality-detection/blob/main/models/class_names.json) (Class names)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User interfaces"]
  node_gradio["Gradio interface<br/>[app.py]"]
  node_flask["Flask interface<br/>[app_simple.py]"]
end

subgraph group_inference["Image grading"]
  node_validation["Tomato validation<br/>[app.py]"]
  node_preprocess["Image preprocessing<br/>[app.py]"]
  node_classifier["CNN inference<br/>[app.py]"]
  node_damage["Damage scoring<br/>[app.py]"]
  node_results["Grading results<br/>[app.py]"]
end

subgraph group_training["Model training"]
  node_training["Model training<br/>[train_complete.py]"]
  node_config["Training configuration<br/>[config.py]"]
end

subgraph group_artifacts["Model artifacts"]
  node_model["Trained model<br/>[tomato_model.keras]"]
  node_classes["Class names<br/>[class_names.json]"]
end

node_user(("Image uploader"))
node_dataset["Training images"]

node_user -->|"uploads image"| node_gradio
node_gradio -->|"calls prediction"| node_validation
node_validation -->|"preprocesses image"| node_preprocess
node_preprocess -->|"supplies image"| node_classifier
node_classifier -->|"scores probabilities"| node_damage
node_classifier -->|"returns class"| node_results
node_damage -->|"returns score"| node_results
node_user -->|"uploads image"| node_flask
node_flask -.->|"uses classifier design"| node_training
node_dataset -->|"trains on images"| node_training
node_training -->|"reads settings"| node_config
node_training -->|"saves model"| node_model
node_training -->|"saves labels"| node_classes
node_gradio -->|"loads labels"| node_classes

click node_gradio "https://github.com/nishigandhachoudhury/tomato-quality-detection/blob/main/app.py"
click node_flask "https://github.com/nishigandhachoudhury/tomato-quality-detection/blob/main/app_simple.py"
click node_validation "https://github.com/nishigandhachoudhury/tomato-quality-detection/blob/main/app.py"
click node_preprocess "https://github.com/nishigandhachoudhury/tomato-quality-detection/blob/main/app.py"
click node_classifier "https://github.com/nishigandhachoudhury/tomato-quality-detection/blob/main/app.py"
click node_damage "https://github.com/nishigandhachoudhury/tomato-quality-detection/blob/main/app.py"
click node_results "https://github.com/nishigandhachoudhury/tomato-quality-detection/blob/main/app.py"
click node_training "https://github.com/nishigandhachoudhury/tomato-quality-detection/blob/main/train_complete.py"
click node_config "https://github.com/nishigandhachoudhury/tomato-quality-detection/blob/main/config.py"
click node_model "https://github.com/nishigandhachoudhury/tomato-quality-detection/blob/main/models/tomato_model.keras"
click node_classes "https://github.com/nishigandhachoudhury/tomato-quality-detection/blob/main/models/class_names.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_gradio,node_flask toneBlue
class node_validation,node_preprocess,node_classifier,node_damage,node_results toneAmber
class node_training,node_config toneMint
class node_model,node_classes toneRose
class node_user,node_dataset toneIndigo
```

## Components

### User interfaces

- [Gradio interface](https://github.com/nishigandhachoudhury/tomato-quality-detection/blob/main/app.py): `app.py`
- [Flask interface](https://github.com/nishigandhachoudhury/tomato-quality-detection/blob/main/app_simple.py): `app_simple.py`

### Image grading

- [Tomato validation](https://github.com/nishigandhachoudhury/tomato-quality-detection/blob/main/app.py): `app.py`
- [Image preprocessing](https://github.com/nishigandhachoudhury/tomato-quality-detection/blob/main/app.py): `app.py`
- [CNN inference](https://github.com/nishigandhachoudhury/tomato-quality-detection/blob/main/app.py): `app.py`
- [Damage scoring](https://github.com/nishigandhachoudhury/tomato-quality-detection/blob/main/app.py): `app.py`
- [Grading results](https://github.com/nishigandhachoudhury/tomato-quality-detection/blob/main/app.py): `app.py`

### Model training

- [Model training](https://github.com/nishigandhachoudhury/tomato-quality-detection/blob/main/train_complete.py): `train_complete.py`
- [Training configuration](https://github.com/nishigandhachoudhury/tomato-quality-detection/blob/main/config.py): `config.py`

### Model artifacts

- [Trained model](https://github.com/nishigandhachoudhury/tomato-quality-detection/blob/main/models/tomato_model.keras): `models/tomato_model.keras`
- [Class names](https://github.com/nishigandhachoudhury/tomato-quality-detection/blob/main/models/class_names.json): `models/class_names.json`

### Other components

- **Image uploader**
- **Training images**

## Connections

- Image uploader → Gradio interface: uploads image (evidence: `app.py`)
- Gradio interface → Tomato validation: calls prediction (evidence: `app.py`)
- Tomato validation → Image preprocessing: preprocesses image (evidence: `app.py`)
- Image preprocessing → CNN inference: supplies image (evidence: `app.py`)
- CNN inference → Damage scoring: scores probabilities (evidence: `app.py`)
- CNN inference → Grading results: returns class (evidence: `app.py`)
- Damage scoring → Grading results: returns score (evidence: `app.py`)
- Image uploader → Flask interface: uploads image (evidence: `app_simple.py`)
- Flask interface → Model training: uses classifier design
- Training images → Model training: trains on images (evidence: `train_complete.py`)
- Model training → Training configuration: reads settings (evidence: `train_complete.py`)
- Model training → Trained model: saves model (evidence: `train_complete.py`)
- Model training → Class names: saves labels (evidence: `train_complete.py`)
- Gradio interface → Class names: loads labels (evidence: `app.py`)
