# espressif/esp-brookesia architecture

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

- Interactive diagram: https://gitdiagram.com/espressif/esp-brookesia
- Repository: https://github.com/espressif/esp-brookesia

## Overview

#### Purpose and Entry Points
ESP-Brookesia is a componentized C/C++ platform for ESP-IDF AIoT/HMI devices, with Linux and WebAssembly simulation paths. Products compose HAL, services, GUI, app runtimes, system orchestration, and packaged apps rather than building a single monolith. Root build integration begins at `CMakeLists.txt`; deployable reference entry points are `examples/system/super/main/main.cpp` and `examples/agent/chatbot/main/main.cpp`.

#### Foundation and Hardware Boundary
The HAL interface defines device-agnostic contracts for audio, display, networking, storage, system, video, Wi-Fi, and power: `hal/brookesia_hal_interface/include/brookesia/hal_interface/interfaces.hpp`. ESP implementations register real peripherals via the adaptor: `hal/brookesia_hal_adaptor/src/display/device.cpp`, `hal/brookesia_hal_adaptor/src/wifi/device.cpp`. Board topology, pins, and defaults remain outside upper layers in board packages such as `hal/brookesia_hal_boards/boards/espressif/esp_box_3/board_devices.yaml`. Alternate implementations support Linux and WASM: `hal/brookesia_hal_linux/src/network/http_client_impl.cpp`, `hal/brookesia_hal_wasm/src/device.cpp`.

#### Service Execution Plane
The service manager is the principal control boundary: it owns service lifecycle, local execution, function routing, and event/function registries. See `service/framework/brookesia_service_manager/src/service/manager.cpp`, `service/framework/brookesia_service_manager/src/event/registry.cpp`, and `service/framework/brookesia_service_manager/src/function/registry.cpp`. Typed helper APIs bind callers to these services without exposing hardware implementations: `service/framework/brookesia_service_helper/include/brookesia/service_helper.hpp`.

Domain services wrap HAL capabilities with application-facing state machines and APIs: Wi-Fi/HTTP/SNTP, storage/device, display/audio/video. Representative paths: `service/network/brookesia_service_wifi/src/state_machine.cpp`, `service/network/brookesia_service_http/src/service_http.cpp`, `service/system/brookesia_service_storage/src/service_storage.cpp`.

#### GUI Pipeline
JSON UI documents, resource data, validation, bindings, and runtime mounting are defined in the GUI interface: `gui/brookesia_gui_interface/include/brookesia/gui_interface/document.hpp`, `gui/brookesia_gui_interface/src/parser.cpp`, `gui/brookesia_gui_interface/src/runtime.cpp`. The LVGL backend resolves that model into widgets, styles, events, layouts, and animations, with ESP/SDL/WASM display ports: `gui/brookesia_gui_lvgl/src/backend.cpp`, `gui/brookesia_gui_lvgl/src/factory.cpp`, `gui/brookesia_gui_lvgl/src/port/wasm/display_source.cpp`. Apps and the shell supply declarative resources under package/resource directories.

#### App Runtime and System Core
Runtime Manager loads dynamic app packages, selects registered backends, and bridges app calls to host services: `runtime/brookesia_runtime_manager/src/runtime.cpp`, `runtime/brookesia_runtime_manager/src/host_bridge.cpp`. Backends support ELF, JavaScript, Lua, and WASM; e.g. `runtime/brookesia_runtime_wasm/src/backend.cpp` and `runtime/brookesia_runtime_js/src/backend.cpp`.

System Core coordinates package scanning/verification, app lifecycle, GUI access, resources, storage, timers, and runtime/service bridges: `system/brookesia_system_core/src/app/manager.cpp`, `system/brookesia_system_core/src/app/package_scan.cpp`, `system/brookesia_system_core/src/system/lifecycle.cpp`. This is the main permission and ownership boundary between installed apps and device capabilities.

#### Product Shell and Built-in Apps
System Super layers a standard touch-device shell over Core: startup, launcher/navigation, overlays, themes, and packaged JSON resources. Its implementation and assets are `system/brookesia_system_super/src/system.cpp`, `system/brookesia_system_super/src/shell_app.cpp`, and `system/brookesia_system_super/resource/shell/root.json`. Built-in Files, Settings, and App Store components follow the app lifecycle and package-resource model; App Store additionally fetches a remote catalog and downloads/installable content: `app/brookesia_app_store/src/network/remote_index.ipp`, `app/brookesia_app_store/src/install/download.ipp`.

