# the-guily/le-guily architecture

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

- Interactive diagram: https://gitdiagram.com/the-guily/le-guily
- Repository: https://github.com/the-guily/le-guily

## Overview

Le-Guily is a modular, two-wheeled self-balancing robot. Its principal runtime path is Zephyr firmware startup on the STM32WB55, sensor and encoder acquisition, control, and motor actuation; the base is intended to remain functional without optional extensions. The graph also preserves the documented safety, battery, BLE/telemetry, hardware, mechanical, and extension capabilities. Runtime links are based on excerpts or README statements; unsampled subsystems are represented only at supported directory or schematic paths.

Main entry points: [`SW/src/app/control/control.c`](https://github.com/the-guily/le-guily/blob/main/SW/src/app/control/control.c) (Control thread), [`SW/src/main.c`](https://github.com/the-guily/le-guily/blob/main/SW/src/main.c) (Firmware startup), [`SW/src/drivers/imu/imu.c`](https://github.com/the-guily/le-guily/blob/main/SW/src/drivers/imu/imu.c) (IMU driver), [`SW/src/drivers/motor/motor.c`](https://github.com/the-guily/le-guily/blob/main/SW/src/drivers/motor/motor.c) (Motor driver)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_firmware["Firmware application"]
  node_zephyr["Zephyr runtime"]
  node_entry["Firmware startup<br/>[main.c]"]
  node_control_thread["Control thread<br/>[control.c]"]
  node_safety["Safety management<br/>[safety.c]"]
  node_module_manager["Module manager<br/>[module_manager.c]"]
  node_telemetry["Telemetry<br/>[telemetry.c]"]
end

subgraph group_control["Control and services"]
  node_pid["PID control<br/>[pid.c]"]
  node_lqr["LQR control<br/>[lqr.c]"]
  node_motion["Motion service<br/>[motion.c]"]
  node_power["Power service<br/>[power.c]"]
end

subgraph group_drivers["Hardware drivers"]
  node_imu["IMU driver<br/>[imu.c]"]
  node_encoder["Encoder driver<br/>[encoder.c]"]
  node_motor["Motor driver<br/>[motor.c]"]
  node_battery["Battery driver<br/>[battery.c]"]
  node_ble["BLE driver<br/>[ble.c]"]
end

subgraph group_physical["Physical design"]
  node_board["Carrier electronics<br/>[Le_Guily.kicad_sch]"]
  node_mechanics["Robot mechanics"]
end

subgraph group_extensions["Extension system"]
  node_gateway["ESP32 gateway"]
  node_optional_modules["Optional modules"]
end

node_operator(("Operator"))

node_operator -.->|"sends commands"| node_ble
node_zephyr -->|"hosts firmware"| node_entry
node_entry -->|"initializes"| node_battery
node_entry -->|"initializes"| node_encoder
node_entry -->|"initializes"| node_ble
node_entry -->|"initializes"| node_imu
node_control_thread -->|"updates wheel state"| node_encoder
node_control_thread -.->|"uses control algorithm"| node_pid
node_control_thread -.->|"uses control algorithm"| node_lqr
node_control_thread -.->|"commands motors"| node_motor
node_control_thread -.->|"uses measurements"| node_imu
node_safety -.->|"manages power"| node_power
node_telemetry -->|"reads battery"| node_battery
node_telemetry -->|"sends telemetry"| node_ble
node_module_manager -.->|"manages extensions"| node_gateway
node_gateway -.->|"connects modules"| node_optional_modules
node_board -.->|"integrates"| node_imu
node_board -.->|"integrates"| node_motor
node_mechanics -.->|"houses drive hardware"| node_motor

click node_zephyr "https://github.com/the-guily/le-guily/tree/main/SW"
click node_entry "https://github.com/the-guily/le-guily/blob/main/SW/src/main.c"
click node_control_thread "https://github.com/the-guily/le-guily/blob/main/SW/src/app/control/control.c"
click node_safety "https://github.com/the-guily/le-guily/blob/main/SW/src/app/safety/safety.c"
click node_module_manager "https://github.com/the-guily/le-guily/blob/main/SW/src/app/module_manager/module_manager.c"
click node_telemetry "https://github.com/the-guily/le-guily/blob/main/SW/src/app/telemetry/telemetry.c"
click node_pid "https://github.com/the-guily/le-guily/blob/main/SW/src/algorithms/pid/pid.c"
click node_lqr "https://github.com/the-guily/le-guily/blob/main/SW/src/algorithms/lqr/lqr.c"
click node_motion "https://github.com/the-guily/le-guily/blob/main/SW/src/services/motion/motion.c"
click node_power "https://github.com/the-guily/le-guily/blob/main/SW/src/services/power/power.c"
click node_imu "https://github.com/the-guily/le-guily/blob/main/SW/src/drivers/imu/imu.c"
click node_encoder "https://github.com/the-guily/le-guily/blob/main/SW/src/drivers/encoder/encoder.c"
click node_motor "https://github.com/the-guily/le-guily/blob/main/SW/src/drivers/motor/motor.c"
click node_battery "https://github.com/the-guily/le-guily/blob/main/SW/src/drivers/battery/battery.c"
click node_ble "https://github.com/the-guily/le-guily/blob/main/SW/src/drivers/ble/ble.c"
click node_board "https://github.com/the-guily/le-guily/blob/main/HW/Le_Guily_kicad/Le_Guily.kicad_sch"
click node_mechanics "https://github.com/the-guily/le-guily/tree/main/Meca/3D"
click node_gateway "https://github.com/the-guily/le-guily/blob/main/HW/Le_Guily_kicad/extension.kicad_sch"
click node_optional_modules "https://github.com/the-guily/le-guily/blob/main/HW/Le_Guily_kicad/extension.kicad_sch"

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_zephyr,node_entry,node_control_thread,node_safety,node_module_manager,node_telemetry toneBlue
class node_pid,node_lqr,node_motion,node_power toneAmber
class node_imu,node_encoder,node_motor,node_battery,node_ble toneMint
class node_board,node_mechanics toneRose
class node_gateway,node_optional_modules,node_operator toneIndigo
```

## Components

### Firmware application

- [Zephyr runtime](https://github.com/the-guily/le-guily/tree/main/SW): `SW`
- [Firmware startup](https://github.com/the-guily/le-guily/blob/main/SW/src/main.c): `SW/src/main.c`
- [Control thread](https://github.com/the-guily/le-guily/blob/main/SW/src/app/control/control.c): `SW/src/app/control/control.c`
- [Safety management](https://github.com/the-guily/le-guily/blob/main/SW/src/app/safety/safety.c): `SW/src/app/safety/safety.c`
- [Module manager](https://github.com/the-guily/le-guily/blob/main/SW/src/app/module_manager/module_manager.c): `SW/src/app/module_manager/module_manager.c`
- [Telemetry](https://github.com/the-guily/le-guily/blob/main/SW/src/app/telemetry/telemetry.c): `SW/src/app/telemetry/telemetry.c`

### Control and services

- [PID control](https://github.com/the-guily/le-guily/blob/main/SW/src/algorithms/pid/pid.c): `SW/src/algorithms/pid/pid.c`
- [LQR control](https://github.com/the-guily/le-guily/blob/main/SW/src/algorithms/lqr/lqr.c): `SW/src/algorithms/lqr/lqr.c`
- [Motion service](https://github.com/the-guily/le-guily/blob/main/SW/src/services/motion/motion.c): `SW/src/services/motion/motion.c`
- [Power service](https://github.com/the-guily/le-guily/blob/main/SW/src/services/power/power.c): `SW/src/services/power/power.c`

### Hardware drivers

- [IMU driver](https://github.com/the-guily/le-guily/blob/main/SW/src/drivers/imu/imu.c): `SW/src/drivers/imu/imu.c`
- [Encoder driver](https://github.com/the-guily/le-guily/blob/main/SW/src/drivers/encoder/encoder.c): `SW/src/drivers/encoder/encoder.c`
- [Motor driver](https://github.com/the-guily/le-guily/blob/main/SW/src/drivers/motor/motor.c): `SW/src/drivers/motor/motor.c`
- [Battery driver](https://github.com/the-guily/le-guily/blob/main/SW/src/drivers/battery/battery.c): `SW/src/drivers/battery/battery.c`
- [BLE driver](https://github.com/the-guily/le-guily/blob/main/SW/src/drivers/ble/ble.c): `SW/src/drivers/ble/ble.c`

### Physical design

- [Carrier electronics](https://github.com/the-guily/le-guily/blob/main/HW/Le_Guily_kicad/Le_Guily.kicad_sch): `HW/Le_Guily_kicad/Le_Guily.kicad_sch`
- [Robot mechanics](https://github.com/the-guily/le-guily/tree/main/Meca/3D): `Meca/3D`

### Extension system

- [ESP32 gateway](https://github.com/the-guily/le-guily/blob/main/HW/Le_Guily_kicad/extension.kicad_sch): `HW/Le_Guily_kicad/extension.kicad_sch`
- [Optional modules](https://github.com/the-guily/le-guily/blob/main/HW/Le_Guily_kicad/extension.kicad_sch): `HW/Le_Guily_kicad/extension.kicad_sch`

### Other components

- **Operator**

## Connections

- Operator → BLE driver: sends commands (evidence: `README.md`)
- Zephyr runtime → Firmware startup: hosts firmware (evidence: `README.md`)
- Firmware startup → Battery driver: initializes (evidence: `SW/src/main.c`)
- Firmware startup → Encoder driver: initializes (evidence: `SW/src/main.c`)
- Firmware startup → BLE driver: initializes (evidence: `SW/src/main.c`)
- Firmware startup → IMU driver: initializes (evidence: `SW/src/main.c`)
- Control thread → Encoder driver: updates wheel state (evidence: `SW/src/app/control/control.c`)
- Control thread → PID control: uses control algorithm (evidence: `README.md`)
- Control thread → LQR control: uses control algorithm (evidence: `README.md`)
- Control thread → Motor driver: commands motors (evidence: `README.md`)
- Control thread → IMU driver: uses measurements (evidence: `README.md`)
- Safety management → Power service: manages power (evidence: `README.md`)
- Telemetry → Battery driver: reads battery (evidence: `SW/src/app/telemetry/telemetry.c`)
- Telemetry → BLE driver: sends telemetry (evidence: `SW/src/app/telemetry/telemetry.c`)
- Module manager → ESP32 gateway: manages extensions (evidence: `README.md`)
- ESP32 gateway → Optional modules: connects modules (evidence: `README.md`)
- Carrier electronics → IMU driver: integrates
- Carrier electronics → Motor driver: integrates
- Robot mechanics → Motor driver: houses drive hardware (evidence: `README.md`)
