# rakiz/rzdomo architecture

> Architecture diagram of the GitHub repository rakiz/rzdomo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rakiz/rzdomo
- Repository: https://github.com/rakiz/rzdomo

## Overview

##### Project type and purpose
- Embedded IoT firmware for microcontrollers (ESP8266/ESP32 via PlatformIO).
- Gathers multiple calibrated sensor readings (pool temperature, pH, UV, greenhouse, hive, etc.).
- Hosts a built-in HTTP server serving static UI (HTML/JS) for live data graphs and calibration screens.

##### File structure
- platformio.ini & CMakeLists.txt → build & deployment scripts targeting MCU.
- src/
– main.cpp, RzLoop.h → primary control loop.
– RzFiles.* → file‐system abstraction (SPIFFS/LittleFS) for serving data/config pages.
– network/ → Wi-Fi (RzWifi), time sync (RzTime), HTTP server (RzServer).
– sensors/ → generic metrics (RzMetric), specific drivers (RzTemperature, etc.).
– tools/ → data‐processing utilities (MultiSampling, LinearCorrection).
- data/ → static assets (config.html/js, index.html/js) to be uploaded into embedded FS.

##### Key README insights
- Project started for pool temp, evolved to multi‐sensor IoT platform.
- Automatic configuration screens generated per available sensors.
- Aims to standardize IoT boilerplate.

##### Main components & interactions
a. Hardware & Sensors
– Microcontroller (ESPxx)
– External sensors (temperature, pH, UV, turbidity, etc.)
b. Firmware modules
– RzLoop (core event loop)
– Sensors layer → RzMetric + sensor drivers → raw data
– Tools layer → sampling, calibration → processed readings
– Files layer → embedded FS for static content & config persistence
– Network layer → RzWifi (Wi-Fi/AP mode), RzTime (NTP), RzServer (HTTP)
c. Client UI
– Browser on smartphone/PC connecting via Wi-Fi AP or station mode
– Serves index.html/js for real-time curves and config.html/js for settings

##### Architectural patterns & principles
- Layered architecture:
– Hardware abstraction (sensor drivers)
– Utility services (sampling, correction)
– Persistence (file system)
– Network/API (HTTP server)
– Presentation (static web assets)
- Modular design via separate directories (sensors, tools, network)
- Event‐driven loop for periodic sampling & serving requests

– Hardware: Microcontroller + sensor connectors
– Sensors Module (RzMetric + specific drivers)
– Processing Module (MultiSampling, LinearCorrection)
– File System Module (RzFiles + data/ assets)
– Network Module (Wi-Fi, Time sync, HTTP Server)
– Main Loop (event dispatcher)
– Sensors → Processing → File System (optional logging)
– Processing → Served in HTTP responses → Client
– Blue for hardware/sensors
– Green for firmware modules
– Orange for external systems (Client, NTP)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Systems
    subgraph "Client UI" 
        direction TB
        LiveUI["Live Data Dashboard\n(index.html, index.js)"]:::external
        ConfUI["Configuration Screens\n(config.html, config.js)"]:::external
    end
    NTP["NTP Server"]:::external

    %% Embedded Device Box
    subgraph "Embedded Device" 
        direction TB
        ML["Main Loop\n(RzLoop)"]:::module

        subgraph "Hardware & Sensors"
            direction TB
            MCU["Microcontroller\n(ESP8266/ESP32)"]:::hardware
            SENSORS["External Sensors\n(pH, Temp, UV, etc.)"]:::hardware
        end

        subgraph "Sensors Module"
            direction TB
            RZMETRIC["RzMetric"]:::module
            RZTEMP["RzTemperature"]:::module
        end

        subgraph "Processing Module"
            direction TB
            MULTI["MultiSampling"]:::module
            LINEAR["LinearCorrection"]:::module
            TOOLS["Tools"]:::module
        end

        subgraph "File System Module"
            direction TB
            RZFILES["RzFiles\n(SPIFFS/LittleFS)"]:::module
        end

        subgraph "Network Module"
            direction TB
            WIFI["RzWifi\n(Wi-Fi/AP modes)"]:::module
            TIME["RzTime\n(NTP Sync)"]:::module
            SERVER["RzServer\n(HTTP Server)"]:::module
        end
    end

    %% Data Flows
    SENSORS -->|"I2C/Analog"| RZMETRIC
    RZMETRIC -->|"raw data"| MULTI
    MULTI -->|"sampled data"| LINEAR
    LINEAR -->|"calibrated readings"| TOOLS
    TOOLS -->|"persist logs"| RZFILES
    TOOLS -->|"JSON readings"| SERVER

    ML -->|"invokes sensor read"| RZMETRIC
    ML -->|"triggers processing"| MULTI
    ML -->|"manages FS"| RZFILES
    ML -->|"handles requests"| SERVER

    SERVER -->|"HTTP GET/JSON"| LiveUI
    LiveUI -->|"HTTP Response"| SERVER
    SERVER -->|"HTTP GET/JSON"| ConfUI
    ConfUI -->|"HTTP Response"| SERVER

    NTP -->|"NTP protocol"| TIME
    TIME -->|"time update"| SERVER

    %% Click Events
    click ML "https://github.com/rakiz/rzdomo/blob/master/src/main.cpp"
    click RZMETRIC "https://github.com/rakiz/rzdomo/blob/master/src/sensors/RzMetric.cpp"
    click RZTEMP "https://github.com/rakiz/rzdomo/blob/master/src/sensors/RzTemperature.cpp"
    click MULTI "https://github.com/rakiz/rzdomo/blob/master/src/tools/MultiSampling.cpp"
    click LINEAR "https://github.com/rakiz/rzdomo/blob/master/src/tools/LinearCorrection.cpp"
    click TOOLS "https://github.com/rakiz/rzdomo/blob/master/src/tools/Tools.cpp"
    click RZFILES "https://github.com/rakiz/rzdomo/blob/master/src/RzFiles.cpp"
    click WIFI "https://github.com/rakiz/rzdomo/blob/master/src/network/RzWifi.cpp"
    click TIME "https://github.com/rakiz/rzdomo/blob/master/src/network/RzTime.cpp"
    click SERVER "https://github.com/rakiz/rzdomo/blob/master/src/network/RzServer.cpp"
    click LiveUI "https://github.com/rakiz/rzdomo/blob/master/data/index.html"
    click ConfUI "https://github.com/rakiz/rzdomo/blob/master/data/config.html"

    %% Styles
    classDef hardware fill:#AED6F1,stroke:#21618C,color:#1B2631
    classDef module fill:#ABEBC6,stroke:#1D8348,color:#145A32
    classDef external fill:#F9E79F,stroke:#B7950B,color:#7D6608
```
