# meatro/openhaldex-s3 architecture

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

- Interactive diagram: https://gitdiagram.com/meatro/openhaldex-s3
- Repository: https://github.com/meatro/openhaldex-s3

## Overview

OpenHaldex-S3 is an ESP32-S3 inline AWD controller for Haldex-equipped VAG vehicles. The principal workflow bridges chassis and Haldex CAN traffic, interprets vehicle signals, computes a selected lock behavior, and sends controller traffic; users configure modes and inspect telemetry through the built-in web UI. The firmware also provides Haldex diagnostics, CAN View, logging, Wi-Fi, OTA updates, and parked sleep. Edges use the shown startup calls or README descriptions; several runtime modules were indexed but not excerpted, so their internal call links are omitted.

Main entry points: [`src/functions/can/can_rx.cpp`](https://github.com/meatro/openhaldex-s3/blob/main/src/functions/can/can_rx.cpp) (CAN receive and bridge), [`src/functions/api/api.cpp`](https://github.com/meatro/openhaldex-s3/blob/main/src/functions/api/api.cpp) (Control API), [`src/functions/core/state.cpp`](https://github.com/meatro/openhaldex-s3/blob/main/src/functions/core/state.cpp) (Mode and telemetry state), [`src/functions/power/power.cpp`](https://github.com/meatro/openhaldex-s3/blob/main/src/functions/power/power.cpp) (Sleep and power)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Web interface"]
  node_ui["Web UI<br/>[app.js]"]
  node_web["Web server<br/>[web.cpp]"]
  node_api["Control API<br/>[api.cpp]"]
end

subgraph group_control["AWD control"]
  node_calcs["Lock calculations<br/>[calcs.cpp]"]
  node_lockdata["Lock modes and maps<br/>[lock_data.cpp]"]
end

subgraph group_vehicle["Vehicle communication"]
  node_canbus["CAN bus setup<br/>[can_bus.cpp]"]
  node_canrx["CAN receive and bridge<br/>[can_rx.cpp]"]
  node_cantx["CAN transmit<br/>[can_tx.cpp]"]
  node_standalone["Standalone CAN<br/>[standalone_can.cpp]"]
  node_frames["Frame generation<br/>[frames.cpp]"]
  node_canview["CAN View<br/>[canview.cpp]"]
  node_pqdbc["PQ DBC decoding"]
  node_mqbdbc["MQB DBC decoding"]
  node_uds["Haldex diagnostics<br/>[uds.cpp]"]
end

subgraph group_services["Device services"]
  node_tasks["Runtime tasks<br/>[tasks.cpp]"]
  node_power["Sleep and power<br/>[power.cpp]"]
  node_update["OTA updates<br/>[update.cpp]"]
end

subgraph group_state["State and persistence"]
  node_state["Mode and telemetry state<br/>[state.cpp]"]
  node_storage[("Settings and maps<br/>[storage.cpp]")]
  node_filelog[("Logs<br/>[filelog.cpp]")]
end

node_driver(("Vehicle user"))
node_vehiclehw{{"Vehicle CAN and Haldex"}}
node_browser(("Browser"))

node_driver -->|"uses"| node_browser
node_browser -.->|"loads interface"| node_ui
node_ui -->|"controls and queries"| node_api
node_web -->|"registers routes"| node_api
node_api -.->|"serves control"| node_state
node_api -.->|"manages settings"| node_storage
node_api -.->|"serves CAN View"| node_canview
node_tasks -.->|"updates behavior"| node_calcs
node_tasks -.->|"schedules frames"| node_frames
node_lockdata -.->|"provides lock modes"| node_calcs
node_canrx -.->|"updates telemetry"| node_state
node_canrx -.->|"feeds frame view"| node_canview
node_canrx -.->|"observes diagnostic frames"| node_uds
node_canrx -.->|"tracks chassis activity"| node_power
node_frames -.->|"sends generated frames"| node_cantx
node_canbus -.->|"initializes buses"| node_vehiclehw
node_canrx -->|"bridges and modifies traffic"| node_vehiclehw
node_pqdbc -.->|"decodes PQ frames"| node_canview
node_mqbdbc -.->|"decodes MQB frames"| node_canview
node_uds -->|"diagnoses Haldex"| node_vehiclehw
node_api -.->|"exposes logs"| node_filelog
node_filelog -.->|"uses persistent storage"| node_storage
node_power -.->|"loads power settings"| node_storage
node_update -.->|"reports update status"| node_browser
node_tasks -.->|"runs controller tasks"| node_state
node_vehiclehw -->|"provides bus traffic"| node_canrx
node_state -.->|"supplies mode inputs"| node_calcs
node_api -.->|"exposes diagnostics"| node_uds
node_api -.->|"exposes OTA controls"| node_update
node_api -.->|"exposes power status"| node_power
node_driver -->|"configures controller"| node_ui
node_vehiclehw -->|"returns vehicle frames"| node_canrx
node_canrx -.->|"relays selected traffic"| node_cantx
node_state -.->|"persists configuration"| node_storage
node_canrx -.->|"selects chassis decoding"| node_pqdbc
node_canrx -.->|"selects chassis decoding"| node_mqbdbc
node_power -.->|"manages low-power bus"| node_vehiclehw
node_update -.->|"updates firmware"| node_vehiclehw

click node_ui "https://github.com/meatro/openhaldex-s3/blob/main/data/app.js"
click node_web "https://github.com/meatro/openhaldex-s3/blob/main/src/functions/web/web.cpp"
click node_api "https://github.com/meatro/openhaldex-s3/blob/main/src/functions/api/api.cpp"
click node_tasks "https://github.com/meatro/openhaldex-s3/blob/main/src/functions/tasks/tasks.cpp"
click node_state "https://github.com/meatro/openhaldex-s3/blob/main/src/functions/core/state.cpp"
click node_calcs "https://github.com/meatro/openhaldex-s3/blob/main/src/functions/core/calcs.cpp"
click node_lockdata "https://github.com/meatro/openhaldex-s3/blob/main/src/functions/can/lock_data.cpp"
click node_canbus "https://github.com/meatro/openhaldex-s3/blob/main/src/functions/can/can_bus.cpp"
click node_canrx "https://github.com/meatro/openhaldex-s3/blob/main/src/functions/can/can_rx.cpp"
click node_cantx "https://github.com/meatro/openhaldex-s3/blob/main/src/functions/can/can_tx.cpp"
click node_standalone "https://github.com/meatro/openhaldex-s3/blob/main/src/functions/can/standalone_can.cpp"
click node_frames "https://github.com/meatro/openhaldex-s3/blob/main/src/functions/io/frames.cpp"
click node_canview "https://github.com/meatro/openhaldex-s3/blob/main/src/functions/canview/canview.cpp"
click node_pqdbc "https://github.com/meatro/openhaldex-s3/blob/main/src/functions/canview/vw_pq_chassis_dbc.cpp"
click node_mqbdbc "https://github.com/meatro/openhaldex-s3/blob/main/src/functions/canview/vw_mqb_chassis_dbc.cpp"
click node_uds "https://github.com/meatro/openhaldex-s3/blob/main/src/functions/diag/uds.cpp"
click node_storage "https://github.com/meatro/openhaldex-s3/blob/main/src/functions/storage/storage.cpp"
click node_filelog "https://github.com/meatro/openhaldex-s3/blob/main/src/functions/storage/filelog.cpp"
click node_power "https://github.com/meatro/openhaldex-s3/blob/main/src/functions/power/power.cpp"
click node_update "https://github.com/meatro/openhaldex-s3/blob/main/src/functions/net/update.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_ui,node_web,node_api,node_driver,node_browser toneBlue
class node_calcs,node_lockdata toneAmber
class node_canbus,node_canrx,node_cantx,node_standalone,node_frames,node_canview,node_pqdbc,node_mqbdbc,node_uds toneMint
class node_tasks,node_power,node_update toneRose
class node_state,node_storage,node_filelog,node_vehiclehw toneIndigo
```

## Components

### Web interface

- [Web UI](https://github.com/meatro/openhaldex-s3/blob/main/data/app.js): `data/app.js`
- [Web server](https://github.com/meatro/openhaldex-s3/blob/main/src/functions/web/web.cpp): `src/functions/web/web.cpp`
- [Control API](https://github.com/meatro/openhaldex-s3/blob/main/src/functions/api/api.cpp): `src/functions/api/api.cpp`

### AWD control

- [Lock calculations](https://github.com/meatro/openhaldex-s3/blob/main/src/functions/core/calcs.cpp): `src/functions/core/calcs.cpp`
- [Lock modes and maps](https://github.com/meatro/openhaldex-s3/blob/main/src/functions/can/lock_data.cpp): `src/functions/can/lock_data.cpp`

### Vehicle communication

- [CAN bus setup](https://github.com/meatro/openhaldex-s3/blob/main/src/functions/can/can_bus.cpp): `src/functions/can/can_bus.cpp`
- [CAN receive and bridge](https://github.com/meatro/openhaldex-s3/blob/main/src/functions/can/can_rx.cpp): `src/functions/can/can_rx.cpp`
- [CAN transmit](https://github.com/meatro/openhaldex-s3/blob/main/src/functions/can/can_tx.cpp): `src/functions/can/can_tx.cpp`
- [Standalone CAN](https://github.com/meatro/openhaldex-s3/blob/main/src/functions/can/standalone_can.cpp): `src/functions/can/standalone_can.cpp`
- [Frame generation](https://github.com/meatro/openhaldex-s3/blob/main/src/functions/io/frames.cpp): `src/functions/io/frames.cpp`
- [CAN View](https://github.com/meatro/openhaldex-s3/blob/main/src/functions/canview/canview.cpp): `src/functions/canview/canview.cpp`
- [PQ DBC decoding](https://github.com/meatro/openhaldex-s3/blob/main/src/functions/canview/vw_pq_chassis_dbc.cpp): `src/functions/canview/vw_pq_chassis_dbc.cpp`
- [MQB DBC decoding](https://github.com/meatro/openhaldex-s3/blob/main/src/functions/canview/vw_mqb_chassis_dbc.cpp): `src/functions/canview/vw_mqb_chassis_dbc.cpp`
- [Haldex diagnostics](https://github.com/meatro/openhaldex-s3/blob/main/src/functions/diag/uds.cpp): `src/functions/diag/uds.cpp`

### Device services

- [Runtime tasks](https://github.com/meatro/openhaldex-s3/blob/main/src/functions/tasks/tasks.cpp): `src/functions/tasks/tasks.cpp`
- [Sleep and power](https://github.com/meatro/openhaldex-s3/blob/main/src/functions/power/power.cpp): `src/functions/power/power.cpp`
- [OTA updates](https://github.com/meatro/openhaldex-s3/blob/main/src/functions/net/update.cpp): `src/functions/net/update.cpp`

### State and persistence

- [Mode and telemetry state](https://github.com/meatro/openhaldex-s3/blob/main/src/functions/core/state.cpp): `src/functions/core/state.cpp`
- [Settings and maps](https://github.com/meatro/openhaldex-s3/blob/main/src/functions/storage/storage.cpp): `src/functions/storage/storage.cpp`
- [Logs](https://github.com/meatro/openhaldex-s3/blob/main/src/functions/storage/filelog.cpp): `src/functions/storage/filelog.cpp`

### Other components

- **Vehicle user**
- **Vehicle CAN and Haldex**
- **Browser**

## Connections

- Vehicle user → Browser: uses
- Browser → Web UI: loads interface
- Web UI → Control API: controls and queries
- Web server → Control API: registers routes
- Control API → Mode and telemetry state: serves control
- Control API → Settings and maps: manages settings
- Control API → CAN View: serves CAN View
- Runtime tasks → Lock calculations: updates behavior
- Runtime tasks → Frame generation: schedules frames
- Lock modes and maps → Lock calculations: provides lock modes
- CAN receive and bridge → Mode and telemetry state: updates telemetry
- CAN receive and bridge → CAN View: feeds frame view
- CAN receive and bridge → Haldex diagnostics: observes diagnostic frames
- CAN receive and bridge → Sleep and power: tracks chassis activity
- Frame generation → CAN transmit: sends generated frames
- CAN bus setup → Vehicle CAN and Haldex: initializes buses
- CAN receive and bridge → Vehicle CAN and Haldex: bridges and modifies traffic
- PQ DBC decoding → CAN View: decodes PQ frames
- MQB DBC decoding → CAN View: decodes MQB frames
- Haldex diagnostics → Vehicle CAN and Haldex: diagnoses Haldex
- Control API → Logs: exposes logs
- Logs → Settings and maps: uses persistent storage
- Sleep and power → Settings and maps: loads power settings
- OTA updates → Browser: reports update status
- Runtime tasks → Mode and telemetry state: runs controller tasks
- Vehicle CAN and Haldex → CAN receive and bridge: provides bus traffic
- Mode and telemetry state → Lock calculations: supplies mode inputs
- Control API → Haldex diagnostics: exposes diagnostics
- Control API → OTA updates: exposes OTA controls
- Control API → Sleep and power: exposes power status
- Vehicle user → Web UI: configures controller
- Vehicle CAN and Haldex → CAN receive and bridge: returns vehicle frames
- CAN receive and bridge → CAN transmit: relays selected traffic
- Mode and telemetry state → Settings and maps: persists configuration
- CAN receive and bridge → PQ DBC decoding: selects chassis decoding
- CAN receive and bridge → MQB DBC decoding: selects chassis decoding
- Sleep and power → Vehicle CAN and Haldex: manages low-power bus
- OTA updates → Vehicle CAN and Haldex: updates firmware
