# anushkagupta12/smart-agriculture-system architecture

> Architecture diagram of the GitHub repository anushkagupta12/smart-agriculture-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/anushkagupta12/smart-agriculture-system
- Repository: https://github.com/anushkagupta12/smart-agriculture-system

## Overview

CP-SAS is a Flask-backed smart-agriculture dashboard for plant-disease detection, sensor monitoring and irrigation control. The main user workflow is submitting a leaf image through the dashboard, receiving a model prediction enriched with disease remedies and sensor context, and viewing the result. In parallel, ESP32 readings feed sensor history and automatic irrigation logic; dashboard controls can also change irrigation mode or state. The backend is largely concentrated in app.py. Some routes and dashboard sections are documented but not shown in the excerpts, so those links rely on README evidence.

Main entry points: [`app.py`](https://github.com/anushkagupta12/smart-agriculture-system/blob/main/app.py) (REST endpoints), [`static/js/dashboard.js`](https://github.com/anushkagupta12/smart-agriculture-system/blob/main/static/js/dashboard.js) (Dashboard interactions), [`data`](https://github.com/anushkagupta12/smart-agriculture-system/tree/main/data) (SQLite data store), [`templates/index.html`](https://github.com/anushkagupta12/smart-agriculture-system/blob/main/templates/index.html) (Web dashboard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Dashboard"]
  node_dashboard["Web dashboard<br/>[index.html]"]
  node_dashboard_js["Dashboard interactions<br/>[dashboard.js]"]
end

subgraph group_api["Flask API"]
  node_api_routes["REST endpoints<br/>[app.py]"]
  node_status["System status<br/>[app.py]"]
end

subgraph group_plant["Plant diagnosis"]
  node_image_upload["Leaf image upload<br/>[app.py]"]
  node_classifier["Disease classifier<br/>[app.py]"]
  node_remedy_lookup["Remedy lookup<br/>[app.py]"]
  node_remedy_data["Disease knowledge base<br/>[remedies.json]"]
  node_ai_recommendation["AI recommendation<br/>[app.py]"]
  node_model_files["Model class metadata<br/>[class_names.json]"]
end

subgraph group_sensing["Sensors and irrigation"]
  node_sensor_ingest["Sensor ingestion<br/>[app.py]"]
  node_sensor_history["Sensor history and stats<br/>[app.py]"]
  node_irrigation_logic["Irrigation control<br/>[app.py]"]
  node_irrigation_events["Irrigation event log<br/>[app.py]"]
end

subgraph group_state["Agricultural data"]
  node_database[("SQLite data store")]
end

node_farmer(("Farm operator"))
node_esp32(("ESP32 device"))
node_ai_service["Gemini service"]

node_farmer -->|"uses"| node_dashboard
node_dashboard -->|"loads"| node_dashboard_js
node_dashboard_js -->|"requests API"| node_api_routes
node_farmer -->|"submits image"| node_dashboard_js
node_api_routes -->|"routes prediction"| node_image_upload
node_image_upload -->|"invokes inference"| node_classifier
node_classifier -->|"loads classes"| node_model_files
node_image_upload -->|"looks up result"| node_remedy_lookup
node_remedy_lookup -->|"reads remedies"| node_remedy_data
node_image_upload -->|"requests advice"| node_ai_recommendation
node_ai_recommendation -.->|"requests recommendation"| node_ai_service
node_esp32 -->|"sends readings"| node_sensor_ingest
node_api_routes -->|"routes readings"| node_sensor_ingest
node_sensor_ingest -->|"writes readings"| node_database
node_sensor_history -->|"queries readings"| node_database
node_api_routes -->|"serves history"| node_sensor_history
node_sensor_ingest -->|"applies auto rules"| node_irrigation_logic
node_irrigation_logic -->|"records changes"| node_irrigation_events
node_irrigation_events -->|"writes events"| node_database
node_irrigation_logic -->|"stores state"| node_database
node_api_routes -->|"routes commands"| node_irrigation_logic
node_api_routes -->|"serves health"| node_status
node_status -->|"reports database"| node_database
node_dashboard_js -->|"loads charts"| node_sensor_history
node_dashboard_js -->|"sends controls"| node_irrigation_logic
node_dashboard_js -->|"checks health"| node_status

click node_dashboard "https://github.com/anushkagupta12/smart-agriculture-system/blob/main/templates/index.html"
click node_dashboard_js "https://github.com/anushkagupta12/smart-agriculture-system/blob/main/static/js/dashboard.js"
click node_api_routes "https://github.com/anushkagupta12/smart-agriculture-system/blob/main/app.py"
click node_image_upload "https://github.com/anushkagupta12/smart-agriculture-system/blob/main/app.py"
click node_classifier "https://github.com/anushkagupta12/smart-agriculture-system/blob/main/app.py"
click node_remedy_lookup "https://github.com/anushkagupta12/smart-agriculture-system/blob/main/app.py"
click node_remedy_data "https://github.com/anushkagupta12/smart-agriculture-system/blob/main/data/remedies.json"
click node_ai_recommendation "https://github.com/anushkagupta12/smart-agriculture-system/blob/main/app.py"
click node_sensor_ingest "https://github.com/anushkagupta12/smart-agriculture-system/blob/main/app.py"
click node_sensor_history "https://github.com/anushkagupta12/smart-agriculture-system/blob/main/app.py"
click node_irrigation_logic "https://github.com/anushkagupta12/smart-agriculture-system/blob/main/app.py"
click node_irrigation_events "https://github.com/anushkagupta12/smart-agriculture-system/blob/main/app.py"
click node_status "https://github.com/anushkagupta12/smart-agriculture-system/blob/main/app.py"
click node_database "https://github.com/anushkagupta12/smart-agriculture-system/tree/main/data"
click node_model_files "https://github.com/anushkagupta12/smart-agriculture-system/blob/main/model/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_dashboard,node_dashboard_js toneBlue
class node_api_routes,node_status toneAmber
class node_image_upload,node_classifier,node_remedy_lookup,node_remedy_data,node_ai_recommendation,node_model_files toneMint
class node_sensor_ingest,node_sensor_history,node_irrigation_logic,node_irrigation_events toneRose
class node_database,node_farmer,node_esp32,node_ai_service toneIndigo
```

## Components

### Dashboard

- [Web dashboard](https://github.com/anushkagupta12/smart-agriculture-system/blob/main/templates/index.html): `templates/index.html`
- [Dashboard interactions](https://github.com/anushkagupta12/smart-agriculture-system/blob/main/static/js/dashboard.js): `static/js/dashboard.js`

### Flask API

- [REST endpoints](https://github.com/anushkagupta12/smart-agriculture-system/blob/main/app.py): `app.py`
- [System status](https://github.com/anushkagupta12/smart-agriculture-system/blob/main/app.py): `app.py`

### Plant diagnosis

- [Leaf image upload](https://github.com/anushkagupta12/smart-agriculture-system/blob/main/app.py): `app.py`
- [Disease classifier](https://github.com/anushkagupta12/smart-agriculture-system/blob/main/app.py): `app.py`
- [Remedy lookup](https://github.com/anushkagupta12/smart-agriculture-system/blob/main/app.py): `app.py`
- [Disease knowledge base](https://github.com/anushkagupta12/smart-agriculture-system/blob/main/data/remedies.json): `data/remedies.json`
- [AI recommendation](https://github.com/anushkagupta12/smart-agriculture-system/blob/main/app.py): `app.py`
- [Model class metadata](https://github.com/anushkagupta12/smart-agriculture-system/blob/main/model/class_names.json): `model/class_names.json`

### Sensors and irrigation

- [Sensor ingestion](https://github.com/anushkagupta12/smart-agriculture-system/blob/main/app.py): `app.py`
- [Sensor history and stats](https://github.com/anushkagupta12/smart-agriculture-system/blob/main/app.py): `app.py`
- [Irrigation control](https://github.com/anushkagupta12/smart-agriculture-system/blob/main/app.py): `app.py`
- [Irrigation event log](https://github.com/anushkagupta12/smart-agriculture-system/blob/main/app.py): `app.py`

### Agricultural data

- [SQLite data store](https://github.com/anushkagupta12/smart-agriculture-system/tree/main/data): `data`

### Other components

- **Farm operator**
- **ESP32 device**
- **Gemini service**

## Connections

- Farm operator → Web dashboard: uses (evidence: `README.md`)
- Web dashboard → Dashboard interactions: loads (evidence: `README.md`)
- Dashboard interactions → REST endpoints: requests API (evidence: `static/js/dashboard.js`)
- Farm operator → Dashboard interactions: submits image (evidence: `README.md`)
- REST endpoints → Leaf image upload: routes prediction (evidence: `README.md`)
- Leaf image upload → Disease classifier: invokes inference (evidence: `app.py`)
- Disease classifier → Model class metadata: loads classes (evidence: `app.py`)
- Leaf image upload → Remedy lookup: looks up result (evidence: `app.py`)
- Remedy lookup → Disease knowledge base: reads remedies (evidence: `app.py`)
- Leaf image upload → AI recommendation: requests advice (evidence: `app.py`)
- AI recommendation → Gemini service: requests recommendation
- ESP32 device → Sensor ingestion: sends readings (evidence: `README.md`)
- REST endpoints → Sensor ingestion: routes readings (evidence: `README.md`)
- Sensor ingestion → SQLite data store: writes readings (evidence: `app.py`)
- Sensor history and stats → SQLite data store: queries readings (evidence: `app.py`)
- REST endpoints → Sensor history and stats: serves history (evidence: `README.md`)
- Sensor ingestion → Irrigation control: applies auto rules (evidence: `app.py`)
- Irrigation control → Irrigation event log: records changes (evidence: `app.py`)
- Irrigation event log → SQLite data store: writes events (evidence: `app.py`)
- Irrigation control → SQLite data store: stores state (evidence: `app.py`)
- REST endpoints → Irrigation control: routes commands (evidence: `README.md`)
- REST endpoints → System status: serves health (evidence: `README.md`)
- System status → SQLite data store: reports database (evidence: `app.py`)
- Dashboard interactions → Sensor history and stats: loads charts (evidence: `static/js/dashboard.js`)
- Dashboard interactions → Irrigation control: sends controls (evidence: `static/js/dashboard.js`)
- Dashboard interactions → System status: checks health (evidence: `static/js/dashboard.js`)
