# angelointj/simut architecture

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

- Interactive diagram: https://gitdiagram.com/angelointj/simut
- Repository: https://github.com/angelointj/simut

## Overview

#### 1. Purpose and Runtime
SIMUT is offline-capable IoT firmware for Raspberry Pi Pico W/RP2040, built on Arduino-Pico through PlatformIO. It monitors up to 16 configurable temperature/humidity/pressure sensor slots, presents local TFT/touch and embedded-web interfaces, retains audit/history data in flash, and exports telemetry.

Primary firmware entry point: `src/main.cpp`. Build/environment and partition behavior are defined in `platformio.ini`; deployment can run in Docker via `Dockerfile` and `docker-compose.yml`.

#### 2. Application Orchestration and Dual-Core Boundary
`AppManager` is the central lifecycle/state coordinator: boot, periodic main-loop work, sensor processing, commands, events, graphs, and historical alarms are split across `src/AppManager_Boot.cpp`, `src/AppManager_Loop.cpp`, and `src/AppManager_Sensors.cpp` (with interface in `src/AppManager.h`).

Core 0 runs application, networking, storage, telemetry, and CLI work. Core 1 owns display/touch work. Cross-core communication is via application state/snapshots; flash operations require Core 1 pausing, with concurrency checking support in `src/ConcurrencyAsserts.h` and `src/FlashIrqProbe.cpp`.

#### 3. Acquisition, Alarm, and Persistence Pipeline
`SensorManager` discovers/configures and samples DS18B20, DHT22, and BMx280 devices, converting readings into first-class channels and applying calibration/error handling. Core paths: `src/SensorManager.cpp`, `src/SensorManager.h`, `src/sensors/SensorChannels.h`.

Sensor results flow through application alarm evaluation and queueing (`src/AlarmQueue.h`, `src/AlarmPayload.h`), then into current state, UI/web snapshots, telemetry, and historical persistence.

`StorageManager` owns LittleFS access, durable configuration, and file lifecycle (`src/StorageManager.cpp`, `src/StorageManager.h`). Binary V5 history is a separate codec/store layer in `src/HistoryV5.cpp` and `src/HistoryV5.h`, using daily records for later graphing/export. This flash boundary is critical for watchdog and dual-core safety.

#### 4. Local Display and Interaction
`DisplayManager` is Core 1’s UI controller, responsible for dashboard, graphs, calibration, settings, authentication screens, touch dispatch, fonts, themes, and language-pack loading. Main boundaries: `src/DisplayManager.cpp`, `src/DisplayManager_Touch.cpp`, `src/DisplayManager_Graph.cpp`.

Display hardware abstractions select TFT/LCD and touch drivers through `src/display/DisplayDriver.h`, `src/display/ILI9341_320x240.h`, and `src/display/XPT2046.h`. Themes and persisted theme assets are represented by `src/Themes.cpp` and `data/themes/`; external PT/ES language packs reside in `data/lang/`.

#### 5. Network, Web, and Authorization Surface
`NetworkManager` establishes Wi-Fi, mDNS, NTP, and setup-AP behavior (`src/NetworkManager.cpp`, `src/NetworkManager.h`). `WebManager` exposes embedded UI, REST API, history/downloads, file operations, metrics, calibration, and OTA routes through `src/WebManager_Core.cpp`, `src/WebManager_Api.cpp`, and `src/WebManager_Auth.cpp`.

The browser UI is bundled in `WebUI.h`. History is intentionally served as raw binary files; browser-side code handles graph bucketing and CSV conversion. Web authorization/session enforcement is a boundary ahead of mutable configuration, filesystem, OTA, and administrative endpoints.

#### 6. External Integrations and Operations
`TelemetryManager` batches readings for HTTP POST or MQTT, including optional Home Assistant discovery (`src/TelemetryManager.cpp`, `src/TelemetryManager.h`, `src/HaDiscovery.h`). Prometheus exposition is handled by `src/WebManager_Metrics.cpp` and `src/PromMetrics.h`; remote RFC 5424 UDP logging uses `src/SyslogManager.cpp`.

