# finntrannn/esp32_matrixcountdownclock architecture

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

- Interactive diagram: https://gitdiagram.com/finntrannn/esp32_matrixcountdownclock
- Repository: https://github.com/finntrannn/esp32_matrixcountdownclock

## Overview

1. **Project shape and runtime**
   - This is an **ESP32 firmware** project built with **PlatformIO + Arduino C++**.
   - It targets a **64x32 HUB75 LED matrix** and uses the ESP32 as the control plane for display, networking, time sync, and sensor reading.

2. **Top-level execution model**
   - `src/main.cpp` is the bootstrapping entry point.
   - The runtime is organized around a small set of manager-style subsystems rather than a large monolith: display, network, time, sensors, and web configuration.
   - The README indicates the firmware is designed to keep the display refresh path isolated from heavier work, with **FreeRTOS-style concurrency / dual-core separation** so graphics stay smooth while networking and I/O run elsewhere.

3. **Core shared state**
   - `include/AppState.h` / `src/AppState.cpp` are the central state container.
   - This likely holds current mode, configuration, timing data, network status, sensor values, and any active screen/effect selection.
   - Other modules appear to read/write through this shared state rather than communicating directly, making `AppState` the main boundary for configuration and runtime status.

4. **Display subsystem**
   - `include/DisplayManager.h` / `src/DisplayManager.cpp` are the primary bridge to the **HUB75 matrix hardware**.
   - This layer is responsible for rendering the active screen, brightness, overlays such as Wi‑Fi indicators, borders, and any animated effects.
   - It is the most time-sensitive part of the system and is architecturally separated from network and web logic.

5. **Screen/page architecture**
   - The `include/screens` and `src/screens` directories define multiple display modes:
     - `CountdownScreen`
     - `DateTimeScreen`
     - `SensorScreen`
     - `TextScreen`
     - `RandomSpinnerScreen`
   - These are not separate apps; they are UI states that the display manager can switch between, likely under control of `AppState`.
   - This gives the firmware a **screen-based presentation layer** where each screen owns its own rendering logic and can participate in auto-cycle behavior.

6. **Visual effects**
   - `include/FireworksEffect.h` / `src/FireworksEffect.cpp` implement a dedicated animation effect.
   - The README describes scheduled fireworks, so this effect is likely triggered by time rules managed elsewhere, then rendered through the display layer.
   - This is a separate concern from the normal screens, which suggests a reusable animation overlay or full-screen effect path.

7. **Time and countdown logic**
   - `include/TimeManager.h` / `src/TimeManager.cpp` handle RTC/NTP-derived time, target time calculation, and countdown math.
   - The countdown screen and fireworks scheduling both depend on this subsystem.
   - Architecturally, this is the time authority for the system: it feeds real-world time into display modes and schedules.

8. **Sensor acquisition**
   - `include/DHTSensor.h` / `src/DHTSensor.cpp` encapsulate the **DHT11 temperature/humidity sensor**.
   - The sensor data is exposed to the display and likely stored in shared state for the sensor screen and any status widgets.
   - This module is isolated from UI logic so sensor polling can happen independently of rendering.

9. **Network and provisioning**
   - `include/NetworkManager.h` / `src/NetworkManager.cpp` manage Wi‑Fi connectivity and AP/client behavior.
   - The README shows an initial **captive portal / soft AP** provisioning flow (`THPT_QG_Config`), with subsequent joining to a home Wi‑Fi network for NTP and remote control.
   - Network status also feeds the display, since the firmware can show a Wi‑Fi icon or similar connectivity indicator.

10. **Web configuration and remote control**
    - `include/WebConfigServer.h` / `src/WebConfigServer.cpp` expose the HTTP-based configuration UI.
    - Supporting assets and strings live in `include/WebUI_Static.h` and `include/WebStrings.h`, which suggests the web app is embedded in firmware as static content rather than served from external storage.
    - This server is the main operator interface for changing settings like target countdown time, screen rotation/cycle behavior, brightness, colors, Wi‑Fi credentials, and OTA updates.

11. **Configuration boundaries**
    - `include/Config.h` is the hardware and system configuration boundary: GPIO mappings, board-specific settings, and likely feature toggles.
    - The README specifically calls out DHT11 pin assignment and HUB75 wiring compatibility with the display library’s expected pinout.
    - Persistent user settings are saved to non-volatile memory, so runtime state and user configuration are distinct.

