# nhi-e/ce232 architecture

> Architecture diagram of the GitHub repository nhi-e/ce232, 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/nhi-e/ce232
- Repository: https://github.com/nhi-e/ce232

## Overview

##### Sensor/Edge Nodes
- Represented by directories like LAB5-MINIPROJECT/main, SENSOR/main, and PROJECT/NOD1/main which contain the embedded C code (e.g., app_main.c, dht11.c, font.h, SSD1306.h).
- These modules deal with reading sensor data, possibly displaying information, and handling local components.
- That some nodes (e.g., under PROJECT/NODE2/Led_Door) include additional hardware integrations such as LED control, servo, BLE GATTS server, and WiFi – indicating actuators and complementary connectivity options.
- Nodes with labels like “Sensor Node – ESP Firmware” or “Door/LED Control Node” and list key peripherals (DHT11 sensor, OLED display, LED, servo, WiFi/BLE).

##### Backend Server
- The Node.js server (as seen in the mongodb folder – server.js and related files) acts as the central processing unit that receives messages from the MQTT broker and probably orchestrates the interaction with the database.
- This as a “Node.js Server” block which is connected to both the MQTT Broker and the database.

##### Database
- MongoDB is used for data persistence (with project directories in mongodb holding package.json, event.js, etc.).
- A “MongoDB Database” component that is linked to the Node.js Server, implying data storage and retrieval of sensor information and control logs.

##### Web Frontend
- The web directories under LAB5-MINIPROJECT/web, PROJECT/web, and sensor-grade directories contain HTML, CSS, and JavaScript files that likely provide a user interface for logging in and interacting with the system.

##### Testing/Integration
- Files like pytest_mqtt_ssl.py indicate that there is testing functionality for secure MQTT connections. Although not an architectural component per se, you might note testing as part of the deployment/verification process (possibly annotated).

- Use clear labels for every component. For example, label blocks “ESP Sensor Node,” “Door/LED Control Node,” “MQTT Broker (HiveMQ),” “Node.js Server,” “MongoDB Database,” and “Web Interface.”
- Optionally, include additional annotations about the protocols (MQTT publish/subscribe), the development frameworks (ESP-IDF for embedded devices), and tech stacks (Node.js and MongoDB on the backend, standard web technologies on the frontend).
- Modular design evident in the file tree by indicating sub-components or nodes (for instance, NODE1 vs. NODE2, with NODE2 showing extra components like BLE, LED, servo, etc.) as specialized sensor/actuator nodes.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Sensor/Edge Nodes
    subgraph "Sensor/Edge Nodes"
        SN1["ESP Sensor Node<br>(LAB5-MINIPROJECT/main)"]:::sensor
        SN2["ESP Sensor Node<br>(SENSOR/main)"]:::sensor
        SN3["ESP Sensor Node<br>(PROJECT/NOD1/main)"]:::sensor
    end

    %% Door/LED Control Node and its Hardware Modules
    subgraph "Door/LED Control Node"
        DN["Door/LED Control Node<br>(PROJECT/NODE2/Led_Door/main)"]:::door
        LED["LED Module"]:::door
        SERVO["Servo Module"]:::door
        BLE["BLE GATTS Module"]:::door
        WIFI["WiFi Module"]:::door
        HC595["74hc595 Driver"]:::door
    end

    %% MQTT Broker
    MQTTC["MQTT Broker (HiveMQ)"]:::broker

    %% Backend Services
    subgraph "Backend Services"
        BS["Node.js Server"]:::backend
        DB["MongoDB Database"]:::database
    end

    %% Web Frontend
    WF["Web Interface"]:::frontend

    %% Testing/Integration
    TEST["MQTT SSL Testing"]:::testing

    %% Connections from Sensor Nodes to MQTT Broker
    SN1 -->|"publishes"| MQTTC
    SN2 -->|"publishes"| MQTTC
    SN3 -->|"publishes"| MQTTC

    %% Connection from Door/LED Control Node to MQTT Broker
    DN -->|"publishes"| MQTTC

    %% Internal connections within Door/LED Control Node
    DN --> LED
    DN --> SERVO
    DN --> BLE
    DN --> WIFI
    DN --> HC595

    %% Communication from MQTT Broker to Backend Server
    MQTTC -->|"forwards"| BS

    %% Read/Write between Node.js Server and MongoDB Database
    BS <-->|"read/write"| DB

    %% API interactions between Node.js Server and Web Interface
    BS -->|"APIcalls"| WF

    %% Testing connection to MQTT Broker
    TEST -->|"tests"| MQTTC

    %% Click Events for Sensor Node directories
    click SN1 "https://github.com/nhi-e/ce232/tree/main/LAB5-MINIPROJECT/main"
    click SN2 "https://github.com/nhi-e/ce232/tree/main/SENSOR/main"
    click SN3 "https://github.com/nhi-e/ce232/tree/main/PROJECT/NOD1/main"

    %% Click Events for Door/LED Control Node and its modules
    click DN "https://github.com/nhi-e/ce232/tree/main/PROJECT/NODE2/Led_Door/main"
    click LED "https://github.com/nhi-e/ce232/tree/main/PROJECT/NODE2/Led_Door/components/LED"
    click SERVO "https://github.com/nhi-e/ce232/tree/main/PROJECT/NODE2/Led_Door/components/servo"
    click BLE "https://github.com/nhi-e/ce232/tree/main/PROJECT/NODE2/Led_Door/components/BLE_GATTS_SERVER"
    click WIFI "https://github.com/nhi-e/ce232/tree/main/PROJECT/NODE2/Led_Door/components/WIFI"
    click HC595 "https://github.com/nhi-e/ce232/tree/main/PROJECT/NODE2/Led_Door/components/74hc595"

    %% Click Events for Backend Server and Database
    click BS "https://github.com/nhi-e/ce232/tree/main/LAB5-MINIPROJECT/mongodb"
    click DB "https://github.com/nhi-e/ce232/tree/main/LAB5-MINIPROJECT/mongodb"

    %% Click Events for Web Frontend
    click WF "https://github.com/nhi-e/ce232/tree/main/LAB5-MINIPROJECT/web"

    %% Click Event for Testing Script
    click TEST "https://github.com/nhi-e/ce232/blob/main/LAB5-MINIPROJECT/pytest_mqtt_ssl.py"

    %% Styles
    classDef sensor fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef door fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef broker fill:#D7BDE2,stroke:#6C3483,stroke-width:2px;
    classDef backend fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef database fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef frontend fill:#FAD7A0,stroke:#AF601A,stroke-width:2px;
    classDef testing fill:#D5DBDB,stroke:#808B96,stroke-width:2px;
```