`LogManager` and policy filtering provide local diagnostics/crash-forensics persistence (`src/LogManager.cpp`, `src/LogPolicy.cpp`). USB CDC CLI enters through command parsing/dispatch in `src/CommandManager.cpp` and `src/CommandParser.cpp`.

#### 7. Update and Recovery Subsystem
OTA is a staged workflow separated from web transport: web routes accept uploads, while `src/ota/orchestrator.cpp` coordinates validation, firmware staging/application, configuration snapshots, and backup/restore. Key stages are `src/ota/validation.cpp`, `src/ota/firmware_stage.cpp`, and `src/ota/restore.cpp`.

This isolation preserves Wi-Fi/users/sensor configuration across firmware replacement and protects flash integrity through metadata, CRC-oriented backup formats, and controlled apply/rollback-related steps.

Main entry points: [`src/AppManager.h`](https://github.com/angelointj/simut/blob/main/src/AppManager.h) (AppManager), [`src/WebManager_Core.cpp`](https://github.com/angelointj/simut/blob/main/src/WebManager_Core.cpp) (WebManager), [`src/StorageManager.cpp`](https://github.com/angelointj/simut/blob/main/src/StorageManager.cpp) (StorageManager), [`src/DisplayManager.cpp`](https://github.com/angelointj/simut/blob/main/src/DisplayManager.cpp) (DisplayManager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core0["Core 0 services"]
  node_app["AppManager<br/>lifecycle coordinator<br/>[AppManager.h]"]
  node_sensors["SensorManager<br/>acquisition<br/>[SensorManager.cpp]"]
  node_channels["Sensor channels<br/>reading model<br/>[SensorChannels.h]"]
  node_alarms["Alarm queue<br/>alarm pipeline<br/>[AlarmQueue.h]"]
  node_storage[("StorageManager<br/>LittleFS persistence<br/>[StorageManager.cpp]")]
  node_history[("V5 history store<br/>binary daily records<br/>[HistoryV5.cpp]")]
  node_network["NetworkManager<br/>Wi-Fi and time<br/>[NetworkManager.cpp]"]
  node_web["WebManager<br/>embedded web and REST"]
  node_auth["Web authorization<br/>session enforcement"]
  node_telemetry["TelemetryManager<br/>HTTP/MQTT export"]
  node_logs["Diagnostics logging<br/>local and syslog<br/>[LogManager.cpp]"]
  node_cli["USB CDC CLI<br/>command dispatch<br/>[CommandManager.cpp]"]
  node_ota["OTA orchestrator<br/>staged updater<br/>[orchestrator.cpp]"]
  node_concurrency["Flash safety checks<br/>dual-core guard"]
end

subgraph group_core1["Core 1 UI"]
  node_display["DisplayManager<br/>UI controller<br/>[DisplayManager.cpp]"]
  node_display_hw["TFT and touch drivers<br/>hardware abstraction<br/>[DisplayDriver.h]"]
end

subgraph group_external["Local and remote surfaces"]
  node_browser["Browser UI<br/>embedded client<br/>[WebUI.h]"]
  node_remote(("Remote consumers<br/>telemetry and syslog<br/>[HaDiscovery.h]"))
end

node_firmware{{"Firmware entry<br/>Arduino-Pico runtime<br/>[main.cpp]"}}

node_firmware -->|"boots"| node_app
node_app -->|"samples"| node_sensors
node_sensors -->|"produces"| node_channels
node_channels -->|"evaluates"| node_alarms
node_app -->|"loads and saves state"| node_storage
node_alarms -->|"persists records"| node_history
node_storage -->|"LittleFS access"| node_history
node_app -->|"starts"| node_network
node_network -->|"connectivity"| node_web
node_auth -->|"protects routes"| node_web
node_web -->|"serves UI and API"| node_browser
node_web -->|"serves raw files"| node_history
node_app -->|"provides readings"| node_telemetry
node_telemetry -->|"exports"| node_remote
node_logs -.->|"forwards syslog"| node_remote
node_cli -->|"commands"| node_app
node_web -->|"upload transport"| node_ota
node_ota -->|"backup and restore"| node_storage
node_app -->|"state snapshots"| node_display
node_display -->|"renders and reads touch"| node_display_hw
node_concurrency -.->|"guards flash operations"| node_storage
node_concurrency -.->|"pauses Core 1"| node_display

click node_firmware "https://github.com/angelointj/simut/blob/main/src/main.cpp"
click node_app "https://github.com/angelointj/simut/blob/main/src/AppManager.h"
click node_sensors "https://github.com/angelointj/simut/blob/main/src/SensorManager.cpp"
click node_channels "https://github.com/angelointj/simut/blob/main/src/sensors/SensorChannels.h"
click node_alarms "https://github.com/angelointj/simut/blob/main/src/AlarmQueue.h"
click node_storage "https://github.com/angelointj/simut/blob/main/src/StorageManager.cpp"
click node_history "https://github.com/angelointj/simut/blob/main/src/HistoryV5.cpp"
click node_network "https://github.com/angelointj/simut/blob/main/src/NetworkManager.cpp"
click node_web "https://github.com/angelointj/simut/blob/main/src/WebManager_Core.cpp"
click node_auth "https://github.com/angelointj/simut/blob/main/src/WebManager_Auth.cpp"
click node_telemetry "https://github.com/angelointj/simut/blob/main/src/TelemetryManager.cpp"
click node_logs "https://github.com/angelointj/simut/blob/main/src/LogManager.cpp"
click node_cli "https://github.com/angelointj/simut/blob/main/src/CommandManager.cpp"
click node_ota "https://github.com/angelointj/simut/blob/main/src/ota/orchestrator.cpp"
click node_concurrency "https://github.com/angelointj/simut/blob/main/src/ConcurrencyAsserts.h"
click node_display "https://github.com/angelointj/simut/blob/main/src/DisplayManager.cpp"
click node_display_hw "https://github.com/angelointj/simut/blob/main/src/display/DisplayDriver.h"
click node_browser "https://github.com/angelointj/simut/blob/main/WebUI.h"
click node_remote "https://github.com/angelointj/simut/blob/main/src/HaDiscovery.h"

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_app,node_sensors,node_channels,node_alarms,node_storage,node_history,node_network,node_web,node_auth,node_telemetry,node_logs,node_cli,node_ota,node_concurrency toneBlue
class node_display,node_display_hw toneAmber
class node_browser,node_remote toneMint
class node_firmware toneNeutral
```

## Components

### Core 0 services

Application, network, storage, and integrations.

- [AppManager](https://github.com/angelointj/simut/blob/main/src/AppManager.h): lifecycle coordinator · Coordinates boot, loop, state, alarms, and snapshots. · `src/AppManager.h`
- [SensorManager](https://github.com/angelointj/simut/blob/main/src/SensorManager.cpp): acquisition · Discovers and samples configured sensor slots. · `src/SensorManager.cpp`
- [Sensor channels](https://github.com/angelointj/simut/blob/main/src/sensors/SensorChannels.h): reading model · `src/sensors/SensorChannels.h`
- [Alarm queue](https://github.com/angelointj/simut/blob/main/src/AlarmQueue.h): alarm pipeline · `src/AlarmQueue.h`
- [StorageManager](https://github.com/angelointj/simut/blob/main/src/StorageManager.cpp): LittleFS persistence · Owns durable configuration and file lifecycle. · `src/StorageManager.cpp`
- [V5 history store](https://github.com/angelointj/simut/blob/main/src/HistoryV5.cpp): binary daily records · Persists historical readings for graphs and export. · `src/HistoryV5.cpp`
- [NetworkManager](https://github.com/angelointj/simut/blob/main/src/NetworkManager.cpp): Wi-Fi and time · Manages Wi-Fi, mDNS, NTP, and setup AP. · `src/NetworkManager.cpp`
- [WebManager](https://github.com/angelointj/simut/blob/main/src/WebManager_Core.cpp): embedded web and REST · Serves UI, API, downloads, files, metrics, and OTA routes. · `src/WebManager_Core.cpp`
- [Web authorization](https://github.com/angelointj/simut/blob/main/src/WebManager_Auth.cpp): session enforcement · Guards mutable and administrative routes. · `src/WebManager_Auth.cpp`
- [TelemetryManager](https://github.com/angelointj/simut/blob/main/src/TelemetryManager.cpp): HTTP/MQTT export · `src/TelemetryManager.cpp`
- [Diagnostics logging](https://github.com/angelointj/simut/blob/main/src/LogManager.cpp): local and syslog · `src/LogManager.cpp`
- [USB CDC CLI](https://github.com/angelointj/simut/blob/main/src/CommandManager.cpp): command dispatch · `src/CommandManager.cpp`
- [OTA orchestrator](https://github.com/angelointj/simut/blob/main/src/ota/orchestrator.cpp): staged updater · Validates, stages, applies, and restores firmware updates. · `src/ota/orchestrator.cpp`
- [Flash safety checks](https://github.com/angelointj/simut/blob/main/src/ConcurrencyAsserts.h): dual-core guard · Coordinates Core 1 pause during flash operations. · `src/ConcurrencyAsserts.h`

### Core 1 UI

Display and touch runtime.

- [DisplayManager](https://github.com/angelointj/simut/blob/main/src/DisplayManager.cpp): UI controller · Owns dashboard, graphs, settings, screens, and touch dispatch. · `src/DisplayManager.cpp`
- [TFT and touch drivers](https://github.com/angelointj/simut/blob/main/src/display/DisplayDriver.h): hardware abstraction · `src/display/DisplayDriver.h`

### Local and remote surfaces

- [Browser UI](https://github.com/angelointj/simut/blob/main/WebUI.h): embedded client · Graphs raw history and converts it to CSV client-side. · `WebUI.h`
- [Remote consumers](https://github.com/angelointj/simut/blob/main/src/HaDiscovery.h): telemetry and syslog · HTTP/MQTT, Home Assistant, and UDP syslog targets. · `src/HaDiscovery.h`

### Other components

- [Firmware entry](https://github.com/angelointj/simut/blob/main/src/main.cpp): Arduino-Pico runtime · `src/main.cpp`

## Connections

- Firmware entry → AppManager: boots
- AppManager → SensorManager: samples
- SensorManager → Sensor channels: produces
- Sensor channels → Alarm queue: evaluates
- AppManager → StorageManager: loads and saves state
- Alarm queue → V5 history store: persists records
- StorageManager → V5 history store: LittleFS access
- AppManager → NetworkManager: starts
- NetworkManager → WebManager: connectivity
- Web authorization → WebManager: protects routes
- WebManager → Browser UI: serves UI and API
- WebManager → V5 history store: serves raw files
- AppManager → TelemetryManager: provides readings
- TelemetryManager → Remote consumers: exports
- Diagnostics logging → Remote consumers: forwards syslog
- USB CDC CLI → AppManager: commands
- WebManager → OTA orchestrator: upload transport
- OTA orchestrator → StorageManager: backup and restore
- AppManager → DisplayManager: state snapshots · Cross-core communication boundary.
- DisplayManager → TFT and touch drivers: renders and reads touch
- Flash safety checks → StorageManager: guards flash operations
- Flash safety checks → DisplayManager: pauses Core 1
