# asterismp/muggleswand-src architecture

> Architecture diagram of the GitHub repository asterismp/muggleswand-src, 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/asterismp/muggleswand-src
- Repository: https://github.com/asterismp/muggleswand-src

## Overview

Muggles’ Wand is ESP32-S3 firmware for a gesture-controlled LED wand. At startup, the firmware initializes services, hardware, inference, and the apps; IMU samples feed gesture buffering and TensorFlow Lite inference, whose events the app task maps to LED effects and features such as BLE HID, ESP-NOW, Lumos, and POV drawing. Separate branches provide console/system control, a web-managed access point, OTA, sleep, and battery/power status. The README documents these capabilities; several implementation files were not sampled, so those links are included only where documented or indexed references support them.

Main entry points: [`src/APP/APP.cpp`](https://github.com/asterismp/muggleswand-src/blob/main/src/APP/APP.cpp) (Gesture app dispatcher), [`src/Service/Service.cpp`](https://github.com/asterismp/muggleswand-src/blob/main/src/Service/Service.cpp) (System service), [`src/main.cpp`](https://github.com/asterismp/muggleswand-src/blob/main/src/main.cpp) (Firmware startup), [`src/Service/EventBus.cpp`](https://github.com/asterismp/muggleswand-src/blob/main/src/Service/EventBus.cpp) (Event bus)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_boot["Startup and Coordination"]
  node_startup["Firmware startup<br/>[main.cpp]"]
  node_eventbus["Event bus<br/>[EventBus.cpp]"]
end

subgraph group_sensing["Sensing and Inference"]
  node_imu["IMU acquisition<br/>[HAL_IMU.cpp]"]
  node_imu_driver["ICM42670P driver<br/>[HAL_ICM42670P.cpp]"]
  node_gesturebuffer["Gesture buffer<br/>[gesture_buffer.cpp]"]
  node_inference["Gesture inference"]
  node_gesturemodel["Gesture model<br/>[gesture_model.h]"]
end

subgraph group_features["User Features"]
  node_appdispatch["Gesture app dispatcher<br/>[APP.cpp]"]
  node_blehid["BLE HID modes<br/>[APP_BLE_HID.cpp]"]
  node_espnow["ESP-NOW signaling<br/>[APP_EspNow.cpp]"]
  node_lumos["Lumos mode<br/>[APP_Lumos.cpp]"]
  node_pov["POV drawing<br/>[APP_POV.cpp]"]
  node_povpatterns["POV patterns<br/>[APP_POVPatterns.h]"]
end

subgraph group_platform["Hardware and Effects"]
  node_ledhal["LED animation engine<br/>[HAL_WS2812.cpp]"]
  node_animationbase["Animation base<br/>[AnimationBase.hpp]"]
  node_animations["Animation effects<br/>[AnimPOV.hpp]"]
  node_hardware["Board HAL<br/>[HAL.h]"]
  node_power["Power and battery<br/>[HAL_Power.cpp]"]
end

subgraph group_services["System Services"]
  node_service["System service<br/>[Service.cpp]"]
  node_console["Serial console<br/>[Console.cpp]"]
  node_ap["Wi-Fi access point<br/>[AP.cpp]"]
  node_apweb["Web management<br/>[AP_Web.cpp]"]
  node_ble["BLE service<br/>[BLE.cpp]"]
  node_ota["OTA update<br/>[OTA.cpp]"]
  node_sleep["Sleep service<br/>[Sleep.cpp]"]
end

node_user(("Wand user"))
node_webadmin(("Web administrator"))
node_blepeer(("BLE host device"))

node_startup -->|"initializes"| node_eventbus
node_startup -->|"starts"| node_service
node_startup -->|"initializes and starts"| node_inference
node_startup -->|"initializes"| node_hardware
node_startup -->|"initializes"| node_appdispatch
node_imu -->|"reads sensor"| node_imu_driver
node_imu -->|"fills samples"| node_gesturebuffer
node_imu -->|"publishes IMU events"| node_eventbus
node_inference -->|"acquires samples"| node_gesturebuffer
node_inference -->|"runs model"| node_gesturemodel
node_inference -->|"publishes gesture"| node_eventbus
node_eventbus -->|"delivers events"| node_appdispatch
node_appdispatch -->|"starts effects"| node_ledhal
node_appdispatch -->|"sends signals"| node_espnow
node_appdispatch -->|"dispatches HID actions"| node_blehid
node_appdispatch -->|"triggers mode"| node_lumos
node_appdispatch -->|"controls mode"| node_pov
node_pov -->|"selects pattern"| node_povpatterns
node_pov -->|"renders drawing"| node_ledhal
node_ledhal -->|"manages animations"| node_animationbase
node_animations -->|"implements"| node_animationbase
node_blehid -->|"uses BLE service"| node_ble
node_startup -->|"initializes"| node_console
node_console -.->|"issues system events"| node_eventbus
node_service -->|"subscribes to events"| node_eventbus
node_service -->|"starts update mode"| node_ota
node_service -->|"toggles BLE"| node_ble
node_service -->|"toggles hotspot"| node_ap
node_service -->|"enters sleep"| node_sleep
node_service -->|"controls power and LEDs"| node_hardware
node_apweb -->|"uses event bus"| node_eventbus
node_ap -.->|"serves management"| node_apweb
node_webadmin -.->|"manages firmware"| node_apweb
node_ble -.->|"communicates"| node_blepeer
node_user -.->|"gestures and presses"| node_appdispatch
node_hardware -->|"exposes power APIs"| node_power

click node_startup "https://github.com/asterismp/muggleswand-src/blob/main/src/main.cpp"
click node_eventbus "https://github.com/asterismp/muggleswand-src/blob/main/src/Service/EventBus.cpp"
click node_appdispatch "https://github.com/asterismp/muggleswand-src/blob/main/src/APP/APP.cpp"
click node_imu "https://github.com/asterismp/muggleswand-src/blob/main/src/HAL/HAL_IMU.cpp"
click node_imu_driver "https://github.com/asterismp/muggleswand-src/blob/main/src/HAL/HAL_ICM42670P.cpp"
click node_gesturebuffer "https://github.com/asterismp/muggleswand-src/blob/main/src/Model/gesture_buffer.cpp"
click node_inference "https://github.com/asterismp/muggleswand-src/blob/main/src/Model/gesture_inference.cpp"
click node_gesturemodel "https://github.com/asterismp/muggleswand-src/blob/main/src/Model/gesture_model.h"
click node_blehid "https://github.com/asterismp/muggleswand-src/blob/main/src/APP/APP_BLE_HID.cpp"
click node_espnow "https://github.com/asterismp/muggleswand-src/blob/main/src/APP/APP_EspNow.cpp"
click node_lumos "https://github.com/asterismp/muggleswand-src/blob/main/src/APP/APP_Lumos.cpp"
click node_pov "https://github.com/asterismp/muggleswand-src/blob/main/src/APP/APP_POV.cpp"
click node_povpatterns "https://github.com/asterismp/muggleswand-src/blob/main/src/APP/APP_POVPatterns.h"
click node_ledhal "https://github.com/asterismp/muggleswand-src/blob/main/src/HAL/HAL_WS2812.cpp"
click node_animationbase "https://github.com/asterismp/muggleswand-src/blob/main/src/HAL/WS2812_Animation/AnimationBase.hpp"
click node_animations "https://github.com/asterismp/muggleswand-src/blob/main/src/HAL/WS2812_Animation/AnimPOV.hpp"
click node_hardware "https://github.com/asterismp/muggleswand-src/blob/main/src/HAL/HAL.h"
click node_service "https://github.com/asterismp/muggleswand-src/blob/main/src/Service/Service.cpp"
click node_console "https://github.com/asterismp/muggleswand-src/blob/main/src/Service/Console.cpp"
click node_ap "https://github.com/asterismp/muggleswand-src/blob/main/src/Service/AP.cpp"
click node_apweb "https://github.com/asterismp/muggleswand-src/blob/main/src/Service/AP_Web.cpp"
click node_ble "https://github.com/asterismp/muggleswand-src/blob/main/src/Service/BLE.cpp"
click node_ota "https://github.com/asterismp/muggleswand-src/blob/main/src/Service/OTA.cpp"
click node_sleep "https://github.com/asterismp/muggleswand-src/blob/main/src/Service/Sleep.cpp"
click node_power "https://github.com/asterismp/muggleswand-src/blob/main/src/HAL/HAL_Power.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_startup,node_eventbus,node_user toneBlue
class node_imu,node_imu_driver,node_gesturebuffer,node_inference,node_gesturemodel toneAmber
class node_appdispatch,node_blehid,node_espnow,node_lumos,node_pov,node_povpatterns toneMint
class node_ledhal,node_animationbase,node_animations,node_hardware,node_power toneRose
class node_service,node_console,node_ap,node_apweb,node_ble,node_ota,node_sleep,node_webadmin,node_blepeer toneIndigo
```

## Components

### Startup and Coordination

- [Firmware startup](https://github.com/asterismp/muggleswand-src/blob/main/src/main.cpp): `src/main.cpp`
- [Event bus](https://github.com/asterismp/muggleswand-src/blob/main/src/Service/EventBus.cpp): `src/Service/EventBus.cpp`

### Sensing and Inference

- [IMU acquisition](https://github.com/asterismp/muggleswand-src/blob/main/src/HAL/HAL_IMU.cpp): `src/HAL/HAL_IMU.cpp`
- [ICM42670P driver](https://github.com/asterismp/muggleswand-src/blob/main/src/HAL/HAL_ICM42670P.cpp): `src/HAL/HAL_ICM42670P.cpp`
- [Gesture buffer](https://github.com/asterismp/muggleswand-src/blob/main/src/Model/gesture_buffer.cpp): `src/Model/gesture_buffer.cpp`
- [Gesture inference](https://github.com/asterismp/muggleswand-src/blob/main/src/Model/gesture_inference.cpp): `src/Model/gesture_inference.cpp`
- [Gesture model](https://github.com/asterismp/muggleswand-src/blob/main/src/Model/gesture_model.h): `src/Model/gesture_model.h`

### User Features

- [Gesture app dispatcher](https://github.com/asterismp/muggleswand-src/blob/main/src/APP/APP.cpp): `src/APP/APP.cpp`
- [BLE HID modes](https://github.com/asterismp/muggleswand-src/blob/main/src/APP/APP_BLE_HID.cpp): `src/APP/APP_BLE_HID.cpp`
- [ESP-NOW signaling](https://github.com/asterismp/muggleswand-src/blob/main/src/APP/APP_EspNow.cpp): `src/APP/APP_EspNow.cpp`
- [Lumos mode](https://github.com/asterismp/muggleswand-src/blob/main/src/APP/APP_Lumos.cpp): `src/APP/APP_Lumos.cpp`
- [POV drawing](https://github.com/asterismp/muggleswand-src/blob/main/src/APP/APP_POV.cpp): `src/APP/APP_POV.cpp`
- [POV patterns](https://github.com/asterismp/muggleswand-src/blob/main/src/APP/APP_POVPatterns.h): `src/APP/APP_POVPatterns.h`

### Hardware and Effects

- [LED animation engine](https://github.com/asterismp/muggleswand-src/blob/main/src/HAL/HAL_WS2812.cpp): `src/HAL/HAL_WS2812.cpp`
- [Animation base](https://github.com/asterismp/muggleswand-src/blob/main/src/HAL/WS2812_Animation/AnimationBase.hpp): `src/HAL/WS2812_Animation/AnimationBase.hpp`
- [Animation effects](https://github.com/asterismp/muggleswand-src/blob/main/src/HAL/WS2812_Animation/AnimPOV.hpp): `src/HAL/WS2812_Animation/AnimPOV.hpp`
- [Board HAL](https://github.com/asterismp/muggleswand-src/blob/main/src/HAL/HAL.h): `src/HAL/HAL.h`
- [Power and battery](https://github.com/asterismp/muggleswand-src/blob/main/src/HAL/HAL_Power.cpp): `src/HAL/HAL_Power.cpp`

### System Services

- [System service](https://github.com/asterismp/muggleswand-src/blob/main/src/Service/Service.cpp): `src/Service/Service.cpp`
- [Serial console](https://github.com/asterismp/muggleswand-src/blob/main/src/Service/Console.cpp): `src/Service/Console.cpp`
- [Wi-Fi access point](https://github.com/asterismp/muggleswand-src/blob/main/src/Service/AP.cpp): `src/Service/AP.cpp`
- [Web management](https://github.com/asterismp/muggleswand-src/blob/main/src/Service/AP_Web.cpp): `src/Service/AP_Web.cpp`
- [BLE service](https://github.com/asterismp/muggleswand-src/blob/main/src/Service/BLE.cpp): `src/Service/BLE.cpp`
- [OTA update](https://github.com/asterismp/muggleswand-src/blob/main/src/Service/OTA.cpp): `src/Service/OTA.cpp`
- [Sleep service](https://github.com/asterismp/muggleswand-src/blob/main/src/Service/Sleep.cpp): `src/Service/Sleep.cpp`

### Other components

- **Wand user**
- **Web administrator**
- **BLE host device**

## Connections

- Firmware startup → Event bus: initializes (evidence: `src/main.cpp`)
- Firmware startup → System service: starts (evidence: `src/main.cpp`)
- Firmware startup → Gesture inference: initializes and starts (evidence: `src/main.cpp`)
- Firmware startup → Board HAL: initializes (evidence: `src/main.cpp`)
- Firmware startup → Gesture app dispatcher: initializes (evidence: `src/main.cpp`)
- IMU acquisition → ICM42670P driver: reads sensor (evidence: `src/HAL/HAL_IMU.cpp`)
- IMU acquisition → Gesture buffer: fills samples (evidence: `src/HAL/HAL_IMU.cpp`)
- IMU acquisition → Event bus: publishes IMU events (evidence: `src/HAL/HAL_IMU.cpp`)
- Gesture inference → Gesture buffer: acquires samples (evidence: `src/Model/gesture_inference.cpp`)
- Gesture inference → Gesture model: runs model (evidence: `src/Model/gesture_inference.cpp`)
- Gesture inference → Event bus: publishes gesture (evidence: `src/Model/gesture_inference.cpp`)
- Event bus → Gesture app dispatcher: delivers events (evidence: `src/APP/APP.cpp`)
- Gesture app dispatcher → LED animation engine: starts effects (evidence: `src/APP/APP.cpp`)
- Gesture app dispatcher → ESP-NOW signaling: sends signals (evidence: `src/APP/APP.cpp`)
- Gesture app dispatcher → BLE HID modes: dispatches HID actions (evidence: `src/APP/APP.cpp`)
- Gesture app dispatcher → Lumos mode: triggers mode (evidence: `src/APP/APP.cpp`)
- Gesture app dispatcher → POV drawing: controls mode (evidence: `src/APP/APP.cpp`)
- POV drawing → POV patterns: selects pattern (evidence: `src/APP/APP_POV.cpp`)
- POV drawing → LED animation engine: renders drawing (evidence: `src/APP/APP_POV.cpp`)
- LED animation engine → Animation base: manages animations (evidence: `src/HAL/HAL_WS2812.cpp`)
- Animation effects → Animation base: implements (evidence: `src/HAL/WS2812_Animation/AnimPOV.hpp`)
- BLE HID modes → BLE service: uses BLE service (evidence: `src/APP/APP_BLE_HID.cpp`)
- Firmware startup → Serial console: initializes (evidence: `src/main.cpp`)
- Serial console → Event bus: issues system events
- System service → Event bus: subscribes to events (evidence: `src/Service/Service.cpp`)
- System service → OTA update: starts update mode (evidence: `src/Service/Service.cpp`)
- System service → BLE service: toggles BLE (evidence: `src/Service/Service.cpp`)
- System service → Wi-Fi access point: toggles hotspot (evidence: `src/Service/Service.cpp`)
- System service → Sleep service: enters sleep (evidence: `src/Service/Service.cpp`)
- System service → Board HAL: controls power and LEDs (evidence: `src/Service/Service.cpp`)
- Web management → Event bus: uses event bus (evidence: `src/Service/AP_Web.cpp`)
- Wi-Fi access point → Web management: serves management
- Web administrator → Web management: manages firmware (evidence: `README.md`)
- BLE service → BLE host device: communicates (evidence: `README.md`)
- Wand user → Gesture app dispatcher: gestures and presses (evidence: `README.md`)
- Board HAL → Power and battery: exposes power APIs (evidence: `src/HAL/HAL.h`)