12. **Primary data flow**
    - The typical flow is: **user configures via web UI or AP portal → settings are persisted → network/time sync and sensor polling run in background → AppState updates → DisplayManager renders the active screen/effect**.
    - Time-driven features like countdown and fireworks use the time manager; sensor-driven features use the DHT module; both converge in the screen layer for presentation.

13. **User experience modes**
    - The firmware supports several high-level modes: countdown clock, date/time display, sensor readout, scrolling text, random number spinner, splash screen, and automatic cycling between them.
    - These are all coordinated by shared state and the display manager, rather than being separate executables or services.

14. **Repo structure and operational notes**
    - `demo/` contains example images for documentation, not runtime logic.
    - `lib/` and `test/` are present but minimal, so the project is primarily organized as a **single firmware application with internal modules** rather than a library ecosystem or large test suite.
    - `.github/workflows/platformio_build.yml` indicates CI builds the firmware through PlatformIO, reinforcing that the main deployment artifact is a compiled ESP32 firmware image.

Main entry points: [`src/DisplayManager.cpp`](https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/DisplayManager.cpp) (DisplayManager), [`src/main.cpp`](https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/main.cpp) (main), [`src/WebConfigServer.cpp`](https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/WebConfigServer.cpp) (WebConfigServer), [`src/AppState.cpp`](https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/AppState.cpp) (AppState)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core firmware"]
  node_main(("main<br/>entrypoint<br/>[main.cpp]"))
  node_appstate[("AppState<br/>shared state<br/>[AppState.cpp]")]
  node_config["Config<br/>[Config.h]"]
  node_display["DisplayManager<br/>render driver<br/>[DisplayManager.cpp]"]
  node_time["TimeManager<br/>time sync<br/>[TimeManager.cpp]"]
  node_sensor["DHTSensor<br/>sensor driver<br/>[DHTSensor.cpp]"]
  node_network["NetworkManager<br/>connectivity<br/>[NetworkManager.cpp]"]
  node_fireworks{{"Fireworks<br/>effect"}}
end

subgraph group_screens["Screens"]
  node_splash["SplashScreen<br/>[SplashScreen.cpp]"]
  node_countdown["Countdown<br/>screen"]
  node_datetime["DateTime<br/>screen<br/>[DateTimeScreen.cpp]"]
  node_sensorscreen["Sensor<br/>screen<br/>[SensorScreen.cpp]"]
  node_textscreen["Text<br/>screen<br/>[TextScreen.cpp]"]
  node_spinner["Spinner<br/>screen"]
end

subgraph group_ui["Config UI"]
  node_web["WebConfigServer<br/>http config"]
  node_webstatic["Web UI<br/>embedded assets<br/>[WebUI_Static.h]"]
  node_webstrings["Strings<br/>ui text<br/>[WebStrings.h]"]
end

node_main -->|"loads"| node_config
node_main -->|"initializes"| node_appstate
node_main -->|"starts"| node_display
node_main -->|"starts"| node_network
node_main -->|"starts"| node_time
node_main -->|"starts"| node_sensor
node_main -->|"starts"| node_web
node_network -->|"hosts"| node_web
node_web -->|"serves"| node_webstatic
node_web -->|"labels"| node_webstrings
node_web -->|"updates"| node_appstate
node_time -->|"publishes"| node_appstate
node_sensor -->|"publishes"| node_appstate
node_display -->|"reads"| node_appstate
node_display -->|"renders"| node_splash
node_display -->|"renders"| node_countdown
node_display -->|"renders"| node_datetime
node_display -->|"renders"| node_sensorscreen
node_display -->|"renders"| node_textscreen
node_display -->|"renders"| node_spinner
node_display -->|"animates"| node_fireworks
node_time -->|"drives"| node_countdown
node_time -->|"triggers"| node_fireworks
node_sensor -->|"feeds"| node_sensorscreen

