# abmt-community/esp32_nodes architecture

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

- Interactive diagram: https://gitdiagram.com/abmt-community/esp32_nodes
- Repository: https://github.com/abmt-community/esp32_nodes

## Overview

##### Project Components
- Configuration Files: Files with the “.acfg” extension (e.g., blinky.acfg, echo.acfg, http_cmd.acfg, etc.) configure which node setups or behaviors to load.
- Models: Under the “models” directory, the “.amdl” files define the node models. These files dictate the behavior or parameters for nodes like blink, echo, HTTP commands, MQTT, and others.
- Nodes: The “nodes” directory contains C++ implementation files (.cpp and .h) responsible for low-level hardware operations (GPIO, I2C, SPI, TCP/UDP communications, etc.). These nodes encapsulate the hardware interaction logic.
- Views & HTML: The “views” directory (with files like led.aview) and the “html” directory (holding files like index.html and cmd.html) provide interface elements or client-side components, notably for interacting with the HTTP-related demos.

##### Diagramming the Architecture
a. Main Components:
- ESP32 Hardware: Centerpiece of the design, running the configuration-based runtime.
- Runtime Environment: The ESP32 Runtime (rt_esp32) executing the node configurations.
- Configuration Layer:
- Configuration Files (.acfg) – define the enabled nodes and their parameters.
- Model Files (.amdl) – provide the definitions or “schemas” for nodes’ behaviors.
- View Files (.aview) – custom visualizations or UI components.
- Nodes Layer:
- Hardware Node Implementations – the C++ files implementing hardware interactions (e.g., GPIO, PWM, ADC, UART, TCP/UDP, etc.).
- Communication Interfaces:
- HTTP Interface: Managed via nodes like esp_http.cpp/h; linked with the html directory (cmd.html, index.html) for REST commands.
- Network Interfaces: TCP, UDP, and MQTT nodes facilitate external communications.

b. Relationships and Data Flow:
- The ESP32 Runtime parses the configuration (.acfg) files and loads the related model definitions (.amdl). This dynamic configuration directs which nodes to instantiate and how they should operate.
- Each node (for example, the “blinky” node for blinking an LED, or the “echo” node for processing UDP/TCP requests) handles specific hardware interactions, with their implementation detailed in the “nodes” folder.
- The HTTP nodes, in association with the html and view components, provide a user interface (web-based) for interacting with the system (e.g., the REST-command example using http_cmd/acfg).

