# mariofritzer/opple-smart-connect-box-diy architecture

> Architecture diagram of the GitHub repository mariofritzer/opple-smart-connect-box-diy, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mariofritzer/opple-smart-connect-box-diy
- Repository: https://github.com/mariofritzer/opple-smart-connect-box-diy

## Overview

SkyBridge turns an ESP32 into a local Bluetooth Mesh-to-Home Assistant bridge. The user imports a Telink mesh export and Wi-Fi/MQTT settings through the setup portal; the bridge persists the keys, discovers lamps, and joins the mesh. MQTT Discovery exposes individual lamps and an all-lamps group to Home Assistant. Commands travel back through MQTT and the mesh, while polled or changed lamp state is published for Home Assistant. The excerpts show the main startup, portal, MQTT, and mesh responsibilities; some discovery and persistence wiring is documented but not fully sampled.

Main entry points: [`main/main.c`](https://github.com/mariofritzer/opple-smart-connect-box-diy/blob/main/main/main.c) (Startup and Wi-Fi), [`main/mesh.c`](https://github.com/mariofritzer/opple-smart-connect-box-diy/blob/main/main/mesh.c) (Mesh Runtime), [`main/portal.c`](https://github.com/mariofritzer/opple-smart-connect-box-diy/blob/main/main/portal.c) (Setup Portal), [`main/mqtt_ha.c`](https://github.com/mariofritzer/opple-smart-connect-box-diy/blob/main/main/mqtt_ha.c) (MQTT Discovery and Commands)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_setup["Setup and Config"]
  node_portal["Setup Portal<br/>[portal.c]"]
  node_config[("Saved Config<br/>[portal.c]")]
  node_board_profiles["Board Profiles<br/>[boards.h]"]
end

subgraph group_network["Connectivity"]
  node_runtime["Startup and Wi-Fi<br/>[main.c]"]
end

subgraph group_mesh["Bluetooth Mesh"]
  node_mesh["Mesh Runtime<br/>[mesh.c]"]
end

subgraph group_ha["Home Assistant"]
  node_mqtt["MQTT Discovery and Commands<br/>[mqtt_ha.c]"]
end

node_user(("Installer"))
node_wifi(("Wi-Fi Network"))
node_mesh_export["Telink Mesh Export"]
node_lamps(("Mesh Lamps"))
node_broker(("MQTT Broker"))
node_ha_actor(("Home Assistant"))

node_user -->|"configures"| node_portal
node_mesh_export -->|"uploads keys"| node_portal
node_portal -->|"saves settings"| node_config
node_runtime -->|"loads settings"| node_config
node_runtime -->|"applies profile"| node_board_profiles
node_runtime -->|"starts portal"| node_portal
node_runtime -->|"joins network"| node_wifi
node_wifi -->|"provides IP"| node_runtime
node_runtime -->|"starts mesh"| node_mesh
node_runtime -->|"starts MQTT"| node_mqtt
node_portal -->|"requests scan"| node_mesh
node_mesh -->|"discovers and controls"| node_lamps
node_lamps -->|"returns status"| node_mesh
node_mesh -->|"stores lamp data"| node_config
node_mesh -->|"publishes lamp state"| node_mqtt
node_mqtt -->|"submits commands"| node_mesh
node_mqtt -->|"publishes and subscribes"| node_broker
node_broker -->|"delivers commands"| node_mqtt
node_ha_actor -->|"sends commands"| node_broker
node_broker -->|"delivers discovery and state"| node_ha_actor

click node_portal "https://github.com/mariofritzer/opple-smart-connect-box-diy/blob/main/main/portal.c"
click node_config "https://github.com/mariofritzer/opple-smart-connect-box-diy/blob/main/main/portal.c"
click node_runtime "https://github.com/mariofritzer/opple-smart-connect-box-diy/blob/main/main/main.c"
click node_mesh "https://github.com/mariofritzer/opple-smart-connect-box-diy/blob/main/main/mesh.c"
click node_mqtt "https://github.com/mariofritzer/opple-smart-connect-box-diy/blob/main/main/mqtt_ha.c"
click node_board_profiles "https://github.com/mariofritzer/opple-smart-connect-box-diy/blob/main/main/boards.h"

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_portal,node_config,node_board_profiles toneBlue
class node_runtime toneAmber
class node_mesh toneMint
class node_mqtt toneRose
class node_user,node_wifi,node_mesh_export,node_lamps,node_broker,node_ha_actor toneIndigo
```

## Components

### Setup and Config

- [Setup Portal](https://github.com/mariofritzer/opple-smart-connect-box-diy/blob/main/main/portal.c): `main/portal.c`
- [Saved Config](https://github.com/mariofritzer/opple-smart-connect-box-diy/blob/main/main/portal.c): `main/portal.c`
- [Board Profiles](https://github.com/mariofritzer/opple-smart-connect-box-diy/blob/main/main/boards.h): `main/boards.h`

### Connectivity

- [Startup and Wi-Fi](https://github.com/mariofritzer/opple-smart-connect-box-diy/blob/main/main/main.c): `main/main.c`

### Bluetooth Mesh

- [Mesh Runtime](https://github.com/mariofritzer/opple-smart-connect-box-diy/blob/main/main/mesh.c): `main/mesh.c`

### Home Assistant

- [MQTT Discovery and Commands](https://github.com/mariofritzer/opple-smart-connect-box-diy/blob/main/main/mqtt_ha.c): `main/mqtt_ha.c`

### Other components

- **Installer**
- **Wi-Fi Network**
- **Telink Mesh Export**
- **Mesh Lamps**
- **MQTT Broker**
- **Home Assistant**

## Connections

- Installer → Setup Portal: configures
- Telink Mesh Export → Setup Portal: uploads keys
- Setup Portal → Saved Config: saves settings
- Startup and Wi-Fi → Saved Config: loads settings
- Startup and Wi-Fi → Board Profiles: applies profile
- Startup and Wi-Fi → Setup Portal: starts portal
- Startup and Wi-Fi → Wi-Fi Network: joins network
- Wi-Fi Network → Startup and Wi-Fi: provides IP
- Startup and Wi-Fi → Mesh Runtime: starts mesh
- Startup and Wi-Fi → MQTT Discovery and Commands: starts MQTT
- Setup Portal → Mesh Runtime: requests scan
- Mesh Runtime → Mesh Lamps: discovers and controls
- Mesh Lamps → Mesh Runtime: returns status
- Mesh Runtime → Saved Config: stores lamp data
- Mesh Runtime → MQTT Discovery and Commands: publishes lamp state
- MQTT Discovery and Commands → Mesh Runtime: submits commands
- MQTT Discovery and Commands → MQTT Broker: publishes and subscribes
- MQTT Broker → MQTT Discovery and Commands: delivers commands
- Home Assistant → MQTT Broker: sends commands
- MQTT Broker → Home Assistant: delivers discovery and state
