# th-luan05/node architecture

> Architecture diagram of the GitHub repository th-luan05/node, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/th-luan05/node
- Repository: https://github.com/th-luan05/node

## Overview

This repository contains ESP32 node firmware for a sensor-and-relay device that communicates with a master over ESP-NOW and Wi-Fi, with BLE provisioning and OTA support. The main device workflow is receiving a master command, dispatching it to relay, configuration, safety, or OTA handling, then reporting status. Most runtime behavior resides in one source file; the excerpts show command dispatch, routing, and OTA event handling, but omit much of setup, telemetry, and sensor sampling, so those connections are not inferred.

Main entry points: [`src/main.cpp`](https://github.com/th-luan05/node/blob/main/src/main.cpp) (Node Firmware), [`lib/proto/proto.h`](https://github.com/th-luan05/node/blob/main/lib/proto/proto.h) (Packet Protocol)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_device["Device Runtime"]
  node_firmware["Node Firmware<br/>[main.cpp]"]
  node_sensing["Sensor Sampling<br/>[main.cpp]"]
  node_relay["Relay Control<br/>[main.cpp]"]
  node_safety["Thermal Safety<br/>[main.cpp]"]
  node_configuration["Device Configuration<br/>[main.cpp]"]
end

subgraph group_network["Mesh Networking"]
  node_protocol["Packet Protocol<br/>[proto.h]"]
  node_routing["Mesh Routing<br/>[main.cpp]"]
  node_udp["Wi-Fi UDP<br/>[main.cpp]"]
end

subgraph group_maintenance["Provisioning And Updates"]
  node_ble["BLE Provisioning<br/>[main.cpp]"]
  node_storage[("Persistent Settings<br/>[main.cpp]")]
  node_ota["Firmware Updates<br/>[main.cpp]"]
  node_ota_queue["OTA Event Queue<br/>[main.cpp]"]
end

node_master(("Master"))
node_ota_server(("OTA Server"))

node_firmware -->|"includes definitions"| node_protocol
node_master -->|"sends commands"| node_firmware
node_firmware -->|"dispatches relay"| node_relay
node_firmware -->|"dispatches config"| node_configuration
node_firmware -->|"dispatches safety"| node_safety
node_firmware -->|"dispatches update"| node_ota
node_relay -->|"sends telemetry"| node_firmware
node_routing -->|"forwards packets"| node_routing
node_ota -->|"queues events"| node_ota_queue
node_ota_queue -->|"drains events"| node_firmware
node_ota -->|"checks and downloads"| node_ota_server

click node_firmware "https://github.com/th-luan05/node/blob/main/src/main.cpp"
click node_sensing "https://github.com/th-luan05/node/blob/main/src/main.cpp"
click node_relay "https://github.com/th-luan05/node/blob/main/src/main.cpp"
click node_safety "https://github.com/th-luan05/node/blob/main/src/main.cpp"
click node_configuration "https://github.com/th-luan05/node/blob/main/src/main.cpp"
click node_protocol "https://github.com/th-luan05/node/blob/main/lib/proto/proto.h"
click node_routing "https://github.com/th-luan05/node/blob/main/src/main.cpp"
click node_udp "https://github.com/th-luan05/node/blob/main/src/main.cpp"
click node_ble "https://github.com/th-luan05/node/blob/main/src/main.cpp"
click node_storage "https://github.com/th-luan05/node/blob/main/src/main.cpp"
click node_ota "https://github.com/th-luan05/node/blob/main/src/main.cpp"
click node_ota_queue "https://github.com/th-luan05/node/blob/main/src/main.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_firmware,node_sensing,node_relay,node_safety,node_configuration toneBlue
class node_protocol,node_routing,node_udp toneAmber
class node_ble,node_storage,node_ota,node_ota_queue,node_ota_server toneMint
class node_master toneIndigo
```

## Components

### Device Runtime

- [Node Firmware](https://github.com/th-luan05/node/blob/main/src/main.cpp): `src/main.cpp`
- [Sensor Sampling](https://github.com/th-luan05/node/blob/main/src/main.cpp): `src/main.cpp`
- [Relay Control](https://github.com/th-luan05/node/blob/main/src/main.cpp): `src/main.cpp`
- [Thermal Safety](https://github.com/th-luan05/node/blob/main/src/main.cpp): `src/main.cpp`
- [Device Configuration](https://github.com/th-luan05/node/blob/main/src/main.cpp): `src/main.cpp`

### Mesh Networking

- [Packet Protocol](https://github.com/th-luan05/node/blob/main/lib/proto/proto.h): `lib/proto/proto.h`
- [Mesh Routing](https://github.com/th-luan05/node/blob/main/src/main.cpp): `src/main.cpp`
- [Wi-Fi UDP](https://github.com/th-luan05/node/blob/main/src/main.cpp): `src/main.cpp`

### Provisioning And Updates

- [BLE Provisioning](https://github.com/th-luan05/node/blob/main/src/main.cpp): `src/main.cpp`
- [Persistent Settings](https://github.com/th-luan05/node/blob/main/src/main.cpp): `src/main.cpp`
- [Firmware Updates](https://github.com/th-luan05/node/blob/main/src/main.cpp): `src/main.cpp`
- [OTA Event Queue](https://github.com/th-luan05/node/blob/main/src/main.cpp): `src/main.cpp`

### Other components

- **Master**
- **OTA Server**

## Connections

- Node Firmware → Packet Protocol: includes definitions (evidence: `src/main.cpp`)
- Master → Node Firmware: sends commands
- Node Firmware → Relay Control: dispatches relay (evidence: `src/main.cpp`)
- Node Firmware → Device Configuration: dispatches config (evidence: `src/main.cpp`)
- Node Firmware → Thermal Safety: dispatches safety (evidence: `src/main.cpp`)
- Node Firmware → Firmware Updates: dispatches update (evidence: `src/main.cpp`)
- Relay Control → Node Firmware: sends telemetry (evidence: `src/main.cpp`)
- Mesh Routing → Mesh Routing: forwards packets (evidence: `src/main.cpp`)
- Firmware Updates → OTA Event Queue: queues events (evidence: `src/main.cpp`)
- OTA Event Queue → Node Firmware: drains events (evidence: `src/main.cpp`)
- Firmware Updates → OTA Server: checks and downloads (evidence: `src/main.cpp`)
