# sampli1/e-mit architecture

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

- Interactive diagram: https://gitdiagram.com/sampli1/e-mit
- Repository: https://github.com/sampli1/e-mit

## Overview

##### Main Components
- Hardware/Platform: ESP32
- Operating System & Scheduler: FreeRTOS (used for multi-threading)
- Firmware Entry Point: The “main” directory (with main.cpp and its CMake configuration)
- Communication Subsystems:
- Client Component: Manages external API communications (including OAuth2, HTTPS in C and C++ located in components/client)
- Server Component: Implements the embedded HTTP server for configuration and static asset delivery (components/server)
- & Graphics:
- Screen Component: Handles rendering and updating the e-paper display (components/screen)
- Graphics Libraries: Adafruit-GFX (components/Adafruit-GFX) and CalEPD (components/CalEPD)
- Environment & Configuration:
- Environment Variable Handler: Reads and processes .env data (components/env_var)
- SPIFFS Storage: Stores assets and certificates required for HTTPS in the “spiffs” folder
- Additional Modules:
- Peripherals: Stub/placeholder for sensor handling (modules in components/peripherals)
- Utilities: Common helper functions and wrappers (components/utils)

##### Relationships and Data Flows
- The firmware (main) initializes the ESP32 hardware while configuring FreeRTOS for multi-threaded operation.
- The Display Subsystem (screen, augmented by Adafruit-GFX and CalEPD libraries) is responsible for drawing on the E-Paper based on data received.
- The Client module makes outbound HTTPS requests to external APIs. It handles OAuth2 authentication (via modules in the client directory) and drives data retrieval (such as weather and calendar events).
- The Server module provides a configuration interface (frontend built with HTML/CSS/JavaScript) that runs on the ESP32 to modify settings and view current configurations, reading from SPIFFS for assets.
- The Env_Var component reads configuration parameters from the .env file (generated via feth.py) and passes them to the various modules.
- The Utilities module provides shared functions (e.g., JSON parsing using jsmn, non-volatile storage (NVS) utilities, Wi-Fi handling) that are used across the project.

##### Architectural Patterns and Design Principles
- Separation of Concerns: There is a clear separation between hardware interfacing (screen, peripherals), network communication (client, server), and configuration management (env_var, SPIFFS).
- Layered Architecture: At the base, you have the hardware and operating system, and then layered software components for external communication, display logic, and support utilities.
- FreeRTOS/Multi-threading: Indicate that tasks are managed concurrently, with separate threads for handling HTTP client/server, display updates, and sensor data.
- Integration with External Services: Highlight that components like the client module interact with Google Calendar API, transit API (GTT), and possibly weather services.

##### Final Recommendations for the Principal Software Engineer
- Decompose this central module into the software components outlined (client, server, screen, env_var, utils, peripherals).
- Where FreeRTOS is responsible for orchestrating concurrent threads.
- Notes (or sidebar annotations) indicating integration points such as SPIFFS use, configuration files (like .env) management, and dependency on external libraries.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["ESP32 Device"]:::hardware
    B["FreeRTOS Scheduler"]:::hardware
    C["Main Firmware"]:::firmware
    D["Env_Var Handler"]:::firmware
    E["HTTP Client"]:::comm
    F["HTTP Server"]:::comm
    G["Display Manager"]:::display
    H["Utilities"]:::utility
    I["Peripherals Module"]:::utility
    J["SPIFFS Storage"]:::utility
    K["External APIs"]:::external
    L["Configuration Frontend"]:::external
    M["Adafruit-GFX"]:::display
    N["CalEPD"]:::display

    %% Hardware and Core Firmware
    A --> B
    B --> C
    D --> C

    %% Application Modules initiated by Main Firmware
    C --> E
    C --> F
    C --> G
    C --> H
    C --> I

    %% Module Interactions
    E -->|"calls"| K
    F -->|"serves"| L
    F -->|"reads_assets"| J
    G -->|"uses"| M
    G -->|"uses"| N

    %% Click Events
    click C "https://github.com/sampli1/e-mit/blob/main/main/main.cpp"
    click E "https://github.com/sampli1/e-mit/tree/main/components/client"
    click F "https://github.com/sampli1/e-mit/tree/main/components/server"
    click G "https://github.com/sampli1/e-mit/tree/main/components/screen"
    click M "https://github.com/sampli1/e-mit/tree/main/components/Adafruit-GFX"
    click N "https://github.com/sampli1/e-mit/tree/main/components/CalEPD"
    click D "https://github.com/sampli1/e-mit/tree/main/components/env_var"
    click J "https://github.com/sampli1/e-mit/tree/main/spiffs"
    click I "https://github.com/sampli1/e-mit/tree/main/components/peripherals"
    click H "https://github.com/sampli1/e-mit/tree/main/components/utils"

    %% Styles
    classDef hardware fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef firmware fill:#A9DFBF,stroke:#145A32,stroke-width:2px;
    classDef comm fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef display fill:#F5CBA7,stroke:#943126,stroke-width:2px;
    classDef utility fill:#D7BDE2,stroke:#6C3483,stroke-width:2px;
    classDef external fill:#E8DAEF,stroke:#5B2C6F,stroke-width:2px;
```
