# noobyco/ledx architecture

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

- Interactive diagram: https://gitdiagram.com/noobyco/ledx
- Repository: https://github.com/noobyco/ledx

## Overview

##### Main Components
- Browser Client: Representing the web application’s user interface (found in the public/ directory with index.html, main.html, and CSS assets).
- Node.js Server (Express.js): The core of the web application (app.js and package.json indicate the use of Node/Express). This handles user commands from the browser.
- MQTT Broker: A public MQTT broker (mqtt://broker.hivemq.com, as noted in the README) that serves as the message exchange intermediary.
- Raspberry Pi with Hardware Control: The hardware side managed by the Python script (Pi/led.py) that subscribes to MQTT topics and controls the LED.

##### Detail the Relationships and Data Flow
- The Browser Client sends HTTP requests to the Node.js server (for commands like turning the LED on/off).
- The Node.js server processes these commands and publishes corresponding messages on MQTT topics to the public broker.
- The Raspberry Pi, running the led.py script, subscribes to the relevant MQTT topic. When it receives a command (e.g., “on” or “off”), it triggers the LED hardware accordingly.
- Optionally, there could be feedback channels or status updates that, if implemented, would flow in reverse – from LED/Pi to the server, then to the client.

##### Architectural Patterns and Design Principles
- Microcontroller-based IoT design: Separating concerns between a web-based control interface and a physical device.
- Decoupling via Messaging: The MQTT broker decouples the Node.js application from the Raspberry Pi’s LED controller, promoting scalability and reliability.
- Separation of Frontend and Backend: The clear organization of static files under the public directory and backend logic in app.js indicate an MVC-like separation (even if informal).

##### Relevant Technologies and Frameworks
- Frontend: HTML, CSS (under public/), and potentially JavaScript driven by the Node.js server.
- Backend: Node.js and Express.js (as seen in package.json and app.js).
- Communication: MQTT protocol for messaging between the server and the Raspberry Pi.
- Hardware: Python3 script (Pi/led.py) interfacing with the LED (likely using a library such as RPi.GPIO or similar).

## Diagram (Mermaid)

```mermaid
graph TD
  %% Browser Client Subgraph
  subgraph "Browser Client"
    indexHTML["index.html"]:::client
    mainHTML["main.html"]:::client
    cssAssets["CSS Assets"]:::client
    BrowserUI["Browser UI"]:::client
    indexHTML --> BrowserUI
    mainHTML --> BrowserUI
    cssAssets --> BrowserUI
  end

  %% Node.js Server Subgraph
  subgraph "Node.js Server"
    appJS["app.js"]:::server
    packageJSON["package.json"]:::server
    NodeServer["Node.js/Express Server"]:::server
    appJS --> NodeServer
    packageJSON --> NodeServer
  end

  %% MQTT Broker Node
  mqttBroker["Public MQTT Broker (broker.hivemq.com)"]:::broker

  %% Raspberry Pi Subgraph
  subgraph "Raspberry Pi"
    ledPy["led.py"]:::hardware
    RPi["Hardware LED Controller"]:::hardware
    ledPy --> RPi
  end

  %% Connections
  BrowserUI -->|"HTTP_requests"| NodeServer
  NodeServer -->|"MQTT_publish"| mqttBroker
  mqttBroker -->|"MQTT_subscribe"| RPi

  %% Optional Reverse Flows for Feedback
  RPi -.->|"Status_update"| mqttBroker
  mqttBroker -.->|"MQTT_feedback"| NodeServer
  NodeServer -.->|"HTTP_response"| BrowserUI

  %% Click Events
  click indexHTML "https://github.com/noobyco/ledx/blob/development/public/index.html"
  click mainHTML "https://github.com/noobyco/ledx/blob/development/public/main.html"
  click cssAssets "https://github.com/noobyco/ledx/tree/development/public/css/"
  click appJS "https://github.com/noobyco/ledx/blob/development/app.js"
  click packageJSON "https://github.com/noobyco/ledx/blob/development/package.json"
  click ledPy "https://github.com/noobyco/ledx/blob/development/Pi/led.py"

  %% Styles
  classDef client fill:#add8e6,stroke:#000,stroke-width:2px;
  classDef server fill:#87cefa,stroke:#000,stroke-width:2px;
  classDef broker fill:#ffa500,stroke:#000,stroke-width:2px;
  classDef hardware fill:#90ee90,stroke:#000,stroke-width:2px;
```
