# espressif/esp-box architecture

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

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

## Overview

##### Project Type and Purpose
- It provides board support packages (BSP), FreeRTOS-based firmware components (voice pipeline, GUI, connectivity), numerous example applications (voice assistant, AI chat, Matter, RainMaker, USB, sensor demos), hardware schematics/PCB files, documentation, and build/CI tools.
- Key use cases: offline/online voice assistants, HMI applications with touchscreen and LVGL GUI, cloud integration (OpenAI, ESP RainMaker), Matter devices, sensor & actuator demos.

##### File Structure Highlights
- Top-level:
- components/ — custom IDF components (bsp, board-abstraction, storage)
- examples/ — dozens of end-to-end demo apps (factory_demo, chatgpt_demo, matter_switch, watering_demo, etc.)
- docs/ — user guides, hardware overviews, technical architecture
- hardware/ — PCB schematics, BOMs, 3D shell models
- tools/ — build scripts, CI checks, launchpad integration
- bin/ — prebuilt factory firmware images
- .github, .gitlab-ci.yml, pre-commit config — CI pipelines, PR/issue automation
- build system: CMakeLists.txt at root and in every component/example -> leverages ESP-IDF CMake integration.

##### Insights from README
- Multi-layered firmware stack: BSP → ESP-IDF + FreeRTOS → voice/speech-recognition components → LVGL GUI → application logic → cloud/edge services.
- Supports multiple boards via IDF menuconfig selection.
- Integrates with external services: OpenAI for chatbots, ESP RainMaker/Matter for home automation, NuttX RTOS optionally.
- Examples illustrate varying application domains, showing extensibility.

1. Hardware Platform
- ESP32-S3 SoC
- Peripherals: dual microphones, LCD touchscreen, SD card, buttons, sensors (I2C/SPI), USB host/device ports, wireless radio (Wi-Fi, BLE)
2. Board Support Package (components/bsp)
- Low-level drivers for board peripherals
- Storage abstraction (SPI-Flash, SD-card)
3. RTOS & Core Framework
- FreeRTOS scheduler
- ESP-IDF core (Wi-Fi, BLE, NVS, drivers)
4. Middleware Components
- Speech-recognition (esp-sr)
- Audio pipeline (mic → DSP → codec)
- GUI engine (LVGL, SquareLine assets)
- Protocol stacks (MQTT, HTTP, Matter, ESP RainMaker SDK)
5. Application Layer
- Offline voice assistant app
- ChatGPT demo (online AI chatbot)
- Factory/demo apps (LED, fan, sensor monitor, switch, watering)
- Matter switch & controller example
6. Cloud & External Services
- OpenAI API
- ESP RainMaker cloud
- Matter ecosystem
- Optional: NuttX integration (external RTOS)
7. Build & Delivery
- CMake + IDF build process
- CI/CD pipelines: GitHub Actions, GitLab CI
- ESP Launchpad flashing tool

b. Relationships and Interactions
- Configuration/build flow from tools/CI to firmware images in bin/.

c. Architectural Patterns & Principles
- Layered architecture: hardware abstraction, core services, middleware, application.
- Component-based design: each feature (GUI, SR, connectivity) is an ESP-IDF component.
- CMake/IDF modular build: clear boundaries between components and examples.
- RTOS task separation: separate tasks for audio capture/processing, GUI rendering, network communication.

d. Key Technologies & Frameworks
- ESP-IDF / FreeRTOS
- CMake build system
- LVGL for GUI
- esp-sr for speech recognition
- MQTT/HTTP, Matter SDK, ESP RainMaker SDK
- Cloud APIs: OpenAI, RainMaker
- NuttX (optional alternative OS)

