# racmanmontes09-cyber/firmware architecture

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

- Interactive diagram: https://gitdiagram.com/racmanmontes09-cyber/firmware
- Repository: https://github.com/racmanmontes09-cyber/firmware

## Overview

Project L.E.A.F. is ESP32 firmware for monitoring and controlling a growing environment. Its main runtime initializes configuration, sensors, networking, and storage, then periodically samples sensors and sends telemetry while maintaining MQTT and Wi-Fi. The firmware also exposes actuator control, calibration and diagnostics, OTA rollback protection, and performance reporting. The graph reflects only relationships visible in the excerpts or source index; several subsystem implementations and runtime connections were not sampled.

Main entry points: [`src/main.cpp`](https://github.com/racmanmontes09-cyber/firmware/blob/main/src/main.cpp) (Main loop), [`src/ApiClient.cpp`](https://github.com/racmanmontes09-cyber/firmware/blob/main/src/ApiClient.cpp) (MQTT and API client), [`src/Sensors.cpp`](https://github.com/racmanmontes09-cyber/firmware/blob/main/src/Sensors.cpp) (Sensor acquisition), [`src/WifiManager.cpp`](https://github.com/racmanmontes09-cyber/firmware/blob/main/src/WifiManager.cpp) (Wi-Fi manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Firmware runtime"]
  node_controller["Main loop<br/>[main.cpp]"]
end

subgraph group_sensing["Sensing and control"]
  node_sensors["Sensor acquisition<br/>[Sensors.cpp]"]
  node_actuators["Actuator control<br/>[Actuators.cpp]"]
end

subgraph group_connectivity["Connectivity and telemetry"]
  node_wifi["Wi-Fi manager<br/>[WifiManager.cpp]"]
  node_api["MQTT and API client<br/>[ApiClient.cpp]"]
  node_queue[("Telemetry queue<br/>[TelemetryQueue.cpp]")]
  node_cellular["Cellular manager"]
end

subgraph group_support["Configuration and support"]
  node_runtimeconfig["Runtime settings<br/>[RuntimeConfig.cpp]"]
  node_config["Firmware settings<br/>[Config.h]"]
  node_ota["OTA rollback<br/>[OtaRollback.cpp]"]
  node_diagnostics["Diagnostics<br/>[Diag.cpp]"]
  node_performance["Performance metrics<br/>[PerfBenchmark.cpp]"]
end

node_broker(("MQTT service"))
node_operator(("Device operator"))

node_controller -->|"initializes"| node_runtimeconfig
node_controller -->|"starts and samples"| node_sensors
node_controller -->|"starts and maintains"| node_wifi
node_controller -->|"mounts storage"| node_queue
node_controller -->|"maintains MQTT"| node_api
node_controller -->|"sends readings"| node_api
node_controller -->|"publishes heartbeat"| node_api
node_controller -->|"marks boot success"| node_ota
node_controller -->|"starts diagnostics"| node_diagnostics
node_controller -->|"starts benchmarking"| node_performance
node_operator -->|"issues serial commands"| node_controller
node_api -.->|"communicates via MQTT"| node_broker

click node_controller "https://github.com/racmanmontes09-cyber/firmware/blob/main/src/main.cpp"
click node_sensors "https://github.com/racmanmontes09-cyber/firmware/blob/main/src/Sensors.cpp"
click node_actuators "https://github.com/racmanmontes09-cyber/firmware/blob/main/src/Actuators.cpp"
click node_wifi "https://github.com/racmanmontes09-cyber/firmware/blob/main/src/WifiManager.cpp"
click node_api "https://github.com/racmanmontes09-cyber/firmware/blob/main/src/ApiClient.cpp"
click node_queue "https://github.com/racmanmontes09-cyber/firmware/blob/main/src/TelemetryQueue.cpp"
click node_cellular "https://github.com/racmanmontes09-cyber/firmware/blob/main/src/CellularManager.cpp"
click node_runtimeconfig "https://github.com/racmanmontes09-cyber/firmware/blob/main/src/RuntimeConfig.cpp"
click node_config "https://github.com/racmanmontes09-cyber/firmware/blob/main/include/Config.h"
click node_ota "https://github.com/racmanmontes09-cyber/firmware/blob/main/src/OtaRollback.cpp"
click node_diagnostics "https://github.com/racmanmontes09-cyber/firmware/blob/main/src/Diag.cpp"
click node_performance "https://github.com/racmanmontes09-cyber/firmware/blob/main/src/PerfBenchmark.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 toneBlue
class node_sensors,node_actuators toneAmber
class node_wifi,node_api,node_queue,node_cellular toneMint
class node_runtimeconfig,node_config,node_ota,node_diagnostics,node_performance toneRose
class node_broker,node_operator toneIndigo
```

## Components

### Firmware runtime

- [Main loop](https://github.com/racmanmontes09-cyber/firmware/blob/main/src/main.cpp): `src/main.cpp`

### Sensing and control

- [Sensor acquisition](https://github.com/racmanmontes09-cyber/firmware/blob/main/src/Sensors.cpp): `src/Sensors.cpp`
- [Actuator control](https://github.com/racmanmontes09-cyber/firmware/blob/main/src/Actuators.cpp): `src/Actuators.cpp`

### Connectivity and telemetry

- [Wi-Fi manager](https://github.com/racmanmontes09-cyber/firmware/blob/main/src/WifiManager.cpp): `src/WifiManager.cpp`
- [MQTT and API client](https://github.com/racmanmontes09-cyber/firmware/blob/main/src/ApiClient.cpp): `src/ApiClient.cpp`
- [Telemetry queue](https://github.com/racmanmontes09-cyber/firmware/blob/main/src/TelemetryQueue.cpp): `src/TelemetryQueue.cpp`
- [Cellular manager](https://github.com/racmanmontes09-cyber/firmware/blob/main/src/CellularManager.cpp): `src/CellularManager.cpp`

### Configuration and support

- [Runtime settings](https://github.com/racmanmontes09-cyber/firmware/blob/main/src/RuntimeConfig.cpp): `src/RuntimeConfig.cpp`
- [Firmware settings](https://github.com/racmanmontes09-cyber/firmware/blob/main/include/Config.h): `include/Config.h`
- [OTA rollback](https://github.com/racmanmontes09-cyber/firmware/blob/main/src/OtaRollback.cpp): `src/OtaRollback.cpp`
- [Diagnostics](https://github.com/racmanmontes09-cyber/firmware/blob/main/src/Diag.cpp): `src/Diag.cpp`
- [Performance metrics](https://github.com/racmanmontes09-cyber/firmware/blob/main/src/PerfBenchmark.cpp): `src/PerfBenchmark.cpp`

### Other components

- **MQTT service**
- **Device operator**

## Connections

- Main loop → Runtime settings: initializes (evidence: `src/main.cpp`)
- Main loop → Sensor acquisition: starts and samples (evidence: `src/main.cpp`)
- Main loop → Wi-Fi manager: starts and maintains (evidence: `src/main.cpp`)
- Main loop → Telemetry queue: mounts storage (evidence: `src/main.cpp`)
- Main loop → MQTT and API client: maintains MQTT (evidence: `src/main.cpp`)
- Main loop → MQTT and API client: sends readings (evidence: `src/main.cpp`)
- Main loop → MQTT and API client: publishes heartbeat (evidence: `src/main.cpp`)
- Main loop → OTA rollback: marks boot success (evidence: `src/main.cpp`)
- Main loop → Diagnostics: starts diagnostics (evidence: `src/main.cpp`)
- Main loop → Performance metrics: starts benchmarking (evidence: `src/main.cpp`)
- Device operator → Main loop: issues serial commands (evidence: `src/main.cpp`)
- MQTT and API client → MQTT service: communicates via MQTT
