# kmishra987/smart-water-level-awd-iot-system architecture

> Architecture diagram of the GitHub repository kmishra987/smart-water-level-awd-iot-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kmishra987/smart-water-level-awd-iot-system
- Repository: https://github.com/kmishra987/smart-water-level-awd-iot-system

## Overview

This ESP32 water-level monitor reads and validates a sensor, derives water depth and AWD threshold status, signals status locally, serves a web view, and reports measurements to ThingSpeak. It also counts threshold events in persistent preferences and buffers measurements for later upload when connectivity returns. These responsibilities are implemented in one source file; the graph separates them by role. The README is empty, and the sampled source is partial, so links are limited to relationships visible in the excerpt.

Main entry points: [`src/main.cpp`](https://github.com/kmishra987/smart-water-level-awd-iot-system/blob/main/src/main.cpp) (Main loop)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_monitoring["Monitoring"]
  node_controller["Main loop<br/>[main.cpp]"]
  node_acquisition["Sensor acquisition<br/>[main.cpp]"]
  node_measurement["Measurement logic<br/>[main.cpp]"]
  node_status["AWD status<br/>[main.cpp]"]
end

subgraph group_local["Local interfaces"]
  node_indicators["LED indicators<br/>[main.cpp]"]
  node_display["OLED display<br/>[main.cpp]"]
  node_webserver["Local web server<br/>[main.cpp]"]
  node_webview["Status page<br/>[main.cpp]"]
end

subgraph group_connectivity["Connectivity"]
  node_wifi{{"Wi-Fi network"}}
  node_uploader["Cloud uploader<br/>[main.cpp]"]
end

subgraph group_state["State"]
  node_offline[("Offline buffer<br/>[main.cpp]")]
  node_eventstore[("Event preferences<br/>[main.cpp]")]
end

node_sensor(("Water sensor"))
node_browser(("Browser user"))
node_thingpeak{{"ThingSpeak"}}

node_controller -->|"reads"| node_acquisition
node_sensor -->|"provides readings"| node_acquisition
node_controller -->|"calculates"| node_measurement
node_controller -->|"updates"| node_status
node_controller -->|"drives"| node_indicators
node_controller -->|"renders"| node_display
node_controller -->|"handles requests"| node_webserver
node_webserver -->|"sends page"| node_webview
node_webview -->|"serves status"| node_browser
node_controller -->|"loads and saves"| node_eventstore
node_controller -->|"buffers measurements"| node_offline
node_controller -->|"schedules uploads"| node_uploader
node_uploader -->|"sends measurements"| node_thingpeak
node_uploader -->|"uses connection"| node_wifi
node_controller -->|"checks connectivity"| node_wifi
node_offline -->|"replays buffered data"| node_uploader

click node_controller "https://github.com/kmishra987/smart-water-level-awd-iot-system/blob/main/src/main.cpp"
click node_acquisition "https://github.com/kmishra987/smart-water-level-awd-iot-system/blob/main/src/main.cpp"
click node_measurement "https://github.com/kmishra987/smart-water-level-awd-iot-system/blob/main/src/main.cpp"
click node_status "https://github.com/kmishra987/smart-water-level-awd-iot-system/blob/main/src/main.cpp"
click node_indicators "https://github.com/kmishra987/smart-water-level-awd-iot-system/blob/main/src/main.cpp"
click node_display "https://github.com/kmishra987/smart-water-level-awd-iot-system/blob/main/src/main.cpp"
click node_webserver "https://github.com/kmishra987/smart-water-level-awd-iot-system/blob/main/src/main.cpp"
click node_webview "https://github.com/kmishra987/smart-water-level-awd-iot-system/blob/main/src/main.cpp"
click node_offline "https://github.com/kmishra987/smart-water-level-awd-iot-system/blob/main/src/main.cpp"
click node_eventstore "https://github.com/kmishra987/smart-water-level-awd-iot-system/blob/main/src/main.cpp"
click node_uploader "https://github.com/kmishra987/smart-water-level-awd-iot-system/blob/main/src/main.cpp"

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_controller,node_acquisition,node_measurement,node_status,node_browser toneBlue
class node_indicators,node_display,node_webserver,node_webview toneAmber
class node_wifi,node_uploader toneMint
class node_offline,node_eventstore toneRose
class node_sensor,node_thingpeak toneIndigo
```

## Components

### Monitoring

- [Main loop](https://github.com/kmishra987/smart-water-level-awd-iot-system/blob/main/src/main.cpp): `src/main.cpp`
- [Sensor acquisition](https://github.com/kmishra987/smart-water-level-awd-iot-system/blob/main/src/main.cpp): `src/main.cpp`
- [Measurement logic](https://github.com/kmishra987/smart-water-level-awd-iot-system/blob/main/src/main.cpp): `src/main.cpp`
- [AWD status](https://github.com/kmishra987/smart-water-level-awd-iot-system/blob/main/src/main.cpp): `src/main.cpp`

### Local interfaces

- [LED indicators](https://github.com/kmishra987/smart-water-level-awd-iot-system/blob/main/src/main.cpp): `src/main.cpp`
- [OLED display](https://github.com/kmishra987/smart-water-level-awd-iot-system/blob/main/src/main.cpp): `src/main.cpp`
- [Local web server](https://github.com/kmishra987/smart-water-level-awd-iot-system/blob/main/src/main.cpp): `src/main.cpp`
- [Status page](https://github.com/kmishra987/smart-water-level-awd-iot-system/blob/main/src/main.cpp): `src/main.cpp`

### Connectivity

- **Wi-Fi network**
- [Cloud uploader](https://github.com/kmishra987/smart-water-level-awd-iot-system/blob/main/src/main.cpp): `src/main.cpp`

### State

- [Offline buffer](https://github.com/kmishra987/smart-water-level-awd-iot-system/blob/main/src/main.cpp): `src/main.cpp`
- [Event preferences](https://github.com/kmishra987/smart-water-level-awd-iot-system/blob/main/src/main.cpp): `src/main.cpp`

### Other components

- **Water sensor**
- **Browser user**
- **ThingSpeak**

## Connections

- Main loop → Sensor acquisition: reads (evidence: `src/main.cpp`)
- Water sensor → Sensor acquisition: provides readings (evidence: `src/main.cpp`)
- Main loop → Measurement logic: calculates (evidence: `src/main.cpp`)
- Main loop → AWD status: updates (evidence: `src/main.cpp`)
- Main loop → LED indicators: drives (evidence: `src/main.cpp`)
- Main loop → OLED display: renders (evidence: `src/main.cpp`)
- Main loop → Local web server: handles requests (evidence: `src/main.cpp`)
- Local web server → Status page: sends page (evidence: `src/main.cpp`)
- Status page → Browser user: serves status (evidence: `src/main.cpp`)
- Main loop → Event preferences: loads and saves (evidence: `src/main.cpp`)
- Main loop → Offline buffer: buffers measurements (evidence: `src/main.cpp`)
- Main loop → Cloud uploader: schedules uploads (evidence: `src/main.cpp`)
- Cloud uploader → ThingSpeak: sends measurements (evidence: `src/main.cpp`)
- Cloud uploader → Wi-Fi network: uses connection (evidence: `src/main.cpp`)
- Main loop → Wi-Fi network: checks connectivity (evidence: `src/main.cpp`)
- Offline buffer → Cloud uploader: replays buffered data (evidence: `src/main.cpp`)
