# kkqq9320/ha-lgu-mttl-w01 architecture

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

- Interactive diagram: https://gitdiagram.com/kkqq9320/ha-lgu-mttl-w01
- Repository: https://github.com/kkqq9320/ha-lgu-mttl-w01

## Overview

This is a Home Assistant add-on for locally controlling LG U+ MTTL-W01 power strips. The main workflow runs from the sidebar dashboard or settings page through the backend to device control and status; settings also configure firmware updates and MQTT discovery. The backend additionally maintains device state and supports backup/restore. The graph preserves the dashboard, logs, QR, firmware, and Home Assistant integration branches. Some subsystem links are documented rather than shown in sampled calls; those are dashed where implementation wiring is unverified.

Main entry points: [`mttl_w01/backend/backend.py`](https://github.com/kkqq9320/ha-lgu-mttl-w01/blob/main/mttl_w01/backend/backend.py) (Backend API and device runtime), [`mttl_w01/backend/static/dashboard.mjs`](https://github.com/kkqq9320/ha-lgu-mttl-w01/blob/main/mttl_w01/backend/static/dashboard.mjs) (Dashboard), [`mttl_w01/backend/static/settings.mjs`](https://github.com/kkqq9320/ha-lgu-mttl-w01/blob/main/mttl_w01/backend/static/settings.mjs) (Settings page), [`mttl_w01/backend/firmware_manager.py`](https://github.com/kkqq9320/ha-lgu-mttl-w01/blob/main/mttl_w01/backend/firmware_manager.py) (Firmware jobs and OTA)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Sidebar experience"]
  node_dashboard["Dashboard<br/>[dashboard.mjs]"]
  node_settings["Settings page<br/>[settings.mjs]"]
  node_logs["Log viewer<br/>[logview.mjs]"]
  node_page["Shared page helpers<br/>[page.mjs]"]
  node_qr["QR encoder<br/>[qr.mjs]"]
end

subgraph group_core["Backend and state"]
  node_backend["Backend API and device runtime<br/>[backend.py]"]
  node_store[("SQLite device state<br/>[backend.py]")]
  node_backup["Backup and restore<br/>[backup_manager.py]"]
end

subgraph group_firmware["Firmware lifecycle"]
  node_firmware_manager["Firmware jobs and OTA"]
  node_patch["Firmware builder<br/>[firmware_patch.py]"]
end

subgraph group_integrations["Home Assistant integration"]
  node_ha_bridge["MQTT discovery bridge<br/>[ha_bridge.py]"]
end

node_user(("Home Assistant user"))
node_strips{{"Power strips"}}
node_mqtt["MQTT broker"]
node_home_assistant(("Home Assistant"))

node_user -->|"opens"| node_dashboard
node_user -->|"configures"| node_settings
node_dashboard -->|"requests API"| node_backend
node_settings -->|"requests API"| node_backend
node_logs -.->|"reads logs"| node_backend
node_dashboard -->|"encodes QR"| node_qr
node_dashboard -->|"uses helpers"| node_page
node_settings -->|"uses helpers"| node_page
node_backend -->|"reads and writes"| node_store
node_backend -->|"dispatches firmware"| node_firmware_manager
node_backend -->|"uses backups"| node_backup
node_firmware_manager -->|"builds firmware"| node_patch
node_firmware_manager -.->|"serves OTA"| node_strips
node_backend -.->|"controls locally"| node_strips
node_backend -.->|"configures bridge"| node_ha_bridge
node_ha_bridge -->|"reads devices"| node_store
node_ha_bridge -->|"publishes discovery"| node_mqtt
node_mqtt -->|"discovers devices"| node_home_assistant

click node_dashboard "https://github.com/kkqq9320/ha-lgu-mttl-w01/blob/main/mttl_w01/backend/static/dashboard.mjs"
click node_settings "https://github.com/kkqq9320/ha-lgu-mttl-w01/blob/main/mttl_w01/backend/static/settings.mjs"
click node_logs "https://github.com/kkqq9320/ha-lgu-mttl-w01/blob/main/mttl_w01/backend/static/logview.mjs"
click node_page "https://github.com/kkqq9320/ha-lgu-mttl-w01/blob/main/mttl_w01/backend/static/page.mjs"
click node_qr "https://github.com/kkqq9320/ha-lgu-mttl-w01/blob/main/mttl_w01/backend/static/qr.mjs"
click node_backend "https://github.com/kkqq9320/ha-lgu-mttl-w01/blob/main/mttl_w01/backend/backend.py"
click node_store "https://github.com/kkqq9320/ha-lgu-mttl-w01/blob/main/mttl_w01/backend/backend.py"
click node_backup "https://github.com/kkqq9320/ha-lgu-mttl-w01/blob/main/mttl_w01/backend/backup_manager.py"
click node_firmware_manager "https://github.com/kkqq9320/ha-lgu-mttl-w01/blob/main/mttl_w01/backend/firmware_manager.py"
click node_patch "https://github.com/kkqq9320/ha-lgu-mttl-w01/blob/main/mttl_w01/backend/firmware_patch.py"
click node_ha_bridge "https://github.com/kkqq9320/ha-lgu-mttl-w01/blob/main/mttl_w01/backend/ha_bridge.py"

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_dashboard,node_settings,node_logs,node_page,node_qr,node_user toneBlue
class node_backend,node_store,node_backup toneAmber
class node_firmware_manager,node_patch toneMint
class node_ha_bridge toneRose
class node_strips,node_mqtt,node_home_assistant toneIndigo
```

## Components

### Sidebar experience

- [Dashboard](https://github.com/kkqq9320/ha-lgu-mttl-w01/blob/main/mttl_w01/backend/static/dashboard.mjs): `mttl_w01/backend/static/dashboard.mjs`
- [Settings page](https://github.com/kkqq9320/ha-lgu-mttl-w01/blob/main/mttl_w01/backend/static/settings.mjs): `mttl_w01/backend/static/settings.mjs`
- [Log viewer](https://github.com/kkqq9320/ha-lgu-mttl-w01/blob/main/mttl_w01/backend/static/logview.mjs): `mttl_w01/backend/static/logview.mjs`
- [Shared page helpers](https://github.com/kkqq9320/ha-lgu-mttl-w01/blob/main/mttl_w01/backend/static/page.mjs): `mttl_w01/backend/static/page.mjs`
- [QR encoder](https://github.com/kkqq9320/ha-lgu-mttl-w01/blob/main/mttl_w01/backend/static/qr.mjs): `mttl_w01/backend/static/qr.mjs`

### Backend and state

- [Backend API and device runtime](https://github.com/kkqq9320/ha-lgu-mttl-w01/blob/main/mttl_w01/backend/backend.py): `mttl_w01/backend/backend.py`
- [SQLite device state](https://github.com/kkqq9320/ha-lgu-mttl-w01/blob/main/mttl_w01/backend/backend.py): `mttl_w01/backend/backend.py`
- [Backup and restore](https://github.com/kkqq9320/ha-lgu-mttl-w01/blob/main/mttl_w01/backend/backup_manager.py): `mttl_w01/backend/backup_manager.py`

### Firmware lifecycle

- [Firmware jobs and OTA](https://github.com/kkqq9320/ha-lgu-mttl-w01/blob/main/mttl_w01/backend/firmware_manager.py): `mttl_w01/backend/firmware_manager.py`
- [Firmware builder](https://github.com/kkqq9320/ha-lgu-mttl-w01/blob/main/mttl_w01/backend/firmware_patch.py): `mttl_w01/backend/firmware_patch.py`

### Home Assistant integration

- [MQTT discovery bridge](https://github.com/kkqq9320/ha-lgu-mttl-w01/blob/main/mttl_w01/backend/ha_bridge.py): `mttl_w01/backend/ha_bridge.py`

### Other components

- **Home Assistant user**
- **Power strips**
- **MQTT broker**
- **Home Assistant**

## Connections

- Home Assistant user → Dashboard: opens (evidence: `README.md`)
- Home Assistant user → Settings page: configures (evidence: `README.md`)
- Dashboard → Backend API and device runtime: requests API (evidence: `mttl_w01/backend/static/dashboard.mjs`)
- Settings page → Backend API and device runtime: requests API
- Log viewer → Backend API and device runtime: reads logs
- Dashboard → QR encoder: encodes QR (evidence: `mttl_w01/backend/static/dashboard.mjs`)
- Dashboard → Shared page helpers: uses helpers (evidence: `mttl_w01/backend/static/dashboard.mjs`)
- Settings page → Shared page helpers: uses helpers (evidence: `mttl_w01/backend/static/settings.mjs`)
- Backend API and device runtime → SQLite device state: reads and writes (evidence: `mttl_w01/backend/backend.py`)
- Backend API and device runtime → Firmware jobs and OTA: dispatches firmware (evidence: `mttl_w01/backend/backend.py`)
- Backend API and device runtime → Backup and restore: uses backups (evidence: `mttl_w01/backend/backend.py`)
- Firmware jobs and OTA → Firmware builder: builds firmware (evidence: `mttl_w01/backend/firmware_manager.py`)
- Firmware jobs and OTA → Power strips: serves OTA
- Backend API and device runtime → Power strips: controls locally
- Backend API and device runtime → MQTT discovery bridge: configures bridge (evidence: `mttl_w01/backend/backend.py`)
- MQTT discovery bridge → SQLite device state: reads devices (evidence: `mttl_w01/backend/ha_bridge.py`)
- MQTT discovery bridge → MQTT broker: publishes discovery (evidence: `README.md`)
- MQTT broker → Home Assistant: discovers devices (evidence: `README.md`)
