How espressif/esp-brookesia works
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: app/manager.cpp System Core · service/manager.cpp Service Manager · interfaces.hpp HAL Contracts · system.cpp System Super Shell
Components 22
Platform Foundation
- ESP-IDF Component Build · CMake, Kconfig, and component manifests compose independently consumable components.
CMakeLists.txt - HAL Contracts · Device-agnostic interfaces for device capabilities.
hal/brookesia_hal_interface/include/brookesia/hal_interface/interfaces.hpp - Board Definitions · Pins, topology, and device defaults stay below upper layers.
hal/brookesia_hal_boards/boards/espressif/esp_box_3/board_devices.yaml - ESP HAL Adaptor · Registers concrete ESP display and Wi-Fi peripherals.
hal/brookesia_hal_adaptor/src/display/device.cpp - Linux & WASM HAL · Alternate device and network implementations for simulation.
hal/brookesia_hal_linux/src/network/http_client_impl.cpp
Service Plane
- Service Manager · Owns lifecycle, local execution, and function routing.
service/framework/brookesia_service_manager/src/service/manager.cpp - Event & Function Registries · Registers event and callable service endpoints.
service/framework/brookesia_service_manager/src/function/registry.cpp - Service Helper API · Binds callers to services without exposing hardware implementations.
service/framework/brookesia_service_helper/include/brookesia/service_helper.hpp - Domain 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 · Connects device services to Coze, OpenAI, and XiaoZhi providers.
service/agent/brookesia_agent_openai/src/agent_openai.cpp - MCP Utilities · Exposes service functions and callbacks as LLM-invocable tools.
utils/brookesia_mcp_utils/src/mcp_utils.cpp
GUI & Apps
- GUI Document Runtime · Parses, validates, binds, and mounts JSON UI documents.
gui/brookesia_gui_interface/src/runtime.cpp - LVGL Backend · Materializes widgets, styles, events, layouts, and animations.
gui/brookesia_gui_lvgl/src/backend.cpp - System Super Shell · Provides startup, launcher, navigation, overlays, and themes.
system/brookesia_system_super/src/system.cpp - Shell JSON Resources
system/brookesia_system_super/resource/shell/root.json - App Store · Fetches remote catalogs and downloads installable content.
app/brookesia_app_store/src/network/remote_index.ipp
Runtime & System
- Runtime Manager · Loads app packages and bridges app calls to host services.
runtime/brookesia_runtime_manager/src/runtime.cpp - App Runtime Backends · Selected backend executes packaged application code.
runtime/brookesia_runtime_wasm/src/backend.cpp - System Core · Coordinates installed-app lifecycle, capabilities, resources, storage, timers, and bridges.
system/brookesia_system_core/src/app/manager.cpp - Package Scan & Verify · Discovers and verifies installed application packages.
system/brookesia_system_core/src/app/package_scan.cpp - System Super Entry
examples/system/super/main/main.cpp - Chatbot Entry
examples/agent/chatbot/main/main.cpp
Connections 26
- 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