c. Architectural Patterns:
- Modularity: Clearly delineation between configuration, business logic (nodes), and presentation (views/html).
- Layered Architecture:
- Top layer: User interfaces and network communication (HTTP, TCP/UDP).
- Middle layer: The runtime core and node instantiation based on configurations.
- Bottom layer: Low-level hardware controllers (GPIO, I2C, SPI, etc.) implemented in C++.
- Use of declarative configuration (via .acfg and .amdl files) allows for flexible customization of node behavior.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% ESP32 Hardware and Runtime Environment
    subgraph "ESP32 Hardware"
        RT("Runtime Environment (rt_esp32)"):::hardware
    end

    %% Configuration Layer: ACFGs, Models, and Views
    subgraph "Configuration Layer"
        subgraph "ACFG Files"
            BC("Blinky Config"):::config
            EC("Echo Config"):::config
            HCC("HTTP_CMD Config"):::config
            HLC("HTTP_LED Config"):::config
            MC("MQTT Config"):::config
            TC("Test Config"):::config
        end
        subgraph "Model Files"
            BM("Blink Model"):::config
            EM("Echo Model"):::config
            HCM("HTTP_CMD Model"):::config
            HLM("HTTP_LED Model"):::config
            MM("MQTT Model"):::config
        end
        subgraph "View & HTML Files"
            LED("LED View"):::view
            HTMLI("HTML Interface (Index)"):::view
            HTMLC("HTML Interface (Cmd)"):::view
        end
    end

    %% Nodes Layer: Hardware Interaction Implementations
    subgraph "Nodes Layer"
        GPIO("GPIO Node"):::nodes
        PWM("PWM Node"):::nodes
        I2C("I2C Node"):::nodes
        SPI("SPI Node"):::nodes
        UART("UART Node"):::nodes
        TCP("TCP Node"):::nodes
        UDP("UDP Node"):::nodes
        DAC("DAC Node"):::nodes
        SYS("System Control Node"):::nodes
        HTTP("HTTP Communication Node"):::nodes
        TEMP("Temperature Sensor Node"):::nodes
        MQTTN("MQTT Node"):::nodes
    end

    %% External Communication Interfaces
    subgraph "External Communication"
        EXT_HTTP("HTTP Interface"):::external
        EXT_MQTT("MQTT Broker"):::external
        EXT_NET("Network (TCP/UDP)"):::external
    end

    %% Connections: Data Flow and Dependencies
    %% Configuration Layer feeds into the Runtime Environment
    BC --- RT
    EC --- RT
    HCC --- RT
    HLC --- RT
    MC --- RT
    TC --- RT
    BM --- RT
    EM --- RT
    HCM --- RT
    HLM --- RT
    MM --- RT
    LED --- RT
    HTMLI --- RT
    HTMLC --- RT

    %% Runtime Environment activates the Nodes Layer
    RT --> GPIO
    RT --> PWM
    RT --> I2C
    RT --> SPI
    RT --> UART
    RT --> TCP
    RT --> UDP
    RT --> DAC
    RT --> SYS
    RT --> HTTP
    RT --> TEMP
    RT --> MQTTN

    %% Nodes communicate with External Interfaces
    HTTP --> EXT_HTTP
    MQTTN --> EXT_MQTT
    TCP --> EXT_NET
    UDP --> EXT_NET

    %% HTML Interfaces interact directly with the HTTP Node
    HTMLI --- HTTP
    HTMLC --- HTTP

    %% Styles
    classDef hardware fill:#AED6F1,stroke:#3498DB,stroke-width:2px;
    classDef config fill:#FCF3CF,stroke:#F1C40F,stroke-width:2px;
    classDef nodes fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
    classDef view fill:#F9E79F,stroke:#F39C12,stroke-width:2px;
    classDef external fill:#FADBD8,stroke:#E74C3C,stroke-width:2px;

    %% Click Events for Configuration Files
    click BC "https://github.com/abmt-community/esp32_nodes/blob/master//blinky.acfg"
    click EC "https://github.com/abmt-community/esp32_nodes/blob/master//echo.acfg"
    click HCC "https://github.com/abmt-community/esp32_nodes/blob/master//http_cmd.acfg"
    click HLC "https://github.com/abmt-community/esp32_nodes/blob/master//http_led.acfg"
    click MC "https://github.com/abmt-community/esp32_nodes/blob/master//mqtt.acfg"
    click TC "https://github.com/abmt-community/esp32_nodes/blob/master//test.acfg"

    %% Click Events for Model Files
    click BM "https://github.com/abmt-community/esp32_nodes/blob/master//models/blink.amdl"
    click EM "https://github.com/abmt-community/esp32_nodes/blob/master//models/echo.amdl"
    click HCM "https://github.com/abmt-community/esp32_nodes/blob/master//models/http_cmd.amdl"
    click HLM "https://github.com/abmt-community/esp32_nodes/blob/master//models/http_led.amdl"
    click MM "https://github.com/abmt-community/esp32_nodes/blob/master//models/mqtt.amdl"

    %% Click Events for Node Implementations
    click GPIO "https://github.com/abmt-community/esp32_nodes/blob/master//nodes/gpio.cpp"
    click GPIO "https://github.com/abmt-community/esp32_nodes/blob/master//nodes/gpio.h"
    click PWM "https://github.com/abmt-community/esp32_nodes/blob/master//nodes/pwm.cpp"
    click PWM "https://github.com/abmt-community/esp32_nodes/blob/master//nodes/pwm.h"
    click I2C "https://github.com/abmt-community/esp32_nodes/blob/master//nodes/i2c.cpp"
    click I2C "https://github.com/abmt-community/esp32_nodes/blob/master//nodes/i2c.h"
    click SPI "https://github.com/abmt-community/esp32_nodes/blob/master//nodes/spi.cpp"
    click SPI "https://github.com/abmt-community/esp32_nodes/blob/master//nodes/spi.h"
    click UART "https://github.com/abmt-community/esp32_nodes/blob/master//nodes/uart.cpp"
    click UART "https://github.com/abmt-community/esp32_nodes/blob/master//nodes/uart.h"
    click TCP "https://github.com/abmt-community/esp32_nodes/blob/master//nodes/tcp.cpp"
    click TCP "https://github.com/abmt-community/esp32_nodes/blob/master//nodes/tcp.h"
    click UDP "https://github.com/abmt-community/esp32_nodes/blob/master//nodes/udp.cpp"
    click UDP "https://github.com/abmt-community/esp32_nodes/blob/master//nodes/udp.h"
    click DAC "https://github.com/abmt-community/esp32_nodes/blob/master//nodes/dac.cpp"
    click DAC "https://github.com/abmt-community/esp32_nodes/blob/master//nodes/dac.h"
    click SYS "https://github.com/abmt-community/esp32_nodes/blob/master//nodes/sys.cpp"
    click SYS "https://github.com/abmt-community/esp32_nodes/blob/master//nodes/sys.h"
    click HTTP "https://github.com/abmt-community/esp32_nodes/blob/master//nodes/esp_http.cpp"
    click HTTP "https://github.com/abmt-community/esp32_nodes/blob/master//nodes/esp_http.h"
    click TEMP "https://github.com/abmt-community/esp32_nodes/blob/master//nodes/esp_temp_sensor.cpp"
    click TEMP "https://github.com/abmt-community/esp32_nodes/blob/master//nodes/esp_temp_sensor.h"
    click MQTTN "https://github.com/abmt-community/esp32_nodes/blob/master//nodes/mqtt.cpp"
    click MQTTN "https://github.com/abmt-community/esp32_nodes/blob/master//nodes/mqtt.h"

    %% Click Events for Views & HTML Files
    click LED "https://github.com/abmt-community/esp32_nodes/blob/master//views/led.aview"
    click HTMLI "https://github.com/abmt-community/esp32_nodes/blob/master//html/index.html"
    click HTMLC "https://github.com/abmt-community/esp32_nodes/blob/master//html/cmd.html"
```
