# alexey-gamov/wirenboard architecture

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

- Interactive diagram: https://gitdiagram.com/alexey-gamov/wirenboard
- Repository: https://github.com/alexey-gamov/wirenboard

## Overview

This project is a lightweight repository providing custom templates and rules for the WirenBoard controller when used in conjunction with SprutHub. Essentially, it supports two main functionalities:

##### Main Components
- Repository Storage: This holds all the configuration files and scripts. Separate them into two domains:
- Templates (located in the “templates/sprut-mqtt” folder) – These are device configuration files (in JSON) intended for SprutHub.
- WB-Rules (located in the “wb-rules” folder) – These are custom JavaScript rules executed on the WirenBoard controller.
- WirenBoard Controller: This is the hardware controller that ultimately will run the custom rules.
- SprutHub Interface: The hub that uses the device templates to discover and manage MQTT devices.
- User Interaction/Configuration: The process described in the README where a user copies files into a hidden folder and then uses the WirenBoard web interface to reload templates or add new rules.

##### Relationships and Interactions
- From the Repository → Templates: Show that the JSON configuration files are manually copied (as per instructions) into a user-specific hidden folder on the controller’s filesystem (e.g., /mnt/data/makesimple/.SprutHub/data/Templates/MQTT/Custom).
- From the Repository → WB-Rules: Show that the JavaScript files are copied into the controller’s “Правила” (Rules) section via the web interface.
- From the Controller → SprutHub: Illustrate that once the templates are uploaded, the SprutHub service integrates them. The controller interacts with SprutHub (e.g., when “Перезагрузить шаблоны” is triggered) to refresh the list of devices.
- From the Web Interface to the Controller and SprutHub: Represent the administrative actions (like reloading templates or creating rules) that a user performs via the web UI.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The project clearly separates configuration files (templates) from operational logic (rules), underscoring a separation of device configuration versus control behavior.
- Extensibility: By placing configuration files in easily replaceable and reloadable directories, the design supports straightforward updates and device integrations.

##### Technologies and Frameworks
- MQTT: As the messaging protocol for device discovery and communication, essential for SprutHub integration.
- JavaScript: Used for the wb-rules that define controller behavior.
- WirenBoard hardware: The physical controller that executes these rules.
- SprutHub: The management hub that processes the JSON templates and connects to the MQTT ecosystem.

- Clearly labeled nodes:
- Repository (with subdivisions: “Templates” and “WB-Rules”)
- WirenBoard Controller (with a “Rules” engine)
- SprutHub (template loader and device manager)
- User/Web Interface (for manual file reload and rule creation)
- Visual Distinction:

##### Final Checklist
- Component is clearly labeled.
- Annotations to note that the rules and templates are meant for customizing the controller’s behavior and interaction with the MQTT network via SprutHub.

## Diagram (Mermaid)

```mermaid
graph TD
  subgraph "Repository Storage"
    T1["Templates (JSON)"]:::file
    Tjson["Configuration Files (.json)"]:::fileSub
    R1["WB-Rules (JavaScript)"]:::file
    Rjs["Custom JS Rules (.js)"]:::fileSub
  end

  T1 -->|"includes"| Tjson
  R1 -->|"includes"| Rjs

  subgraph "WirenBoard Controller"
    CT["Templates Folder (/mnt/data/makesimple/.SprutHub/data/Templates/MQTT/Custom)"]:::storage
    CR["Rules Section (Правила)"]:::storage
  end

  UI["User/Web Interface"]:::user
  SH["SprutHub Interface"]:::service

  T1 -->|"manual_copy"| CT
  R1 -->|"upload_via_UI"| CR

  UI -->|"ReloadTemplates"| CT
  UI -->|"CreateRules"| CR

  CT -->|"IntegrateMQTT"| SH

  classDef file fill:#f9c,stroke:#333,stroke-width:2px;
  classDef fileSub fill:#fce,stroke:#333,stroke-width:2px;
  classDef storage fill:#bbf,stroke:#333,stroke-width:2px;
  classDef service fill:#afa,stroke:#333,stroke-width:2px;
  classDef user fill:#ff9,stroke:#333,stroke-width:2px;

  click T1 "https://github.com/alexey-gamov/wirenboard/tree/main/templates/sprut-mqtt"
  click Tjson "https://github.com/alexey-gamov/wirenboard/blob/main/templates/sprut-mqtt/*.json"
  click R1 "https://github.com/alexey-gamov/wirenboard/tree/main/wb-rules"
  click Rjs "https://github.com/alexey-gamov/wirenboard/blob/main/wb-rules/*.js"
```
