# erwin-schrodinger-token/ewn-box-opener-espressif architecture

> Architecture diagram of the GitHub repository erwin-schrodinger-token/ewn-box-opener-espressif, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/erwin-schrodinger-token/ewn-box-opener-espressif
- Repository: https://github.com/erwin-schrodinger-token/ewn-box-opener-espressif

## Overview

##### Project Type and Purpose
- The README details how to flash the firmware, connect via Wi-Fi, and configure the device. The project also supports board integration through community collaboration.

##### File Structure
- Top-level Directories:
- "src": Contains the core C++ firmware code (e.g., main.cpp, display, led, rgbled, websocket modules, param handling).
- "data": Contains web assets (HTML, CSS, JS, images) that power the captive portal and static configuration pages.
- "include" and "lib": Provide headers and perhaps additional libraries (check README in these folders for more details).
- ".github": Contains CI/CD workflows (build, SonarQube for code quality) indicating integration with automated testing and build systems.
- "test": Contains testing-related materials.
- Key patterns indicate a modular separation where each hardware function (display, LED, button) and network-related code (websocket) is encapsulated in its own module.

##### Important Architectural Details to Capture
a. Main Firmware Module:
- Central control running on the ESP board (refer to src/main.cpp).
- This module orchestrates the passing of control to the different submodules.
b. Hardware Interface Components:
- Button, LED, RGB LED modules (src/button.h, src/led.*, src/rgbled.*) that directly control the physical hardware.
- Control related modules (display.cpp, display.h, s3-display.h) that manage output.
- Parameter handling (param.cpp and param.h) for configuration data.
c. Network and Web Server Module:
- The captive portal functionality is enabled by the firmware hosting a web server serving static files from the "data" folder (HTML, CSS, JS files such as index.html, style.css, stats.js, etc.).
- The websocket communication (src/websocket.cpp, websockets.h) is used to enable real-time data exchange between the device and the client (for status updates or command/control).
d. Build and Integration Tools:
- PlatformIO (platformio.ini) is used for building, flashing, and board integration.
- CI workflows in .github (for building and code analysis through SonarQube) should be noted, though they are more for development than runtime architecture.

##### Relationships and Interactions
- The firmware (Main Control Unit) initiates and manages hardware interaction by invoking modules for LED, RGB LED, display, and button handling.
- When the device boots, it starts a web server that serves static content from the "data" directory, creating a captive portal.
- The user interacts with the captive portal through their browser, and this contact can trigger changes in configuration (handled by the param module) while the websocket module may push real-time updates.
- There is a clear data flow between user input via HTTP/websocket routes and the actual hardware control.
- The CI/CD processes (workflows in .github) support testing and quality assurance, ensuring that changes across modules are reliably integrated.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Firmware Core
    F["ESP Firmware (Main Controller)"]:::firmware

    %% Hardware Modules
    subgraph "Hardware Modules"
        B["Button Hardware Module"]:::hardware
        L["LED Hardware Module"]:::hardware
        R["RGB LED Module"]:::hardware
        D["Display Module"]:::hardware
        P["Parameter Handling Module"]:::hardware
    end

    %% Network Modules
    subgraph "Network Modules"
        CP["Captive Portal"]:::network
        WS["Websocket Communication Module"]:::network
    end

    %% Build & Integration Tools
    subgraph "Build & Integration Tools"
        PI["PlatformIO (platformio.ini)"]:::build
        CI["CI/CD Workflows (.github/workflows)"]:::build
    end

    %% External User
    U["User/Client"]:::external

    %% Connections from Firmware to Hardware Modules
    F -->|"controls"| B
    F -->|"controls"| L
    F -->|"controls"| R
    F -->|"controls"| D
    F -->|"controls"| P

    %% Connections from Firmware to Network Modules
    F -->|"serves"| CP
    F -->|"communicates_with"| WS

    %% User Interaction 
    CP -->|"serves_to"| U
    U -->|"sends_config"| P

    %% Websocket feedback to Firmware
    WS -->|"updates_status"| F

    %% Build & Integration relationships (dotted lines)
    CI -.->|"integrates"| F
    PI -.->|"builds"| F

    %% Click Events
    click F "https://github.com/erwin-schrodinger-token/ewn-box-opener-espressif/blob/main/src/main.cpp"
    click B "https://github.com/erwin-schrodinger-token/ewn-box-opener-espressif/blob/main/src/button.h"
    click L "https://github.com/erwin-schrodinger-token/ewn-box-opener-espressif/blob/main/src/led.cpp"
    click L "https://github.com/erwin-schrodinger-token/ewn-box-opener-espressif/blob/main/src/led.h"
    click R "https://github.com/erwin-schrodinger-token/ewn-box-opener-espressif/blob/main/src/rgbled.cpp"
    click R "https://github.com/erwin-schrodinger-token/ewn-box-opener-espressif/blob/main/src/rgbled.h"
    click D "https://github.com/erwin-schrodinger-token/ewn-box-opener-espressif/blob/main/src/display.cpp"
    click D "https://github.com/erwin-schrodinger-token/ewn-box-opener-espressif/blob/main/src/display.h"
    click D "https://github.com/erwin-schrodinger-token/ewn-box-opener-espressif/blob/main/src/s3-display.h"
    click P "https://github.com/erwin-schrodinger-token/ewn-box-opener-espressif/blob/main/src/param.cpp"
    click P "https://github.com/erwin-schrodinger-token/ewn-box-opener-espressif/blob/main/src/param.h"
    click CP "https://github.com/erwin-schrodinger-token/ewn-box-opener-espressif/tree/main/data"
    click WS "https://github.com/erwin-schrodinger-token/ewn-box-opener-espressif/blob/main/src/websocket.cpp"
    click WS "https://github.com/erwin-schrodinger-token/ewn-box-opener-espressif/blob/main/src/websockets.h"
    click PI "https://github.com/erwin-schrodinger-token/ewn-box-opener-espressif/blob/main/platformio.ini"
    click CI "https://github.com/erwin-schrodinger-token/ewn-box-opener-espressif/tree/main/.github/workflows"

    %% Styles
    classDef firmware fill:#cce5ff,stroke:#003366,stroke-width:2px;
    classDef hardware fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef network fill:#ffeeba,stroke:#856404,stroke-width:2px;
    classDef build fill:#d1c4e9,stroke:#5e35b1,stroke-width:2px;
    classDef external fill:#f8d7da,stroke:#721c24,stroke-width:2px;
```
