# pellururambabu/ai-crop-detection-system architecture

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

- Interactive diagram: https://gitdiagram.com/pellururambabu/ai-crop-detection-system
- Repository: https://github.com/pellururambabu/ai-crop-detection-system

## Overview

This is a Streamlit crop-disease diagnostic dashboard. Users provide a leaf image from an upload or camera source; the app loads the serialized MobileNetV2 model, produces a diagnosis, and presents severity and treatment guidance. It also exposes ESP32 sensor telemetry and keeps scan records in session state for CSV export. The README describes additional supported acquisition modes and diagnostic outputs; the sampled source is partial, so those implementation details are not independently verified here.

Main entry points: [`app.py`](https://github.com/pellururambabu/ai-crop-detection-system/blob/main/app.py) (Diagnosis Result), [`crop_disease_model.pkl`](https://github.com/pellururambabu/ai-crop-detection-system/blob/main/crop_disease_model.pkl) (Model Artifact)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_capture["Image Acquisition"]
  node_upload["Image Upload<br/>[app.py]"]
  node_usb["USB Camera<br/>[app.py]"]
  node_esp_camera["ESP32 Camera<br/>[app.py]"]
  node_active_image["Active Image<br/>[app.py]"]
end

subgraph group_diagnosis["Diagnosis"]
  node_preprocess["Image Preprocessing<br/>[app.py]"]
  node_model_loader["Model Loader<br/>[app.py]"]
  node_model_file["Model Artifact"]
  node_classifier["Disease Classifier<br/>[app.py]"]
  node_diagnosis_result["Diagnosis Result<br/>[app.py]"]
  node_treatment["Treatment Guidance<br/>[app.py]"]
end

subgraph group_field["Field Monitoring"]
  node_sensor_poll["Sensor Polling<br/>[app.py]"]
  node_telemetry["Telemetry Display<br/>[app.py]"]
end

subgraph group_records["Results and Records"]
  node_dashboard["Diagnostic Dashboard<br/>[app.py]"]
  node_session_log[("Session Scan Log<br/>[app.py]")]
  node_csv_export["CSV Export<br/>[app.py]"]
end

node_user(("Field User"))
node_esp_device["ESP32 Device"]

node_user -->|"uploads image"| node_upload
node_user -->|"captures image"| node_usb
node_user -->|"requests capture"| node_esp_camera
node_upload -->|"sets image"| node_active_image
node_usb -->|"sets image"| node_active_image
node_esp_camera -->|"captures frame"| node_active_image
node_active_image -->|"normalizes image"| node_preprocess
node_preprocess -->|"provides tensor"| node_classifier
node_model_loader -->|"loads weights"| node_model_file
node_model_loader -->|"constructs model"| node_classifier
node_classifier -->|"returns prediction"| node_diagnosis_result
node_diagnosis_result -->|"drives guidance"| node_treatment
node_diagnosis_result -->|"renders diagnosis"| node_dashboard
node_treatment -->|"renders guidance"| node_dashboard
node_user -->|"configures device"| node_sensor_poll
node_sensor_poll -->|"requests telemetry"| node_esp_device
node_sensor_poll -->|"provides readings"| node_telemetry
node_telemetry -->|"renders status"| node_dashboard
node_diagnosis_result -->|"appends scan"| node_session_log
node_session_log -->|"exports records"| node_csv_export
node_csv_export -->|"downloads CSV"| node_user

click node_upload "https://github.com/pellururambabu/ai-crop-detection-system/blob/main/app.py"
click node_usb "https://github.com/pellururambabu/ai-crop-detection-system/blob/main/app.py"
click node_esp_camera "https://github.com/pellururambabu/ai-crop-detection-system/blob/main/app.py"
click node_active_image "https://github.com/pellururambabu/ai-crop-detection-system/blob/main/app.py"
click node_preprocess "https://github.com/pellururambabu/ai-crop-detection-system/blob/main/app.py"
click node_model_loader "https://github.com/pellururambabu/ai-crop-detection-system/blob/main/app.py"
click node_model_file "https://github.com/pellururambabu/ai-crop-detection-system/blob/main/crop_disease_model.pkl"
click node_classifier "https://github.com/pellururambabu/ai-crop-detection-system/blob/main/app.py"
click node_diagnosis_result "https://github.com/pellururambabu/ai-crop-detection-system/blob/main/app.py"
click node_treatment "https://github.com/pellururambabu/ai-crop-detection-system/blob/main/app.py"
click node_dashboard "https://github.com/pellururambabu/ai-crop-detection-system/blob/main/app.py"
click node_sensor_poll "https://github.com/pellururambabu/ai-crop-detection-system/blob/main/app.py"
click node_telemetry "https://github.com/pellururambabu/ai-crop-detection-system/blob/main/app.py"
click node_session_log "https://github.com/pellururambabu/ai-crop-detection-system/blob/main/app.py"
click node_csv_export "https://github.com/pellururambabu/ai-crop-detection-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_upload,node_usb,node_esp_camera,node_active_image,node_user toneBlue
class node_preprocess,node_model_loader,node_model_file,node_classifier,node_diagnosis_result,node_treatment toneAmber
class node_sensor_poll,node_telemetry toneMint
class node_dashboard,node_session_log,node_csv_export toneRose
class node_esp_device toneIndigo
```

## Components

### Image Acquisition

- [Image Upload](https://github.com/pellururambabu/ai-crop-detection-system/blob/main/app.py): `app.py`
- [USB Camera](https://github.com/pellururambabu/ai-crop-detection-system/blob/main/app.py): `app.py`
- [ESP32 Camera](https://github.com/pellururambabu/ai-crop-detection-system/blob/main/app.py): `app.py`
- [Active Image](https://github.com/pellururambabu/ai-crop-detection-system/blob/main/app.py): `app.py`

### Diagnosis

- [Image Preprocessing](https://github.com/pellururambabu/ai-crop-detection-system/blob/main/app.py): `app.py`
- [Model Loader](https://github.com/pellururambabu/ai-crop-detection-system/blob/main/app.py): `app.py`
- [Model Artifact](https://github.com/pellururambabu/ai-crop-detection-system/blob/main/crop_disease_model.pkl): `crop_disease_model.pkl`
- [Disease Classifier](https://github.com/pellururambabu/ai-crop-detection-system/blob/main/app.py): `app.py`
- [Diagnosis Result](https://github.com/pellururambabu/ai-crop-detection-system/blob/main/app.py): `app.py`
- [Treatment Guidance](https://github.com/pellururambabu/ai-crop-detection-system/blob/main/app.py): `app.py`

### Field Monitoring

- [Sensor Polling](https://github.com/pellururambabu/ai-crop-detection-system/blob/main/app.py): `app.py`
- [Telemetry Display](https://github.com/pellururambabu/ai-crop-detection-system/blob/main/app.py): `app.py`

### Results and Records

- [Diagnostic Dashboard](https://github.com/pellururambabu/ai-crop-detection-system/blob/main/app.py): `app.py`
- [Session Scan Log](https://github.com/pellururambabu/ai-crop-detection-system/blob/main/app.py): `app.py`
- [CSV Export](https://github.com/pellururambabu/ai-crop-detection-system/blob/main/app.py): `app.py`

### Other components

- **Field User**
- **ESP32 Device**

## Connections

- Field User → Image Upload: uploads image (evidence: `README.md`)
- Field User → USB Camera: captures image (evidence: `README.md`)
- Field User → ESP32 Camera: requests capture (evidence: `README.md`)
- Image Upload → Active Image: sets image (evidence: `README.md`)
- USB Camera → Active Image: sets image (evidence: `README.md`)
- ESP32 Camera → Active Image: captures frame (evidence: `app.py`)
- Active Image → Image Preprocessing: normalizes image (evidence: `README.md`)
- Image Preprocessing → Disease Classifier: provides tensor (evidence: `README.md`)
- Model Loader → Model Artifact: loads weights (evidence: `app.py`)
- Model Loader → Disease Classifier: constructs model (evidence: `app.py`)
- Disease Classifier → Diagnosis Result: returns prediction (evidence: `README.md`)
- Diagnosis Result → Treatment Guidance: drives guidance (evidence: `README.md`)
- Diagnosis Result → Diagnostic Dashboard: renders diagnosis (evidence: `app.py`)
- Treatment Guidance → Diagnostic Dashboard: renders guidance (evidence: `app.py`)
- Field User → Sensor Polling: configures device (evidence: `app.py`)
- Sensor Polling → ESP32 Device: requests telemetry (evidence: `app.py`)
- Sensor Polling → Telemetry Display: provides readings (evidence: `app.py`)
- Telemetry Display → Diagnostic Dashboard: renders status (evidence: `app.py`)
- Diagnosis Result → Session Scan Log: appends scan (evidence: `app.py`)
- Session Scan Log → CSV Export: exports records (evidence: `README.md`)
- CSV Export → Field User: downloads CSV (evidence: `README.md`)
