# matth-x/microocpp architecture

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

- Interactive diagram: https://gitdiagram.com/matth-x/microocpp
- Repository: https://github.com/matth-x/microocpp

## Overview

##### Main Components
- Library Core: The “src” directory contains the core of MicroOcpp. This is where all the modules such as Configuration management, Connection handling, Context, Models, and Operations reside.
- Operation Modules: Under “src/MicroOcpp/Operations” you have the individual OCPP operations (Authorize, BootNotification, RemoteStartTransaction, etc.). Each operation is encapsulated as its own file.
- Model & Services: The “src/MicroOcpp/Model” folder implements various services and functionalities (Authorization, Boot, Availability, Diagnostics, Metering, SmartCharging, Certificates, etc.) that represent the business logic of a charging station.
- Dependencies & Adapters: There are adapters like FilesystemAdapter and MbedTLS integration for certificate management. External dependencies include ArduinoJSON, arduinoWebSockets and optionally Mbed-TLS.
- Hardware & Platform Layer: There is a “Platform.cpp/h” indicating that the library abstracts hardware or system-dependent operations.
- Test Suite: The “tests” directory contains unit tests, benchmarks, and integration tests. This indicates strong test coverage and separation of test code.
- Demo/Example Projects: The “examples” folder shows multiple demo integrations (e.g., for ESP-IDF, ESP, and ESP-TLS) which serve as usage references.

##### Relationships and Interactions
- Data Flow: Start with external events coming from the microcontroller’s hardware (for instance, an RFID read or a charging session event). These events are processed by the Core (e.g., MicroOcpp.cpp) and then routed to the appropriate Operation (e.g., Authorize, BootNotification) based on configuration.
- Configuration Management: The Configuration Container and related modules manage settings and persist them (e.g., flash storage or a file system) before they are used to adjust behavior at runtime.
- Communication: The Connection module is responsible for establishing and maintaining a WebSocket or similar connection with the OCPP backend, sending/receiving messages.
- Cryptography/Certificates: If enabled (using MbedTLS), certificate management verifies the security handshake and manages credentials.
- The operations make calls to the model layer services which encapsulate business logic specific to charging station functionality.
- CI/CD and Documentation: The ".github/workflows" along with documentation directories show supporting infrastructure for testing, continuous integration, and user documentation. While not part of the runtime architecture, they reflect the overall development and deployment lifecycle.

##### Architectural Patterns and Important Principles
- Modular Design: By separating operations, models, and core utilities into their own subdirectories, the project follows a modular approach.
- Hardware Abstraction Layer: The use of platform-specific adapters (e.g., for filesystem or communication) suggests that the library is designed to keep hardware dependencies nicely isolated.
- Extensibility: The clear separation between core functionality, operations, and models allows integrators to extend or customize behavior.
- Interdependency Management: The CMakeLists, SConscript, and various build configuration files illustrate how cross-platform compilation and dependency integration are managed.

##### Relevant Technologies and Frameworks
- C/C++ language for the embedded environment.
- Build Systems: CMake, SCons, and PlatformIO are used based on configuration files (platformio.ini, CMakeLists.txt).
- External Libraries: ArduinoJSON for JSON parsing, ArduinoWebSockets for communication, and optionally MbedTLS for secure communications.
- GitHub Workflows: Various CI workflows (documented in .github/workflows) are part of the overall ecosystem to ensure code quality.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External and Hardware Layer
    HE("Hardware Event"):::external
    HP("Hardware Abstraction Layer"):::adapter

    %% Core Library Components
    subgraph "Core Library Components"
        LC("Library Core"):::core
        OM("Operation Modules"):::operation
        MS("Model & Services"):::model
    end

    %% Dependencies & Adapters
    subgraph "Dependencies & Adapters"
        FSA("Filesystem Adapter"):::adapter
        CS("Certificate Service"):::adapter
    end

    %% External Communication
    OCPP("OCPP Backend Server"):::external

    %% Quality Assurance and Demo
    subgraph "Quality & Demo"
        TS("Test Suite"):::test
        DEMO("Demo/Example Projects"):::demo
    end

    %% Data Flow Connections
    HE -->|"triggers"| LC
    HP -->|"provides hardware abstraction"| LC
    LC -->|"dispatches operations"| OM
    OM -->|"invokes business logic"| MS
    LC -->|"establishes connection"| OCPP
    MS -->|"handles certificates"| CS
    LC ---|"uses"| FSA
    TS ---|"tests"| LC
    DEMO ---|"demonstrates"| LC

    %% Click Events
    click LC "https://github.com/matth-x/microocpp/tree/main/src/MicroOcpp/Core"
    click OM "https://github.com/matth-x/microocpp/tree/main/src/MicroOcpp/Operations"
    click MS "https://github.com/matth-x/microocpp/tree/main/src/MicroOcpp/Model"
    click FSA "https://github.com/matth-x/microocpp/blob/main/src/MicroOcpp/Core/FilesystemAdapter.cpp"
    click CS "https://github.com/matth-x/microocpp/blob/main/src/MicroOcpp/Model/Certificates/CertificateMbedTLS.cpp"
    click HP "https://github.com/matth-x/microocpp/blob/main/src/MicroOcpp/Platform.cpp"
    click TS "https://github.com/matth-x/microocpp/tree/main/tests"
    click DEMO "https://github.com/matth-x/microocpp/tree/main/examples"

    %% Styles
    classDef core fill:#f9e79f,stroke:#d35400,stroke-width:2px;
    classDef operation fill:#aed6f1,stroke:#2471a3,stroke-width:2px;
    classDef model fill:#abebc6,stroke:#1e8449,stroke-width:2px;
    classDef adapter fill:#f7dc6f,stroke:#b7950b,stroke-width:2px;
    classDef external fill:#f5b7b1,stroke:#943126,stroke-width:2px;
    classDef test fill:#d2b4de,stroke:#6c3483,stroke-width:2px;
    classDef demo fill:#f9c6c9,stroke:#922b21,stroke-width:2px;
```
