# cmames/floraguard architecture

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

- Interactive diagram: https://gitdiagram.com/cmames/floraguard
- Repository: https://github.com/cmames/floraguard

## Overview

FloraGuard is ESP32 irrigation firmware. Boot initialization configures sensing, storage, actuators, and—when WiFi connects—time and HTTP services; a FreeRTOS automation loop reads soil moisture, applies safety and daylight thresholds, and controls watering. The dashboard fetches status and displays telemetry and logs. Calibration is a separate firmware mode. The graph preserves documented dashboard, history, and discovery capabilities; unsampled frontend and calibration behavior is not inferred beyond README or indexed references.

Main entry points: [`src/main.c`](https://github.com/cmames/floraguard/blob/main/src/main.c) (Firmware orchestration), [`components/http_api_manager/http_api_manager.c`](https://github.com/cmames/floraguard/blob/main/components/http_api_manager/http_api_manager.c) (HTTP API and dashboard server), [`components/log_manager/log_manager.c`](https://github.com/cmames/floraguard/blob/main/components/log_manager/log_manager.c) (Logs and moisture history), [`components/soil_moisture/soil_moisture.c`](https://github.com/cmames/floraguard/blob/main/components/soil_moisture/soil_moisture.c) (Soil moisture ADC)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Irrigation control"]
  node_main["Firmware orchestration<br/>[main.c]"]
  node_automation["Watering control loop<br/>[main.c]"]
  node_calibration["Sensor calibration<br/>[calibration.c]"]
  node_actuators["Pump and status LEDs<br/>[actuator_manager.c]"]
end

subgraph group_telemetry["Sensors and history"]
  node_soil["Soil moisture ADC<br/>[soil_moisture.c]"]
  node_bme["BME280 telemetry<br/>[bme280_manager.c]"]
  node_history[("Logs and moisture history<br/>[log_manager.c]")]
end

subgraph group_connectivity["Network and dashboard"]
  node_wifi["WiFi and mDNS<br/>[wifi_manager.c]"]
  node_api["HTTP API and dashboard server<br/>[http_api_manager.c]"]
  node_dashboard["Async web dashboard<br/>[index.html]"]
end

subgraph group_platform["Device services"]
  node_time["SNTP and daylight time<br/>[sntp_manager.c]"]
  node_storage["SPIFFS mount<br/>[storage_manager.c]"]
end

node_operator(("Local user"))
node_network(("Local network"))

node_operator -->|"opens dashboard"| node_dashboard
node_dashboard -->|"fetches status"| node_api
node_operator -->|"requests status"| node_api
node_main -->|"initializes"| node_history
node_main -->|"mounts"| node_storage
node_main -->|"initializes"| node_actuators
node_main -->|"initializes"| node_soil
node_main -->|"initializes"| node_bme
node_main -->|"starts"| node_wifi
node_main -->|"initializes"| node_time
node_main -->|"starts"| node_api
node_main -->|"launches task"| node_automation
node_main -->|"dispatches mode"| node_calibration
node_automation -->|"reads moisture"| node_soil
node_automation -->|"records samples"| node_history
node_automation -->|"checks daylight"| node_time
node_automation -->|"controls watering"| node_actuators
node_api -->|"reads metrics"| node_soil
node_api -->|"reads telemetry"| node_bme
node_api -->|"reads history"| node_history
node_api -->|"signals requests"| node_actuators
node_api -->|"streams dashboard file"| node_storage
node_wifi -->|"joins and advertises"| node_network
node_api -->|"serves HTTP"| node_network
node_calibration -.->|"calibrates readings"| node_soil
node_history -->|"timestamps logs"| node_time

click node_main "https://github.com/cmames/floraguard/blob/main/src/main.c"
click node_automation "https://github.com/cmames/floraguard/blob/main/src/main.c"
click node_calibration "https://github.com/cmames/floraguard/blob/main/components/moisture_calibration/calibration.c"
click node_soil "https://github.com/cmames/floraguard/blob/main/components/soil_moisture/soil_moisture.c"
click node_bme "https://github.com/cmames/floraguard/blob/main/components/bme280_manager/bme280_manager.c"
click node_history "https://github.com/cmames/floraguard/blob/main/components/log_manager/log_manager.c"
click node_time "https://github.com/cmames/floraguard/blob/main/components/sntp_manager/sntp_manager.c"
click node_actuators "https://github.com/cmames/floraguard/blob/main/components/actuator_manager/actuator_manager.c"
click node_storage "https://github.com/cmames/floraguard/blob/main/components/storage_manager/storage_manager.c"
click node_wifi "https://github.com/cmames/floraguard/blob/main/components/wifi_manager/wifi_manager.c"
click node_api "https://github.com/cmames/floraguard/blob/main/components/http_api_manager/http_api_manager.c"
click node_dashboard "https://github.com/cmames/floraguard/blob/main/data/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_main,node_automation,node_calibration,node_actuators,node_operator toneBlue
class node_soil,node_bme,node_history toneAmber
class node_wifi,node_api,node_dashboard toneMint
class node_time,node_storage toneRose
class node_network toneIndigo
```

## Components

### Irrigation control

- [Firmware orchestration](https://github.com/cmames/floraguard/blob/main/src/main.c): `src/main.c`
- [Watering control loop](https://github.com/cmames/floraguard/blob/main/src/main.c): `src/main.c`
- [Sensor calibration](https://github.com/cmames/floraguard/blob/main/components/moisture_calibration/calibration.c): `components/moisture_calibration/calibration.c`
- [Pump and status LEDs](https://github.com/cmames/floraguard/blob/main/components/actuator_manager/actuator_manager.c): `components/actuator_manager/actuator_manager.c`

### Sensors and history

- [Soil moisture ADC](https://github.com/cmames/floraguard/blob/main/components/soil_moisture/soil_moisture.c): `components/soil_moisture/soil_moisture.c`
- [BME280 telemetry](https://github.com/cmames/floraguard/blob/main/components/bme280_manager/bme280_manager.c): `components/bme280_manager/bme280_manager.c`
- [Logs and moisture history](https://github.com/cmames/floraguard/blob/main/components/log_manager/log_manager.c): `components/log_manager/log_manager.c`

### Network and dashboard

- [WiFi and mDNS](https://github.com/cmames/floraguard/blob/main/components/wifi_manager/wifi_manager.c): `components/wifi_manager/wifi_manager.c`
- [HTTP API and dashboard server](https://github.com/cmames/floraguard/blob/main/components/http_api_manager/http_api_manager.c): `components/http_api_manager/http_api_manager.c`
- [Async web dashboard](https://github.com/cmames/floraguard/blob/main/data/index.html): `data/index.html`

### Device services

- [SNTP and daylight time](https://github.com/cmames/floraguard/blob/main/components/sntp_manager/sntp_manager.c): `components/sntp_manager/sntp_manager.c`
- [SPIFFS mount](https://github.com/cmames/floraguard/blob/main/components/storage_manager/storage_manager.c): `components/storage_manager/storage_manager.c`

### Other components

- **Local user**
- **Local network**

## Connections

- Local user → Async web dashboard: opens dashboard (evidence: `README.md`)
- Async web dashboard → HTTP API and dashboard server: fetches status (evidence: `README.md`)
- Local user → HTTP API and dashboard server: requests status (evidence: `README.md`)
- Firmware orchestration → Logs and moisture history: initializes (evidence: `src/main.c`)
- Firmware orchestration → SPIFFS mount: mounts (evidence: `src/main.c`)
- Firmware orchestration → Pump and status LEDs: initializes (evidence: `src/main.c`)
- Firmware orchestration → Soil moisture ADC: initializes (evidence: `src/main.c`)
- Firmware orchestration → BME280 telemetry: initializes (evidence: `src/main.c`)
- Firmware orchestration → WiFi and mDNS: starts (evidence: `src/main.c`)
- Firmware orchestration → SNTP and daylight time: initializes (evidence: `src/main.c`)
- Firmware orchestration → HTTP API and dashboard server: starts (evidence: `src/main.c`)
- Firmware orchestration → Watering control loop: launches task (evidence: `src/main.c`)
- Firmware orchestration → Sensor calibration: dispatches mode (evidence: `src/main.c`)
- Watering control loop → Soil moisture ADC: reads moisture (evidence: `src/main.c`)
- Watering control loop → Logs and moisture history: records samples (evidence: `src/main.c`)
- Watering control loop → SNTP and daylight time: checks daylight (evidence: `src/main.c`)
- Watering control loop → Pump and status LEDs: controls watering (evidence: `src/main.c`)
- HTTP API and dashboard server → Soil moisture ADC: reads metrics (evidence: `components/http_api_manager/http_api_manager.c`)
- HTTP API and dashboard server → BME280 telemetry: reads telemetry (evidence: `components/http_api_manager/http_api_manager.c`)
- HTTP API and dashboard server → Logs and moisture history: reads history (evidence: `components/http_api_manager/http_api_manager.c`)
- HTTP API and dashboard server → Pump and status LEDs: signals requests (evidence: `components/http_api_manager/http_api_manager.c`)
- HTTP API and dashboard server → SPIFFS mount: streams dashboard file (evidence: `components/http_api_manager/http_api_manager.c`)
- WiFi and mDNS → Local network: joins and advertises (evidence: `components/wifi_manager/wifi_manager.c`)
- HTTP API and dashboard server → Local network: serves HTTP (evidence: `README.md`)
- Sensor calibration → Soil moisture ADC: calibrates readings
- Logs and moisture history → SNTP and daylight time: timestamps logs
