# sangle422005-commits/do-an-tuoi-cay architecture

> Architecture diagram of the GitHub repository sangle422005-commits/do-an-tuoi-cay, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sangle422005-commits/do-an-tuoi-cay
- Repository: https://github.com/sangle422005-commits/do-an-tuoi-cay

## Overview

This is a small IoT garden-watering server: ESP32 moisture reports and dashboard commands update shared state, automatic watering and scheduled watering control the pump, and state is exposed to dashboards. The server also accepts air-humidity updates and serves the dashboard HTML. The HTML source was not sampled, so its client-side behavior and calls cannot be confirmed; the graph shows only server-side routes and documented endpoint behavior.

Main entry points: [`server.js`](https://github.com/sangle422005-commits/do-an-tuoi-cay/blob/main/server.js) (Garden state), [`index.html`](https://github.com/sangle422005-commits/do-an-tuoi-cay/blob/main/index.html) (Dashboard HTML)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_server["Server runtime"]
  node_sync_api["Device sync API<br/>[server.js]"]
  node_weather_api["Weather sync API<br/>[server.js]"]
  node_web_control["Web control API<br/>[server.js]"]
  node_shared_state["Garden state<br/>[server.js]"]
end

subgraph group_watering["Watering control"]
  node_auto_control["Automatic watering<br/>[server.js]"]
  node_schedule_timer["Scheduled watering<br/>[server.js]"]
end

subgraph group_dashboard["Dashboard delivery"]
  node_event_stream["State event stream<br/>[server.js]"]
  node_web_sync["State query API<br/>[server.js]"]
  node_dashboard_html["Dashboard HTML<br/>[index.html]"]
end

node_esp32(("ESP32 hardware"))
node_dashboard_user(("Dashboard user"))
node_weather_sender(("Weather data sender"))

node_esp32 -->|"reports moisture"| node_sync_api
node_sync_api -->|"updates state"| node_shared_state
node_sync_api -->|"evaluates thresholds"| node_auto_control
node_auto_control -->|"sets pump state"| node_shared_state
node_sync_api -->|"returns pump state"| node_esp32
node_weather_sender -->|"submits humidity"| node_weather_api
node_weather_api -->|"updates humidity"| node_shared_state
node_weather_api -->|"may stop pump"| node_auto_control
node_dashboard_user -->|"sends commands"| node_web_control
node_web_control -->|"changes settings"| node_shared_state
node_web_control -->|"sets or cancels"| node_schedule_timer
node_schedule_timer -->|"updates pump state"| node_shared_state
node_shared_state -->|"broadcasts updates"| node_event_stream
node_dashboard_user -->|"opens event stream"| node_event_stream
node_dashboard_user -->|"requests state"| node_web_sync
node_web_sync -->|"reads state"| node_shared_state
node_dashboard_user -.->|"opens dashboard"| node_dashboard_html
node_dashboard_html -.->|"sends commands"| node_web_control

click node_sync_api "https://github.com/sangle422005-commits/do-an-tuoi-cay/blob/main/server.js"
click node_weather_api "https://github.com/sangle422005-commits/do-an-tuoi-cay/blob/main/server.js"
click node_web_control "https://github.com/sangle422005-commits/do-an-tuoi-cay/blob/main/server.js"
click node_shared_state "https://github.com/sangle422005-commits/do-an-tuoi-cay/blob/main/server.js"
click node_auto_control "https://github.com/sangle422005-commits/do-an-tuoi-cay/blob/main/server.js"
click node_schedule_timer "https://github.com/sangle422005-commits/do-an-tuoi-cay/blob/main/server.js"
click node_event_stream "https://github.com/sangle422005-commits/do-an-tuoi-cay/blob/main/server.js"
click node_web_sync "https://github.com/sangle422005-commits/do-an-tuoi-cay/blob/main/server.js"
click node_dashboard_html "https://github.com/sangle422005-commits/do-an-tuoi-cay/blob/main/index.html"

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_sync_api,node_weather_api,node_web_control,node_shared_state,node_dashboard_user toneBlue
class node_auto_control,node_schedule_timer toneAmber
class node_event_stream,node_web_sync,node_dashboard_html toneMint
class node_esp32,node_weather_sender toneIndigo
```

## Components

### Server runtime

- [Device sync API](https://github.com/sangle422005-commits/do-an-tuoi-cay/blob/main/server.js): `server.js`
- [Weather sync API](https://github.com/sangle422005-commits/do-an-tuoi-cay/blob/main/server.js): `server.js`
- [Web control API](https://github.com/sangle422005-commits/do-an-tuoi-cay/blob/main/server.js): `server.js`
- [Garden state](https://github.com/sangle422005-commits/do-an-tuoi-cay/blob/main/server.js): `server.js`

### Watering control

- [Automatic watering](https://github.com/sangle422005-commits/do-an-tuoi-cay/blob/main/server.js): `server.js`
- [Scheduled watering](https://github.com/sangle422005-commits/do-an-tuoi-cay/blob/main/server.js): `server.js`

### Dashboard delivery

- [State event stream](https://github.com/sangle422005-commits/do-an-tuoi-cay/blob/main/server.js): `server.js`
- [State query API](https://github.com/sangle422005-commits/do-an-tuoi-cay/blob/main/server.js): `server.js`
- [Dashboard HTML](https://github.com/sangle422005-commits/do-an-tuoi-cay/blob/main/index.html): `index.html`

### Other components

- **ESP32 hardware**
- **Dashboard user**
- **Weather data sender**

## Connections

- ESP32 hardware → Device sync API: reports moisture (evidence: `server.js`)
- Device sync API → Garden state: updates state (evidence: `server.js`)
- Device sync API → Automatic watering: evaluates thresholds (evidence: `server.js`)
- Automatic watering → Garden state: sets pump state (evidence: `server.js`)
- Device sync API → ESP32 hardware: returns pump state (evidence: `server.js`)
- Weather data sender → Weather sync API: submits humidity (evidence: `server.js`)
- Weather sync API → Garden state: updates humidity (evidence: `server.js`)
- Weather sync API → Automatic watering: may stop pump (evidence: `server.js`)
- Dashboard user → Web control API: sends commands (evidence: `server.js`)
- Web control API → Garden state: changes settings (evidence: `server.js`)
- Web control API → Scheduled watering: sets or cancels (evidence: `server.js`)
- Scheduled watering → Garden state: updates pump state (evidence: `server.js`)
- Garden state → State event stream: broadcasts updates (evidence: `server.js`)
- Dashboard user → State event stream: opens event stream (evidence: `server.js`)
- Dashboard user → State query API: requests state (evidence: `server.js`)
- State query API → Garden state: reads state (evidence: `server.js`)
- Dashboard user → Dashboard HTML: opens dashboard
- Dashboard HTML → Web control API: sends commands
