# zou-shui/muggleswand-src architecture

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

- Interactive diagram: https://gitdiagram.com/zou-shui/muggleswand-src
- Repository: https://github.com/zou-shui/muggleswand-src

## Overview

Muggles’ Wand is ESP32-S3 wand firmware. Its principal workflow samples motion, buffers gesture data, runs TensorFlow Lite inference, publishes detected gestures, and dispatches them to wand actions such as lighting, BLE HID, ESP-NOW, or POV drawing. The event bus also connects hardware and system services. The README documents AP/Web management and OTA; those capabilities are included, though their complete runtime wiring is not shown in the excerpts. Edges reflect shown calls, references, or README statements; unsampled details are not inferred.

Main entry points: [`src/Service/Service.cpp`](https://github.com/zou-shui/muggleswand-src/blob/main/src/Service/Service.cpp) (System Service), [`src/APP/APP.cpp`](https://github.com/zou-shui/muggleswand-src/blob/main/src/APP/APP.cpp) (App Dispatcher), [`src/Service/EventBus.h`](https://github.com/zou-shui/muggleswand-src/blob/main/src/Service/EventBus.h) (Event Bus), [`src/main.cpp`](https://github.com/zou-shui/muggleswand-src/blob/main/src/main.cpp) (Startup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Firmware Runtime"]
  node_main["Startup<br/>[main.cpp]"]
  node_bus["Event Bus<br/>[EventBus.h]"]
end

subgraph group_motion["Motion Recognition"]
  node_gesture_buffer["Gesture Buffer<br/>[gesture_buffer.cpp]"]
  node_inference["Gesture Inference"]
  node_model["TFLite Model<br/>[gesture_model.h]"]
end

subgraph group_hardware["Hardware Layer"]
  node_imu["IMU Sampling<br/>[HAL_IMU.cpp]"]
  node_imu_driver["ICM42670P Driver<br/>[HAL_ICM42670P.cpp]"]
  node_led_hal["LED Animation HAL<br/>[HAL_WS2812.cpp]"]
  node_animation_base["Animation Engine<br/>[AnimationBase.hpp]"]
  node_power["Power Management<br/>[HAL_Power.cpp]"]
  node_button["Button Input<br/>[HAL_Button.cpp]"]
end

subgraph group_apps["Wand Applications"]
  node_app_dispatch["App Dispatcher<br/>[APP.cpp]"]
  node_lumos["Lumos<br/>[APP_Lumos.cpp]"]
  node_ble_hid["BLE HID<br/>[APP_BLE_HID.cpp]"]
  node_espnow["ESP-NOW Actions<br/>[APP_EspNow.cpp]"]
  node_pov["POV Drawing<br/>[APP_POV.cpp]"]
  node_pov_patterns["POV Patterns<br/>[APP_POVPatterns.h]"]
end

subgraph group_services["System Services"]
  node_service["System Service<br/>[Service.cpp]"]
  node_console["Serial Console<br/>[Console.cpp]"]
  node_ble_service["BLE Service<br/>[BLE.cpp]"]
  node_ap["Wi-Fi Access Point<br/>[AP.cpp]"]
  node_web["Web Management<br/>[AP_Web.cpp]"]
  node_ota["OTA Update<br/>[OTA.cpp]"]
  node_sleep["Sleep Service<br/>[Sleep.cpp]"]
end

node_user(("Wand User"))
node_ble_host(("BLE Host"))
node_browser(("Browser"))

node_user -->|"moves wand"| node_imu
node_main -->|"initializes"| node_bus
node_main -->|"starts"| node_service
node_main -->|"starts"| node_inference
node_main -->|"initializes"| node_imu_driver
node_main -->|"initializes"| node_app_dispatch
node_imu -->|"fills buffer"| node_gesture_buffer
node_imu -->|"publishes data"| node_bus
node_imu -->|"reads sensor"| node_imu_driver
node_inference -->|"acquires samples"| node_gesture_buffer
node_inference -->|"loads model"| node_model
node_inference -->|"publishes gesture"| node_bus
node_bus -->|"delivers events"| node_app_dispatch
node_app_dispatch -->|"starts effects"| node_led_hal
node_app_dispatch -->|"sends signals"| node_espnow
node_app_dispatch -->|"dispatches controls"| node_ble_hid
node_app_dispatch -->|"triggers"| node_lumos
node_app_dispatch -->|"controls mode"| node_pov
node_pov -->|"uses patterns"| node_pov_patterns
node_pov -->|"renders drawing"| node_led_hal
node_led_hal -->|"manages animations"| node_animation_base
node_button -.->|"reports presses"| node_bus
node_service -->|"subscribes"| node_bus
node_service -->|"toggles"| node_ble_service
node_service -->|"toggles"| node_ap
node_service -->|"starts update"| node_ota
node_service -->|"enters sleep"| node_sleep
node_service -->|"reads status"| node_power
node_console -.->|"issues commands"| node_bus
node_ap -.->|"serves management"| node_web
node_web -->|"accepts firmware"| node_ota
node_browser -->|"uploads firmware"| node_web
node_ble_hid -->|"uses BLE"| node_ble_service
node_ble_service -.->|"connects"| node_ble_host

click node_main "https://github.com/zou-shui/muggleswand-src/blob/main/src/main.cpp"
click node_bus "https://github.com/zou-shui/muggleswand-src/blob/main/src/Service/EventBus.h"
click node_app_dispatch "https://github.com/zou-shui/muggleswand-src/blob/main/src/APP/APP.cpp"
click node_imu "https://github.com/zou-shui/muggleswand-src/blob/main/src/HAL/HAL_IMU.cpp"
click node_imu_driver "https://github.com/zou-shui/muggleswand-src/blob/main/src/HAL/HAL_ICM42670P.cpp"
click node_gesture_buffer "https://github.com/zou-shui/muggleswand-src/blob/main/src/Model/gesture_buffer.cpp"
click node_inference "https://github.com/zou-shui/muggleswand-src/blob/main/src/Model/gesture_inference.cpp"
click node_model "https://github.com/zou-shui/muggleswand-src/blob/main/src/Model/gesture_model.h"
click node_lumos "https://github.com/zou-shui/muggleswand-src/blob/main/src/APP/APP_Lumos.cpp"
click node_ble_hid "https://github.com/zou-shui/muggleswand-src/blob/main/src/APP/APP_BLE_HID.cpp"
click node_espnow "https://github.com/zou-shui/muggleswand-src/blob/main/src/APP/APP_EspNow.cpp"
click node_pov "https://github.com/zou-shui/muggleswand-src/blob/main/src/APP/APP_POV.cpp"
click node_pov_patterns "https://github.com/zou-shui/muggleswand-src/blob/main/src/APP/APP_POVPatterns.h"
click node_led_hal "https://github.com/zou-shui/muggleswand-src/blob/main/src/HAL/HAL_WS2812.cpp"
click node_animation_base "https://github.com/zou-shui/muggleswand-src/blob/main/src/HAL/WS2812_Animation/AnimationBase.hpp"
click node_power "https://github.com/zou-shui/muggleswand-src/blob/main/src/HAL/HAL_Power.cpp"
click node_button "https://github.com/zou-shui/muggleswand-src/blob/main/src/HAL/HAL_Button.cpp"
click node_service "https://github.com/zou-shui/muggleswand-src/blob/main/src/Service/Service.cpp"
click node_console "https://github.com/zou-shui/muggleswand-src/blob/main/src/Service/Console.cpp"
click node_ble_service "https://github.com/zou-shui/muggleswand-src/blob/main/src/Service/BLE.cpp"
click node_ap "https://github.com/zou-shui/muggleswand-src/blob/main/src/Service/AP.cpp"
click node_web "https://github.com/zou-shui/muggleswand-src/blob/main/src/Service/AP_Web.cpp"
click node_ota "https://github.com/zou-shui/muggleswand-src/blob/main/src/Service/OTA.cpp"
click node_sleep "https://github.com/zou-shui/muggleswand-src/blob/main/src/Service/Sleep.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_main,node_bus,node_user,node_browser toneBlue
class node_gesture_buffer,node_inference,node_model toneAmber
class node_imu,node_imu_driver,node_led_hal,node_animation_base,node_power,node_button toneMint
class node_app_dispatch,node_lumos,node_ble_hid,node_espnow,node_pov,node_pov_patterns toneRose
class node_service,node_console,node_ble_service,node_ap,node_web,node_ota,node_sleep,node_ble_host toneIndigo
```

## Components

### Firmware Runtime

- [Startup](https://github.com/zou-shui/muggleswand-src/blob/main/src/main.cpp): `src/main.cpp`
- [Event Bus](https://github.com/zou-shui/muggleswand-src/blob/main/src/Service/EventBus.h): `src/Service/EventBus.h`

### Motion Recognition

- [Gesture Buffer](https://github.com/zou-shui/muggleswand-src/blob/main/src/Model/gesture_buffer.cpp): `src/Model/gesture_buffer.cpp`
- [Gesture Inference](https://github.com/zou-shui/muggleswand-src/blob/main/src/Model/gesture_inference.cpp): `src/Model/gesture_inference.cpp`
- [TFLite Model](https://github.com/zou-shui/muggleswand-src/blob/main/src/Model/gesture_model.h): `src/Model/gesture_model.h`

### Hardware Layer

- [IMU Sampling](https://github.com/zou-shui/muggleswand-src/blob/main/src/HAL/HAL_IMU.cpp): `src/HAL/HAL_IMU.cpp`
- [ICM42670P Driver](https://github.com/zou-shui/muggleswand-src/blob/main/src/HAL/HAL_ICM42670P.cpp): `src/HAL/HAL_ICM42670P.cpp`
- [LED Animation HAL](https://github.com/zou-shui/muggleswand-src/blob/main/src/HAL/HAL_WS2812.cpp): `src/HAL/HAL_WS2812.cpp`
- [Animation Engine](https://github.com/zou-shui/muggleswand-src/blob/main/src/HAL/WS2812_Animation/AnimationBase.hpp): `src/HAL/WS2812_Animation/AnimationBase.hpp`
- [Power Management](https://github.com/zou-shui/muggleswand-src/blob/main/src/HAL/HAL_Power.cpp): `src/HAL/HAL_Power.cpp`
- [Button Input](https://github.com/zou-shui/muggleswand-src/blob/main/src/HAL/HAL_Button.cpp): `src/HAL/HAL_Button.cpp`

### Wand Applications

- [App Dispatcher](https://github.com/zou-shui/muggleswand-src/blob/main/src/APP/APP.cpp): `src/APP/APP.cpp`
- [Lumos](https://github.com/zou-shui/muggleswand-src/blob/main/src/APP/APP_Lumos.cpp): `src/APP/APP_Lumos.cpp`
- [BLE HID](https://github.com/zou-shui/muggleswand-src/blob/main/src/APP/APP_BLE_HID.cpp): `src/APP/APP_BLE_HID.cpp`
- [ESP-NOW Actions](https://github.com/zou-shui/muggleswand-src/blob/main/src/APP/APP_EspNow.cpp): `src/APP/APP_EspNow.cpp`
- [POV Drawing](https://github.com/zou-shui/muggleswand-src/blob/main/src/APP/APP_POV.cpp): `src/APP/APP_POV.cpp`
- [POV Patterns](https://github.com/zou-shui/muggleswand-src/blob/main/src/APP/APP_POVPatterns.h): `src/APP/APP_POVPatterns.h`

### System Services

- [System Service](https://github.com/zou-shui/muggleswand-src/blob/main/src/Service/Service.cpp): `src/Service/Service.cpp`
- [Serial Console](https://github.com/zou-shui/muggleswand-src/blob/main/src/Service/Console.cpp): `src/Service/Console.cpp`
- [BLE Service](https://github.com/zou-shui/muggleswand-src/blob/main/src/Service/BLE.cpp): `src/Service/BLE.cpp`
- [Wi-Fi Access Point](https://github.com/zou-shui/muggleswand-src/blob/main/src/Service/AP.cpp): `src/Service/AP.cpp`
- [Web Management](https://github.com/zou-shui/muggleswand-src/blob/main/src/Service/AP_Web.cpp): `src/Service/AP_Web.cpp`
- [OTA Update](https://github.com/zou-shui/muggleswand-src/blob/main/src/Service/OTA.cpp): `src/Service/OTA.cpp`
- [Sleep Service](https://github.com/zou-shui/muggleswand-src/blob/main/src/Service/Sleep.cpp): `src/Service/Sleep.cpp`

### Other components

- **Wand User**
- **BLE Host**
- **Browser**

## Connections

- Wand User → IMU Sampling: moves wand
- Startup → Event Bus: initializes (evidence: `src/main.cpp`)
- Startup → System Service: starts (evidence: `src/main.cpp`)
- Startup → Gesture Inference: starts (evidence: `src/main.cpp`)
- Startup → ICM42670P Driver: initializes (evidence: `src/main.cpp`)
- Startup → App Dispatcher: initializes (evidence: `src/main.cpp`)
- IMU Sampling → Gesture Buffer: fills buffer (evidence: `src/HAL/HAL_IMU.cpp`)
- IMU Sampling → Event Bus: publishes data (evidence: `src/HAL/HAL_IMU.cpp`)
- IMU Sampling → ICM42670P Driver: reads sensor (evidence: `src/HAL/HAL_IMU.cpp`)
- Gesture Inference → Gesture Buffer: acquires samples (evidence: `src/Model/gesture_inference.cpp`)
- Gesture Inference → TFLite Model: loads model (evidence: `src/Model/gesture_inference.cpp`)
- Gesture Inference → Event Bus: publishes gesture (evidence: `src/Model/gesture_inference.cpp`)
- Event Bus → App Dispatcher: delivers events (evidence: `src/APP/APP.cpp`)
- App Dispatcher → LED Animation HAL: starts effects (evidence: `src/APP/APP.cpp`)
- App Dispatcher → ESP-NOW Actions: sends signals (evidence: `src/APP/APP.cpp`)
- App Dispatcher → BLE HID: dispatches controls (evidence: `src/APP/APP.cpp`)
- App Dispatcher → Lumos: triggers (evidence: `src/APP/APP.cpp`)
- App Dispatcher → POV Drawing: controls mode (evidence: `src/APP/APP.cpp`)
- POV Drawing → POV Patterns: uses patterns (evidence: `src/APP/APP_POV.cpp`)
- POV Drawing → LED Animation HAL: renders drawing (evidence: `src/APP/APP_POV.cpp`)
- LED Animation HAL → Animation Engine: manages animations (evidence: `src/HAL/HAL_WS2812.cpp`)
- Button Input → Event Bus: reports presses
- System Service → Event Bus: subscribes (evidence: `src/Service/Service.cpp`)
- System Service → BLE Service: toggles (evidence: `src/Service/Service.cpp`)
- System Service → Wi-Fi Access Point: toggles (evidence: `src/Service/Service.cpp`)
- System Service → OTA Update: starts update (evidence: `src/Service/Service.cpp`)
- System Service → Sleep Service: enters sleep (evidence: `src/Service/Service.cpp`)
- System Service → Power Management: reads status (evidence: `src/Service/Service.cpp`)
- Serial Console → Event Bus: issues commands
- Wi-Fi Access Point → Web Management: serves management
- Web Management → OTA Update: accepts firmware
- Browser → Web Management: uploads firmware
- BLE HID → BLE Service: uses BLE (evidence: `src/APP/APP_BLE_HID.cpp`)
- BLE Service → BLE Host: connects
