# vingupta09/tomatoguard architecture

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

- Interactive diagram: https://gitdiagram.com/vingupta09/tomatoguard
- Repository: https://github.com/vingupta09/tomatoguard

## Overview

This is a tomato-leaf diagnosis and automated spraying system: camera or user images are classified by the backend, saved as diagnosis history, and can trigger pump commands; a web app provides diagnosis, monitoring, history, and pump controls. The excerpts show the frontend upload/API flow and backend inference and device endpoints. Firmware behavior and several frontend page internals were not sampled, so those links are limited to documented or indexed relationships.

Main entry points: [`backend/app.py`](https://github.com/vingupta09/tomatoguard/blob/main/backend/app.py) (HTTP API), [`frontend/src/App.jsx`](https://github.com/vingupta09/tomatoguard/blob/main/frontend/src/App.jsx) (Web routes), [`frontend/src/pages/Home.jsx`](https://github.com/vingupta09/tomatoguard/blob/main/frontend/src/pages/Home.jsx) (Image classifier), [`frontend/src/api/client.js`](https://github.com/vingupta09/tomatoguard/blob/main/frontend/src/api/client.js) (API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_app["Web routes<br/>[App.jsx]"]
  node_home["Image classifier<br/>[Home.jsx]"]
  node_dashboard["Dashboard<br/>[Dashboard.jsx]"]
  node_history["Diagnosis history<br/>[History.jsx]"]
  node_pumpui["Pump controls<br/>[PumpTest.jsx]"]
  node_api["API client<br/>[client.js]"]
  node_auth["Authentication state<br/>[AuthContext.jsx]"]
  node_demo["Demo data<br/>[demo.js]"]
  node_diagnosisui["Diagnosis display<br/>[DiagnosisPanel.jsx]"]
end

subgraph group_backend["Diagnosis backend"]
  node_backendapp["HTTP API<br/>[app.py]"]
  node_inference["Image inference<br/>[inference.py]"]
end

subgraph group_devices["Field devices"]
  node_camera["ESP32 camera"]
  node_pumpboard["ESP32 pump board"]
end

subgraph group_state["Persistence and reference"]
  node_disease["Disease guidance<br/>[disease_info.py]"]
  node_store[("Device and history store<br/>[store.py]")]
end

node_grower(("Grower"))

node_grower -->|"uploads image"| node_home
node_home -->|"posts image"| node_api
node_api -->|"sends API requests"| node_backendapp
node_backendapp -->|"classifies image"| node_inference
node_backendapp -->|"uses guidance"| node_disease
node_backendapp -->|"reads and writes"| node_store
node_backendapp -->|"accepts capture uploads"| node_camera
node_pumpboard -->|"polls commands"| node_backendapp
node_backendapp -->|"returns pump commands"| node_pumpboard
node_app -->|"routes to"| node_home
node_app -->|"routes to"| node_dashboard
node_app -->|"routes to"| node_history
node_app -->|"routes to"| node_pumpui
node_app -->|"protected by"| node_auth
node_home -->|"renders result"| node_diagnosisui
node_home -->|"uses fallback"| node_demo
node_dashboard -->|"requests status"| node_api
node_dashboard -->|"renders diagnosis"| node_diagnosisui
node_history -->|"loads and clears"| node_api
node_history -.->|"displays saved records"| node_store
node_history -->|"uses fallback"| node_demo
node_pumpui -->|"requests pump action"| node_api

click node_camera "https://github.com/vingupta09/tomatoguard/blob/main/firmware/esp32cam_capture/esp32cam_capture.ino"
click node_pumpboard "https://github.com/vingupta09/tomatoguard/blob/main/firmware/esp32_pump_controller/esp32_pump_controller.ino"
click node_app "https://github.com/vingupta09/tomatoguard/blob/main/frontend/src/App.jsx"
click node_home "https://github.com/vingupta09/tomatoguard/blob/main/frontend/src/pages/Home.jsx"
click node_dashboard "https://github.com/vingupta09/tomatoguard/blob/main/frontend/src/pages/Dashboard.jsx"
click node_history "https://github.com/vingupta09/tomatoguard/blob/main/frontend/src/pages/History.jsx"
click node_pumpui "https://github.com/vingupta09/tomatoguard/blob/main/frontend/src/pages/PumpTest.jsx"
click node_api "https://github.com/vingupta09/tomatoguard/blob/main/frontend/src/api/client.js"
click node_auth "https://github.com/vingupta09/tomatoguard/blob/main/frontend/src/context/AuthContext.jsx"
click node_demo "https://github.com/vingupta09/tomatoguard/blob/main/frontend/src/data/demo.js"
click node_diagnosisui "https://github.com/vingupta09/tomatoguard/blob/main/frontend/src/components/DiagnosisPanel.jsx"
click node_backendapp "https://github.com/vingupta09/tomatoguard/blob/main/backend/app.py"
click node_inference "https://github.com/vingupta09/tomatoguard/blob/main/backend/inference.py"
click node_disease "https://github.com/vingupta09/tomatoguard/blob/main/backend/disease_info.py"
click node_store "https://github.com/vingupta09/tomatoguard/blob/main/backend/store.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_app,node_home,node_dashboard,node_history,node_pumpui,node_api,node_auth,node_demo,node_diagnosisui toneBlue
class node_backendapp,node_inference toneAmber
class node_camera,node_pumpboard toneMint
class node_disease,node_store toneRose
class node_grower toneIndigo
```

## Components

### Web application

- [Web routes](https://github.com/vingupta09/tomatoguard/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Image classifier](https://github.com/vingupta09/tomatoguard/blob/main/frontend/src/pages/Home.jsx): `frontend/src/pages/Home.jsx`
- [Dashboard](https://github.com/vingupta09/tomatoguard/blob/main/frontend/src/pages/Dashboard.jsx): `frontend/src/pages/Dashboard.jsx`
- [Diagnosis history](https://github.com/vingupta09/tomatoguard/blob/main/frontend/src/pages/History.jsx): `frontend/src/pages/History.jsx`
- [Pump controls](https://github.com/vingupta09/tomatoguard/blob/main/frontend/src/pages/PumpTest.jsx): `frontend/src/pages/PumpTest.jsx`
- [API client](https://github.com/vingupta09/tomatoguard/blob/main/frontend/src/api/client.js): `frontend/src/api/client.js`
- [Authentication state](https://github.com/vingupta09/tomatoguard/blob/main/frontend/src/context/AuthContext.jsx): `frontend/src/context/AuthContext.jsx`
- [Demo data](https://github.com/vingupta09/tomatoguard/blob/main/frontend/src/data/demo.js): `frontend/src/data/demo.js`
- [Diagnosis display](https://github.com/vingupta09/tomatoguard/blob/main/frontend/src/components/DiagnosisPanel.jsx): `frontend/src/components/DiagnosisPanel.jsx`

### Diagnosis backend

- [HTTP API](https://github.com/vingupta09/tomatoguard/blob/main/backend/app.py): `backend/app.py`
- [Image inference](https://github.com/vingupta09/tomatoguard/blob/main/backend/inference.py): `backend/inference.py`

### Field devices

- [ESP32 camera](https://github.com/vingupta09/tomatoguard/blob/main/firmware/esp32cam_capture/esp32cam_capture.ino): `firmware/esp32cam_capture/esp32cam_capture.ino`
- [ESP32 pump board](https://github.com/vingupta09/tomatoguard/blob/main/firmware/esp32_pump_controller/esp32_pump_controller.ino): `firmware/esp32_pump_controller/esp32_pump_controller.ino`

### Persistence and reference

- [Disease guidance](https://github.com/vingupta09/tomatoguard/blob/main/backend/disease_info.py): `backend/disease_info.py`
- [Device and history store](https://github.com/vingupta09/tomatoguard/blob/main/backend/store.py): `backend/store.py`

### Other components

- **Grower**

## Connections

- Grower → Image classifier: uploads image (evidence: `frontend/src/pages/Home.jsx`)
- Image classifier → API client: posts image (evidence: `frontend/src/pages/Home.jsx`)
- API client → HTTP API: sends API requests (evidence: `frontend/src/api/client.js`)
- HTTP API → Image inference: classifies image (evidence: `backend/app.py`)
- HTTP API → Disease guidance: uses guidance (evidence: `backend/app.py`)
- HTTP API → Device and history store: reads and writes (evidence: `backend/app.py`)
- HTTP API → ESP32 camera: accepts capture uploads (evidence: `backend/app.py`)
- ESP32 pump board → HTTP API: polls commands (evidence: `backend/app.py`)
- HTTP API → ESP32 pump board: returns pump commands (evidence: `backend/app.py`)
- Web routes → Image classifier: routes to (evidence: `frontend/src/App.jsx`)
- Web routes → Dashboard: routes to (evidence: `frontend/src/App.jsx`)
- Web routes → Diagnosis history: routes to (evidence: `frontend/src/App.jsx`)
- Web routes → Pump controls: routes to (evidence: `frontend/src/App.jsx`)
- Web routes → Authentication state: protected by (evidence: `frontend/src/App.jsx`)
- Image classifier → Diagnosis display: renders result (evidence: `frontend/src/pages/Home.jsx`)
- Image classifier → Demo data: uses fallback (evidence: `frontend/src/pages/Home.jsx`)
- Dashboard → API client: requests status (evidence: `frontend/src/pages/Dashboard.jsx`)
- Dashboard → Diagnosis display: renders diagnosis (evidence: `frontend/src/pages/Dashboard.jsx`)
- Diagnosis history → API client: loads and clears (evidence: `frontend/src/pages/History.jsx`)
- Diagnosis history → Device and history store: displays saved records
- Diagnosis history → Demo data: uses fallback (evidence: `frontend/src/pages/History.jsx`)
- Pump controls → API client: requests pump action (evidence: `frontend/src/pages/PumpTest.jsx`)