click node_main "https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/main.cpp"
click node_appstate "https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/AppState.cpp"
click node_config "https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/include/Config.h"
click node_display "https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/DisplayManager.cpp"
click node_time "https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/TimeManager.cpp"
click node_sensor "https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/DHTSensor.cpp"
click node_network "https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/NetworkManager.cpp"
click node_web "https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/WebConfigServer.cpp"
click node_webstatic "https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/include/WebUI_Static.h"
click node_webstrings "https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/include/WebStrings.h"
click node_splash "https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/SplashScreen.cpp"
click node_countdown "https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/screens/CountdownScreen.cpp"
click node_datetime "https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/screens/DateTimeScreen.cpp"
click node_sensorscreen "https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/screens/SensorScreen.cpp"
click node_textscreen "https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/screens/TextScreen.cpp"
click node_spinner "https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/screens/RandomSpinnerScreen.cpp"
click node_fireworks "https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/FireworksEffect.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_main,node_appstate,node_config,node_display,node_time,node_sensor,node_network,node_fireworks toneBlue
class node_splash,node_countdown,node_datetime,node_sensorscreen,node_textscreen,node_spinner toneAmber
class node_web,node_webstatic,node_webstrings toneMint
```

## Components

### Core firmware

Boot, shared state, hardware control, and system services

- [main](https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/main.cpp): entrypoint · Firmware bootstrap and runtime wiring · `src/main.cpp`
- [AppState](https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/AppState.cpp): shared state · Central runtime/configuration state · `src/AppState.cpp`
- [Config](https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/include/Config.h): hw config · Board pins, feature flags, and system constants · `include/Config.h`
- [DisplayManager](https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/DisplayManager.cpp): render driver · HUB75 matrix rendering and display coordination · `src/DisplayManager.cpp`
- [TimeManager](https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/TimeManager.cpp): time sync · RTC/NTP time authority and countdown math · `src/TimeManager.cpp`
- [DHTSensor](https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/DHTSensor.cpp): sensor driver · Temperature and humidity acquisition · `src/DHTSensor.cpp`
- [NetworkManager](https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/NetworkManager.cpp): connectivity · Wi-Fi AP/client setup and connection state · `src/NetworkManager.cpp`
- [Fireworks](https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/FireworksEffect.cpp): effect · Scheduled animation effect for celebrations · `src/FireworksEffect.cpp`

### Screens

Presentation modes rendered on the LED matrix

- [SplashScreen](https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/SplashScreen.cpp): screen · Startup display shown during boot · `src/SplashScreen.cpp`
- [Countdown](https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/screens/CountdownScreen.cpp): screen · Target-time countdown presentation · `src/screens/CountdownScreen.cpp`
- [DateTime](https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/screens/DateTimeScreen.cpp): screen · Current date and time display · `src/screens/DateTimeScreen.cpp`
- [Sensor](https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/screens/SensorScreen.cpp): screen · Temperature and humidity readout · `src/screens/SensorScreen.cpp`
- [Text](https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/screens/TextScreen.cpp): screen · Scrolling or fixed text display · `src/screens/TextScreen.cpp`
- [Spinner](https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/screens/RandomSpinnerScreen.cpp): screen · Random number spinner display · `src/screens/RandomSpinnerScreen.cpp`

### Config UI

Embedded web configuration and static UI assets

- [WebConfigServer](https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/src/WebConfigServer.cpp): http config · Embedded configuration and remote control server · `src/WebConfigServer.cpp`
- [Web UI](https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/include/WebUI_Static.h): embedded assets · Static HTML/CSS/JS served by the config server · `include/WebUI_Static.h`
- [Strings](https://github.com/finntrannn/esp32_matrixcountdownclock/blob/main/include/WebStrings.h): ui text · Labels and messages for the web interface · `include/WebStrings.h`

## Connections

- main → Config: loads · Reads hardware and build-time settings
- main → AppState: initializes · Creates shared runtime state
- main → DisplayManager: starts · Brings up matrix rendering
- main → NetworkManager: starts · Begins Wi-Fi/provisioning flow
- main → TimeManager: starts · Enables time synchronization
- main → DHTSensor: starts · Begins sensor polling
- main → WebConfigServer: starts · Launches configuration server
- NetworkManager → WebConfigServer: hosts · Provides network access for config UI
- WebConfigServer → Web UI: serves · Embedded web application assets
- WebConfigServer → Strings: labels · Uses UI text and messages
- WebConfigServer → AppState: updates · Writes user settings into shared state
- TimeManager → AppState: publishes · Stores current time and countdown status
- DHTSensor → AppState: publishes · Stores latest temperature and humidity
- DisplayManager → AppState: reads · Consumes current mode and status
- DisplayManager → SplashScreen: renders · Shows startup splash when booting
- DisplayManager → Countdown: renders · Delegates countdown view
- DisplayManager → DateTime: renders · Delegates clock/date view
- DisplayManager → Sensor: renders · Delegates sensor view
- DisplayManager → Text: renders · Delegates text view
- DisplayManager → Spinner: renders · Delegates spinner view
- DisplayManager → Fireworks: animates · Plays celebration effect on matrix
- TimeManager → Countdown: drives · Supplies countdown timing and target math
- TimeManager → Fireworks: triggers · Schedules fireworks at configured times
- DHTSensor → Sensor: feeds · Provides temperature/humidity values