#### External Integrations and Delivery
ESP-IDF is the primary embedded runtime/build environment; CMake/Kconfig and `idf_component.yml` make each subsystem independently consumable through Espressif’s Component Registry. LVGL is the GUI rendering backend. External network boundaries include HTTP/HTTPS, SNTP, Wi-Fi, remote app indexes, and AI providers: Coze, OpenAI, and XiaoZhi adapters under `service/agent/brookesia_agent_openai/src/agent_openai.cpp` and `service/agent/brookesia_agent_coze/src/agent_coze.cpp`. MCP utilities expose service functions or callbacks as LLM-invocable tools: `utils/brookesia_mcp_utils/src/mcp_utils.cpp`.

Main entry points: [`system/brookesia_system_core/src/app/manager.cpp`](https://github.com/espressif/esp-brookesia/blob/master/system/brookesia_system_core/src/app/manager.cpp) (System Core), [`service/framework/brookesia_service_manager/src/service/manager.cpp`](https://github.com/espressif/esp-brookesia/blob/master/service/framework/brookesia_service_manager/src/service/manager.cpp) (Service Manager), [`hal/brookesia_hal_interface/include/brookesia/hal_interface/interfaces.hpp`](https://github.com/espressif/esp-brookesia/blob/master/hal/brookesia_hal_interface/include/brookesia/hal_interface/interfaces.hpp) (HAL Contracts), [`system/brookesia_system_super/src/system.cpp`](https://github.com/espressif/esp-brookesia/blob/master/system/brookesia_system_super/src/system.cpp) (System Super Shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_foundation["Platform Foundation"]
  node_build["ESP-IDF Component Build<br/>build integration<br/>[CMakeLists.txt]"]
  node_hal_interface{{"HAL Contracts<br/>hardware abstraction<br/>[interfaces.hpp]"}}
  node_boards["Board Definitions<br/>board package<br/>[board_devices.yaml]"]
  node_esp_adaptor["ESP HAL Adaptor<br/>ESP peripheral binding<br/>[device.cpp]"]
  node_portable_hal["Linux &amp; WASM HAL<br/>simulation implementation"]
end

subgraph group_services["Service Plane"]
  node_service_manager{{"Service Manager<br/>service control boundary<br/>[manager.cpp]"}}
  node_service_registries["Event &amp; Function Registries<br/>service dispatch<br/>[registry.cpp]"]
  node_service_helper["Service Helper API<br/>typed client API<br/>[service_helper.hpp]"]
  node_domain_services["Domain Services<br/>network, media, system services<br/>[state_machine.cpp]"]
  node_agent_services["AI Agent Adapters<br/>provider integration<br/>[agent_openai.cpp]"]
  node_mcp["MCP Utilities<br/>LLM tool bridge<br/>[mcp_utils.cpp]"]
end

subgraph group_experience["GUI &amp; Apps"]
  node_gui_model["GUI Document Runtime<br/>declarative UI model<br/>[runtime.cpp]"]
  node_lvgl["LVGL Backend<br/>GUI renderer<br/>[backend.cpp]"]
  node_system_super["System Super Shell<br/>touch device shell<br/>[system.cpp]"]
  node_shell_resources["Shell JSON Resources<br/>declarative UI assets<br/>[root.json]"]
  node_app_store["App Store<br/>built-in package app<br/>[remote_index.ipp]"]
end

subgraph group_runtime["Runtime &amp; System"]
  node_runtime_manager{{"Runtime Manager<br/>dynamic app runtime<br/>[runtime.cpp]"}}
  node_runtime_backends["App Runtime Backends<br/>ELF, JS, Lua, WASM<br/>[backend.cpp]"]
  node_system_core{{"System Core<br/>app ownership boundary<br/>[manager.cpp]"}}
  node_package_scan["Package Scan &amp; Verify<br/>package intake<br/>[package_scan.cpp]"]
  node_super_entry(("System Super Entry<br/>ESP-IDF application entry<br/>[main.cpp]"))
  node_chatbot_entry(("Chatbot Entry<br/>ESP-IDF application entry<br/>[main.cpp]"))
end

node_build -->|"builds"| node_hal_interface
node_build -->|"builds"| node_service_manager
node_build -->|"builds"| node_system_core
node_boards -->|"configures"| node_esp_adaptor
node_esp_adaptor -->|"implements"| node_hal_interface
node_portable_hal -->|"implements"| node_hal_interface
node_domain_services -->|"uses device capabilities"| node_hal_interface
node_service_registries -->|"dispatches through"| node_service_manager
node_service_manager -->|"manages"| node_domain_services
node_service_helper -->|"calls"| node_service_manager
node_agent_services -->|"uses"| node_service_helper
node_mcp -->|"exposes functions"| node_service_manager
node_lvgl -->|"renders document model"| node_gui_model
node_lvgl -->|"uses display port"| node_hal_interface
node_system_core -->|"scans packages"| node_package_scan
node_system_core -->|"owns app execution"| node_runtime_manager
node_runtime_manager -->|"selects"| node_runtime_backends
node_runtime_manager -->|"bridges host calls"| node_service_manager
node_system_core -->|"grants GUI access"| node_gui_model
node_system_super -->|"runs on"| node_system_core
node_system_super -->|"mounts"| node_shell_resources
node_system_super -->|"supplies UI"| node_gui_model
node_app_store -->|"follows app lifecycle"| node_system_core
node_app_store -->|"installs packages"| node_package_scan
node_super_entry -->|"starts"| node_system_super
node_chatbot_entry -->|"starts agent integration"| node_agent_services

click node_build "https://github.com/espressif/esp-brookesia/blob/master/CMakeLists.txt"
click node_hal_interface "https://github.com/espressif/esp-brookesia/blob/master/hal/brookesia_hal_interface/include/brookesia/hal_interface/interfaces.hpp"
click node_boards "https://github.com/espressif/esp-brookesia/blob/master/hal/brookesia_hal_boards/boards/espressif/esp_box_3/board_devices.yaml"
click node_esp_adaptor "https://github.com/espressif/esp-brookesia/blob/master/hal/brookesia_hal_adaptor/src/display/device.cpp"
click node_portable_hal "https://github.com/espressif/esp-brookesia/blob/master/hal/brookesia_hal_linux/src/network/http_client_impl.cpp"
click node_service_manager "https://github.com/espressif/esp-brookesia/blob/master/service/framework/brookesia_service_manager/src/service/manager.cpp"
click node_service_registries "https://github.com/espressif/esp-brookesia/blob/master/service/framework/brookesia_service_manager/src/function/registry.cpp"
click node_service_helper "https://github.com/espressif/esp-brookesia/blob/master/service/framework/brookesia_service_helper/include/brookesia/service_helper.hpp"
click node_domain_services "https://github.com/espressif/esp-brookesia/blob/master/service/network/brookesia_service_wifi/src/state_machine.cpp"
click node_agent_services "https://github.com/espressif/esp-brookesia/blob/master/service/agent/brookesia_agent_openai/src/agent_openai.cpp"
click node_mcp "https://github.com/espressif/esp-brookesia/blob/master/utils/brookesia_mcp_utils/src/mcp_utils.cpp"
click node_gui_model "https://github.com/espressif/esp-brookesia/blob/master/gui/brookesia_gui_interface/src/runtime.cpp"
click node_lvgl "https://github.com/espressif/esp-brookesia/blob/master/gui/brookesia_gui_lvgl/src/backend.cpp"
click node_runtime_manager "https://github.com/espressif/esp-brookesia/blob/master/runtime/brookesia_runtime_manager/src/runtime.cpp"
click node_runtime_backends "https://github.com/espressif/esp-brookesia/blob/master/runtime/brookesia_runtime_wasm/src/backend.cpp"
click node_system_core "https://github.com/espressif/esp-brookesia/blob/master/system/brookesia_system_core/src/app/manager.cpp"
click node_package_scan "https://github.com/espressif/esp-brookesia/blob/master/system/brookesia_system_core/src/app/package_scan.cpp"
click node_system_super "https://github.com/espressif/esp-brookesia/blob/master/system/brookesia_system_super/src/system.cpp"
click node_shell_resources "https://github.com/espressif/esp-brookesia/blob/master/system/brookesia_system_super/resource/shell/root.json"
click node_app_store "https://github.com/espressif/esp-brookesia/blob/master/app/brookesia_app_store/src/network/remote_index.ipp"
click node_super_entry "https://github.com/espressif/esp-brookesia/blob/master/examples/system/super/main/main.cpp"
click node_chatbot_entry "https://github.com/espressif/esp-brookesia/blob/master/examples/agent/chatbot/main/main.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_build,node_hal_interface,node_boards,node_esp_adaptor,node_portable_hal toneBlue
class node_service_manager,node_service_registries,node_service_helper,node_domain_services,node_agent_services,node_mcp toneAmber
class node_gui_model,node_lvgl,node_system_super,node_shell_resources,node_app_store toneMint
class node_runtime_manager,node_runtime_backends,node_system_core,node_package_scan,node_super_entry,node_chatbot_entry toneRose
```

## Components

### Platform Foundation

- [ESP-IDF Component Build](https://github.com/espressif/esp-brookesia/blob/master/CMakeLists.txt): build integration · CMake, Kconfig, and component manifests compose independently consumable components. · `CMakeLists.txt`
- [HAL Contracts](https://github.com/espressif/esp-brookesia/blob/master/hal/brookesia_hal_interface/include/brookesia/hal_interface/interfaces.hpp): hardware abstraction · Device-agnostic interfaces for device capabilities. · `hal/brookesia_hal_interface/include/brookesia/hal_interface/interfaces.hpp`
- [Board Definitions](https://github.com/espressif/esp-brookesia/blob/master/hal/brookesia_hal_boards/boards/espressif/esp_box_3/board_devices.yaml): board package · Pins, topology, and device defaults stay below upper layers. · `hal/brookesia_hal_boards/boards/espressif/esp_box_3/board_devices.yaml`
- [ESP HAL Adaptor](https://github.com/espressif/esp-brookesia/blob/master/hal/brookesia_hal_adaptor/src/display/device.cpp): ESP peripheral binding · Registers concrete ESP display and Wi-Fi peripherals. · `hal/brookesia_hal_adaptor/src/display/device.cpp`
- [Linux & WASM HAL](https://github.com/espressif/esp-brookesia/blob/master/hal/brookesia_hal_linux/src/network/http_client_impl.cpp): simulation implementation · Alternate device and network implementations for simulation. · `hal/brookesia_hal_linux/src/network/http_client_impl.cpp`

### Service Plane

- [Service Manager](https://github.com/espressif/esp-brookesia/blob/master/service/framework/brookesia_service_manager/src/service/manager.cpp): service control boundary · Owns lifecycle, local execution, and function routing. · `service/framework/brookesia_service_manager/src/service/manager.cpp`
- [Event & Function Registries](https://github.com/espressif/esp-brookesia/blob/master/service/framework/brookesia_service_manager/src/function/registry.cpp): service dispatch · Registers event and callable service endpoints. · `service/framework/brookesia_service_manager/src/function/registry.cpp`
- [Service Helper API](https://github.com/espressif/esp-brookesia/blob/master/service/framework/brookesia_service_helper/include/brookesia/service_helper.hpp): typed client API · Binds callers to services without exposing hardware implementations. · `service/framework/brookesia_service_helper/include/brookesia/service_helper.hpp`
- [Domain Services](https://github.com/espressif/esp-brookesia/blob/master/service/network/brookesia_service_wifi/src/state_machine.cpp): network, media, system services · Application-facing Wi-Fi, HTTP, storage, display, audio, and video state machines. · `service/network/brookesia_service_wifi/src/state_machine.cpp`
- [AI Agent Adapters](https://github.com/espressif/esp-brookesia/blob/master/service/agent/brookesia_agent_openai/src/agent_openai.cpp): provider integration · Connects device services to Coze, OpenAI, and XiaoZhi providers. · `service/agent/brookesia_agent_openai/src/agent_openai.cpp`
- [MCP Utilities](https://github.com/espressif/esp-brookesia/blob/master/utils/brookesia_mcp_utils/src/mcp_utils.cpp): LLM tool bridge · Exposes service functions and callbacks as LLM-invocable tools. · `utils/brookesia_mcp_utils/src/mcp_utils.cpp`

### GUI & Apps

- [GUI Document Runtime](https://github.com/espressif/esp-brookesia/blob/master/gui/brookesia_gui_interface/src/runtime.cpp): declarative UI model · Parses, validates, binds, and mounts JSON UI documents. · `gui/brookesia_gui_interface/src/runtime.cpp`
- [LVGL Backend](https://github.com/espressif/esp-brookesia/blob/master/gui/brookesia_gui_lvgl/src/backend.cpp): GUI renderer · Materializes widgets, styles, events, layouts, and animations. · `gui/brookesia_gui_lvgl/src/backend.cpp`
- [System Super Shell](https://github.com/espressif/esp-brookesia/blob/master/system/brookesia_system_super/src/system.cpp): touch device shell · Provides startup, launcher, navigation, overlays, and themes. · `system/brookesia_system_super/src/system.cpp`
- [Shell JSON Resources](https://github.com/espressif/esp-brookesia/blob/master/system/brookesia_system_super/resource/shell/root.json): declarative UI assets · `system/brookesia_system_super/resource/shell/root.json`
- [App Store](https://github.com/espressif/esp-brookesia/blob/master/app/brookesia_app_store/src/network/remote_index.ipp): built-in package app · Fetches remote catalogs and downloads installable content. · `app/brookesia_app_store/src/network/remote_index.ipp`

### Runtime & System

- [Runtime Manager](https://github.com/espressif/esp-brookesia/blob/master/runtime/brookesia_runtime_manager/src/runtime.cpp): dynamic app runtime · Loads app packages and bridges app calls to host services. · `runtime/brookesia_runtime_manager/src/runtime.cpp`
- [App Runtime Backends](https://github.com/espressif/esp-brookesia/blob/master/runtime/brookesia_runtime_wasm/src/backend.cpp): ELF, JS, Lua, WASM · Selected backend executes packaged application code. · `runtime/brookesia_runtime_wasm/src/backend.cpp`
- [System Core](https://github.com/espressif/esp-brookesia/blob/master/system/brookesia_system_core/src/app/manager.cpp): app ownership boundary · Coordinates installed-app lifecycle, capabilities, resources, storage, timers, and bridges. · `system/brookesia_system_core/src/app/manager.cpp`
- [Package Scan & Verify](https://github.com/espressif/esp-brookesia/blob/master/system/brookesia_system_core/src/app/package_scan.cpp): package intake · Discovers and verifies installed application packages. · `system/brookesia_system_core/src/app/package_scan.cpp`
- [System Super Entry](https://github.com/espressif/esp-brookesia/blob/master/examples/system/super/main/main.cpp): ESP-IDF application entry · `examples/system/super/main/main.cpp`
- [Chatbot Entry](https://github.com/espressif/esp-brookesia/blob/master/examples/agent/chatbot/main/main.cpp): ESP-IDF application entry · `examples/agent/chatbot/main/main.cpp`

## Connections

- ESP-IDF Component Build → HAL Contracts: builds
- ESP-IDF Component Build → Service Manager: builds
- ESP-IDF Component Build → System Core: builds
- Board Definitions → ESP HAL Adaptor: configures
- ESP HAL Adaptor → HAL Contracts: implements
- Linux & WASM HAL → HAL Contracts: implements
- Domain Services → HAL Contracts: uses device capabilities
- Event & Function Registries → Service Manager: dispatches through
- Service Manager → Domain Services: manages
- Service Helper API → Service Manager: calls
- AI Agent Adapters → Service Helper API: uses
- MCP Utilities → Service Manager: exposes functions
- LVGL Backend → GUI Document Runtime: renders document model
- LVGL Backend → HAL Contracts: uses display port
- System Core → Package Scan & Verify: scans packages
- System Core → Runtime Manager: owns app execution
- Runtime Manager → App Runtime Backends: selects
- Runtime Manager → Service Manager: bridges host calls
- System Core → GUI Document Runtime: grants GUI access
- System Super Shell → System Core: runs on
- System Super Shell → Shell JSON Resources: mounts
- System Super Shell → GUI Document Runtime: supplies UI
- App Store → System Core: follows app lifecycle
- App Store → Package Scan & Verify: installs packages
- System Super Entry → System Super Shell: starts
- Chatbot Entry → AI Agent Adapters: starts agent integration