##### Detail & Coverage
- Every major component: BSP, IDF, middleware, apps, build tools, docs, hardware assets.
- Don’t hesitate to break out sub-components (e.g., separate “Audio pipeline” from “GUI engine”).
- How examples like chatgpt_demo and factory_demo map onto the middleware stacks.
- Keep it readable by grouping high-level modules and expanding only the essential internals.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Hardware Layer
    subgraph "Hardware Platform" 
        direction TB
        HW["ESP32-S3 SoC + Peripherals"]:::hardware
    end

    %% BSP Layer
    subgraph "Board Support Package (BSP)" 
        direction TB
        BSP["Low-level Drivers & Storage Abstraction"]:::firmware
    end

    %% RTOS & Core Framework
    subgraph "RTOS & Core Framework" 
        direction TB
        CORE["ESP-IDF + FreeRTOS Scheduler"]:::firmware
    end

    %% Middleware Components
    subgraph "Middleware Components"
        direction TB
        SR["Speech Recognition (esp-sr)"]:::middleware
        AP["Audio Pipeline (DSP, Codec)"]:::middleware
        GUI["GUI Engine (LVGL)"]:::middleware
        PS["Protocol Stacks (MQTT, HTTP, Matter, RainMaker SDK)"]:::middleware
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        CHAT["ChatGPT Demo"]:::application
        FACT["Factory Demo"]:::application
        MATTER["Matter Switch Example"]:::application
        WATER["Watering Demo"]:::application
        LV["LVGL GUI Demos"]:::application
        IMG["Image Display Demo"]:::application
        MP3["MP3 Demo"]:::application
        USBCAM["USB Camera LCD Demo"]:::application
        USBAUD["USB Headset Demo"]:::application
    end

    %% Cloud & External Services
    subgraph "Cloud & External Services"
        direction TB
        OPENAI["OpenAI API"]:::cloud
        RAINMAKER["ESP RainMaker Cloud"]:::cloud
        MATTERCLOUD["Matter Ecosystem"]:::cloud
        NUTTX["NuttX RTOS (Optional)"]:::cloud
    end

    %% Build & Delivery Tools
    subgraph "Build & Delivery Tools"
        direction TB
        GHA["GitHub Actions"]:::tools
        GLCI["GitLab CI"]:::tools
        BUILD["Build Scripts"]:::tools
        CI_TOOLS["CI Checks & Styling"]:::tools
        LAUNCH["ESP Launchpad Tool"]:::tools
        BIN["Firmware Images (bin/)"]:::tools
    end

    %% Relationships
    HW --> BSP
    BSP --> CORE
    CORE --> SR
    CORE --> AP
    CORE --> GUI
    CORE --> PS

    SR --> CHAT
    AP --> CHAT
    GUI --> CHAT
    PS --> CHAT

    SR --> FACT
    AP --> FACT
    GUI --> FACT
    PS --> FACT

    SR --> MATTER
    AP --> MATTER
    GUI --> MATTER
    PS --> MATTER

    SR --> WATER
    AP --> WATER
    PS --> WATER

    GUI --> LV
    GUI --> IMG
    AP --> MP3
    GUI --> USBCAM
    AP --> USBAUD

    SR <--> OPENAI
    PS <--> RAINMAKER
    PS <--> MATTERCLOUD
    CORE --> NUTTX

    GHA --> BIN
    GLCI --> BIN
    BUILD --> BIN
    CI_TOOLS --> BIN
    LAUNCH --> BIN

    BIN -->|Flashed via| HW

    %% Click Events
    click HW "https://github.com/espressif/esp-box/tree/master/hardware/"
    click BSP "https://github.com/espressif/esp-box/tree/master/components/bsp/"
    click CORE "https://github.com/espressif/esp-box/blob/master/CMakeLists.txt"
    click GHA "https://github.com/espressif/esp-box/tree/master/.github/workflows/"
    click GLCI "https://github.com/espressif/esp-box/blob/master/.gitlab-ci.yml"
    click GLCI "https://github.com/espressif/esp-box/tree/master/.gitlab/ci/"
    click BUILD "https://github.com/espressif/esp-box/blob/master/tools/build_apps.py"
    click CI_TOOLS "https://github.com/espressif/esp-box/tree/master/tools/ci/"
    click LAUNCH "https://github.com/espressif/esp-box/tree/master/tools/launchpad/"
    click CHAT "https://github.com/espressif/esp-box/tree/master/examples/chatgpt_demo/"
    click FACT "https://github.com/espressif/esp-box/tree/master/examples/factory_demo/"
    click MATTER "https://github.com/espressif/esp-box/tree/master/examples/matter_switch/"
    click WATER "https://github.com/espressif/esp-box/tree/master/examples/watering_demo/"
    click LV "https://github.com/espressif/esp-box/tree/master/examples/lv_demos/"
    click IMG "https://github.com/espressif/esp-box/tree/master/examples/image_display/"
    click MP3 "https://github.com/espressif/esp-box/tree/master/examples/mp3_demo/"
    click USBCAM "https://github.com/espressif/esp-box/tree/master/examples/usb_camera_lcd_display/"
    click USBAUD "https://github.com/espressif/esp-box/tree/master/examples/usb_headset/"

    %% Styles
    classDef hardware fill:#DDDDDD,stroke:#555,stroke-width:1px;
    classDef firmware fill:#AED6F1,stroke:#217DBB,stroke-width:1px;
    classDef middleware fill:#85C1E9,stroke:#21618C,stroke-width:1px;
    classDef application fill:#A9DFBF,stroke:#1D8348,stroke-width:1px;
    classDef cloud fill:#ABEBC6,stroke:#148F77,stroke-width:1px;
    classDef tools fill:#F5CBA7,stroke:#B9770E,stroke-width:1px;
```
