# s0lidstat3/dendrite architecture

> Architecture diagram of the GitHub repository s0lidstat3/dendrite, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/s0lidstat3/dendrite
- Repository: https://github.com/s0lidstat3/dendrite

## Overview

##### Project type and purpose
- This is a hardware-centric embedded system with two cooperating firmware modules (on ESP32-C3 and ESP32-S3) plus PC-side Python tooling.

##### File structure
- Top-level:
- docs/ – calibration, wiring, protocol, quickstart, troubleshooting
- firmware/ – two ESP32 platforms
- prototyping_tools/ – Python scripts for calibration and visualization
- firmware/esp32-c3-scanner:
- debug_serial/ – prototype mode, outputs direction data via serial
- production_i2c_slave/ – production mode, acts as I2C slave sending direction
- firmware/esp32-s3-wled-usermod:
- WLED core + custom usermod to overlay direction on existing animations
- PlatformIO config files, usermod source under WLED/usermods
- prototyping_tools:
- calibration/ – interactive BLE angle calibration (calibration.py)
- radar_visualizer/ – serial data visualizer (Prototype_Python_Serial_Visualizer.py)

##### Readme insights
- System overview: BLE scanner feeds direction data; WLED usermod changes presets and lights LEDs.
- External dependencies: WLED firmware on ESP32-S3, Arduino/PlatformIO builds, Python 3 for tools.
- Communication protocol documented in docs/protocol_spec.md

##### Main components
a. Hardware
- BLE Antenna array (hardhat)
- ESP32-C3 (BLE scanner MCU)
- ESP32-S3 (WLED MCU plus LED driver)
- LED strip (e.g., WS2812)
- Power supply / battery / level shifter (if any)
b. Firmware modules
- esp32-c3-scanner (two build variants):
– Debug mode: UART TX of direction data
– Production mode: I2C slave providing direction registers
- esp32-s3-wled-usermod:
– WLED core engine
– Custom usermod for BLE direction overlay
– Preset loader (idle/detected JSON)
c. PC-side tools (optional external components)
- Calibration script (calibration.py) – USB-serial to ESP32-C3 for calibration angles

##### Relationships and data flow
- BLE antenna array → analog front-end (antenna switching) → ESP32-C3
- ESP32-C3 scans BLE RSSI, computes angle
- In debug mode: angle → UART → PC visualizer
- In production: angle → I2C → ESP32-S3 usermod
- ESP32-S3 usermod receives angle, selects preset, overlays white LEDs on LED strip
- LED strip displays combined WLED animation + direction indicator
- PC tools (calibration) ↔ USB-serial ↔ ESP32-C3 for tuning antenna angle offsets

##### Architectural patterns and design principles
- Separation of concerns:
- Scanning and angle computation on a dedicated MCU (ESP32-C3)
- Visualization and LED control on another MCU (ESP32-S3) running a mature LED firmware (WLED)
- Extensibility via WLED usermod API
- Modularity: two firmware builds for pre-production vs production; clear protocol (docs/protocol_spec.md)
- Reusable PC tools separated from embedded code

##### Technologies, frameworks, libraries
- Arduino/PlatformIO for ESP32 builds
- WLED open-source LED controller
- Custom C++ usermods in WLED
- Python 3 for calibration & visualization tools
- I2C and UART hardware interfaces

##### Diagramming recommendations
- Labels:
- Clouds for external docs/protocol spec

## Diagram (Mermaid)

```mermaid
graph TB
    %% Hardware components
    AntennaArray["BLE Antenna Array"]:::hardware
    AnalogFE["Antenna Switching Front-End"]:::hardware
    Power["Power Supply / Battery"]:::hardware

    %% ESP32-C3 Scanner
    subgraph "ESP32-C3 Scanner"
        ScannerDebug["Debug Mode (UART)"]:::mcu
        ScannerProd["Production Mode (I2C Slave)"]:::mcu
    end

    %% ESP32-S3 WLED MCU
    subgraph "ESP32-S3 WLED MCU"
        WLEDCore["WLED Core Firmware"]:::mcu
        Usermod["Custom I2C Direction Usermod"]:::mcu
        I2CDebug["I2C Debug Sketch"]:::mcu
        Presets[(WLED Presets JSON)]:::presets
        LEDStrip["LED Strip (WS2812)"]:::hardware
    end

    %% PC-Side Tools
    subgraph "PC-Side Tools"
        Calibration["Calibration Script"]:::pc
        Visualizer["Radar Visualizer"]:::pc
    end

    %% Documentation
    subgraph "Documentation"
        CalGuide["Calibration Guide"]:::docs
        HWWire["Hardware Wiring Diagram"]:::docs
        ProtSpec["Protocol Spec"]:::docs
        Quickstart["Quickstart Instructions"]:::docs
        Troubleshoot["Troubleshooting"]:::docs
    end

    %% Data flow
    AntennaArray --> AnalogFE
    AnalogFE --> ScannerDebug
    AnalogFE --> ScannerProd
    Power --> ScannerDebug
    Power --> ScannerProd
    ScannerDebug -->|"UART (Serial)"| Visualizer
    ScannerProd -->|"I2C"| Usermod
    Usermod --> WLEDCore
    WLEDCore --> Presets
    Usermod --> LEDStrip
    WLEDCore --> LEDStrip
    Calibration -.->|"USB-Serial"| ScannerDebug
    Calibration -.->|"USB-Serial"| ScannerProd

    %% Click Events
    click CalGuide "https://github.com/s0lidstat3/dendrite/blob/main/docs/calibration_guide.md"
    click HWWire "https://github.com/s0lidstat3/dendrite/blob/main/docs/hardware_wiring.md"
    click ProtSpec "https://github.com/s0lidstat3/dendrite/blob/main/docs/protocol_spec.md"
    click Quickstart "https://github.com/s0lidstat3/dendrite/blob/main/docs/quickstart.md"
    click Troubleshoot "https://github.com/s0lidstat3/dendrite/blob/main/docs/troubleshooting.md"
    click ScannerDebug "https://github.com/s0lidstat3/dendrite/blob/main/firmware/esp32-c3-scanner/debug_serial/scanner_debug_serial.ino"
    click ScannerProd "https://github.com/s0lidstat3/dendrite/blob/main/firmware/esp32-c3-scanner/production_i2c_slave/production_i2c_scanner.ino"
    click WLEDCore "https://github.com/s0lidstat3/dendrite/tree/main/firmware/esp32-s3-wled-usermod/WLED/"
    click Usermod "https://github.com/s0lidstat3/dendrite/blob/main/firmware/esp32-s3-wled-usermod/WLED/usermods/usermod_i2c_direction_v1/usermod_i2c_direction_v1.cpp"
    click I2CDebug "https://github.com/s0lidstat3/dendrite/blob/main/firmware/esp32-s3-wled-usermod/s3_main_i2c_debug/s3_main_i2c_debug.ino"
    click Presets "https://github.com/s0lidstat3/dendrite/blob/main/presets/README.md"
    click Calibration "https://github.com/s0lidstat3/dendrite/blob/main/prototyping_tools/calibration/calibration.py"
    click Visualizer "https://github.com/s0lidstat3/dendrite/blob/main/prototyping_tools/radar_visualizer/Prototype_Python_Serial_Visualizer.py"

    %% Styles
    classDef hardware fill:#FCF3CF,stroke:#C39BD3,stroke-width:1px
    classDef mcu fill:#D6EAF8,stroke:#1F618D,stroke-width:1px
    classDef pc fill:#D5F5E3,stroke:#145A32,stroke-width:1px
    classDef docs fill:#E8DAEF,stroke:#7D3C98,stroke-width:1px
    classDef presets fill:#FADBD8,stroke:#943126,stroke-width:1px
```
