# txp666/xiaozhi-esp32 architecture

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

- Interactive diagram: https://gitdiagram.com/txp666/xiaozhi-esp32
- Repository: https://github.com/txp666/xiaozhi-esp32

## Overview

XiaoZhi is an embedded, voice-first AI chatbot firmware for many ESP32 boards. A user speaks or activates a wake word; the firmware captures and processes audio, exchanges voice and control messages with an AI service, then plays responses and updates device interfaces. Documented capabilities also include camera input, MCP tools, multiple network transports, provisioning, localization, and customizable assets. The graph combines sampled implementation references with README-documented features; several feature links are documented rather than verified in sampled implementation.

Main entry points: [`main/application.cc`](https://github.com/txp666/xiaozhi-esp32/blob/main/main/application.cc) (Application), [`main/audio/audio_service.cc`](https://github.com/txp666/xiaozhi-esp32/blob/main/main/audio/audio_service.cc) (Audio service), [`main/audio/engines/afe_audio_engine.cc`](https://github.com/txp666/xiaozhi-esp32/blob/main/main/audio/engines/afe_audio_engine.cc) (Audio engines), [`main/protocols/protocol.h`](https://github.com/txp666/xiaozhi-esp32/blob/main/main/protocols/protocol.h) (Protocol interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime orchestration"]
  node_application["Application<br/>[application.cc]"]
  node_settings[("Device settings<br/>[settings.h]")]
end

subgraph group_audio["Voice processing"]
  node_audio_service["Audio service<br/>[audio_service.cc]"]
  node_audio_codec["Audio codec<br/>[audio_codec.h]"]
  node_audio_engine["Audio engines"]
  node_wake_words["Wake words<br/>[custom_wake_word.h]"]
  node_notify["Voice notifications<br/>[notify_player.cc]"]
end

subgraph group_connectivity["Connectivity and AI"]
  node_protocol["Protocol interface<br/>[protocol.h]"]
  node_websocket["WebSocket transport"]
  node_mqtt["MQTT and UDP<br/>[mqtt_protocol.cc]"]
  node_ai_service(("AI service"))
end

subgraph group_device["Device interfaces"]
  node_board["Board hardware<br/>[board.h]"]
  node_display["Display and UI<br/>[lcd_display.cc]"]
  node_camera["Camera input<br/>[camera.h]"]
  node_network["Network interfaces<br/>[board.h]"]
end

subgraph group_tools["MCP and personalization"]
  node_mcp["MCP tools<br/>[mcp_server.cc]"]
  node_robot_tools["Robot controls<br/>[otto_controller.cc]"]
  node_assets["Custom assets<br/>[assets.cc]"]
end

node_user(("User"))

node_user -->|"interacts with"| node_application
node_application -->|"initializes"| node_board
node_application -->|"starts"| node_audio_service
node_board -->|"provides"| node_audio_codec
node_audio_service -->|"uses"| node_audio_codec
node_audio_service -->|"selects"| node_audio_engine
node_audio_engine -->|"processes audio"| node_audio_codec
node_audio_engine -->|"detects"| node_wake_words
node_application -->|"initializes"| node_protocol
node_protocol -.->|"implemented by"| node_websocket
node_protocol -->|"implemented by"| node_mqtt
node_websocket -->|"exchanges messages"| node_ai_service
node_mqtt -->|"exchanges audio and messages"| node_ai_service
node_application -->|"sets up UI"| node_display
node_board -->|"provides"| node_network
node_user -.->|"provides vision input"| node_camera
node_camera -.->|"feeds vision"| node_application
node_application -->|"integrates"| node_mcp
node_mcp -->|"dispatches tools"| node_robot_tools
node_application -->|"checks asset version"| node_assets
node_application -.->|"configures runtime"| node_settings
node_application -->|"starts playback"| node_notify
node_audio_service -->|"plays notification audio"| node_notify
node_user -.->|"provisions device"| node_network

click node_application "https://github.com/txp666/xiaozhi-esp32/blob/main/main/application.cc"
click node_board "https://github.com/txp666/xiaozhi-esp32/blob/main/main/boards/common/board.h"
click node_audio_service "https://github.com/txp666/xiaozhi-esp32/blob/main/main/audio/audio_service.cc"
click node_audio_codec "https://github.com/txp666/xiaozhi-esp32/blob/main/main/audio/audio_codec.h"
click node_audio_engine "https://github.com/txp666/xiaozhi-esp32/blob/main/main/audio/engines/afe_audio_engine.cc"
click node_wake_words "https://github.com/txp666/xiaozhi-esp32/blob/main/main/audio/wake_words/custom_wake_word.h"
click node_protocol "https://github.com/txp666/xiaozhi-esp32/blob/main/main/protocols/protocol.h"
click node_websocket "https://github.com/txp666/xiaozhi-esp32/blob/main/main/protocols/websocket_protocol.cc"
click node_mqtt "https://github.com/txp666/xiaozhi-esp32/blob/main/main/protocols/mqtt_protocol.cc"
click node_mcp "https://github.com/txp666/xiaozhi-esp32/blob/main/main/mcp_server.cc"
click node_robot_tools "https://github.com/txp666/xiaozhi-esp32/blob/main/main/boards/otto-robot/otto_controller.cc"
click node_display "https://github.com/txp666/xiaozhi-esp32/blob/main/main/display/lcd_display.cc"
click node_camera "https://github.com/txp666/xiaozhi-esp32/blob/main/main/boards/common/camera.h"
click node_network "https://github.com/txp666/xiaozhi-esp32/blob/main/main/boards/common/board.h"
click node_assets "https://github.com/txp666/xiaozhi-esp32/blob/main/main/assets.cc"
click node_settings "https://github.com/txp666/xiaozhi-esp32/blob/main/main/settings.h"
click node_notify "https://github.com/txp666/xiaozhi-esp32/blob/main/main/notify/notify_player.cc"

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_application,node_settings,node_user toneBlue
class node_audio_service,node_audio_codec,node_audio_engine,node_wake_words,node_notify toneAmber
class node_protocol,node_websocket,node_mqtt,node_ai_service toneMint
class node_board,node_display,node_camera,node_network toneRose
class node_mcp,node_robot_tools,node_assets toneIndigo
```

## Components

### Runtime orchestration

- [Application](https://github.com/txp666/xiaozhi-esp32/blob/main/main/application.cc): `main/application.cc`
- [Device settings](https://github.com/txp666/xiaozhi-esp32/blob/main/main/settings.h): `main/settings.h`

### Voice processing

- [Audio service](https://github.com/txp666/xiaozhi-esp32/blob/main/main/audio/audio_service.cc): `main/audio/audio_service.cc`
- [Audio codec](https://github.com/txp666/xiaozhi-esp32/blob/main/main/audio/audio_codec.h): `main/audio/audio_codec.h`
- [Audio engines](https://github.com/txp666/xiaozhi-esp32/blob/main/main/audio/engines/afe_audio_engine.cc): `main/audio/engines/afe_audio_engine.cc`
- [Wake words](https://github.com/txp666/xiaozhi-esp32/blob/main/main/audio/wake_words/custom_wake_word.h): `main/audio/wake_words/custom_wake_word.h`
- [Voice notifications](https://github.com/txp666/xiaozhi-esp32/blob/main/main/notify/notify_player.cc): `main/notify/notify_player.cc`

### Connectivity and AI

- [Protocol interface](https://github.com/txp666/xiaozhi-esp32/blob/main/main/protocols/protocol.h): `main/protocols/protocol.h`
- [WebSocket transport](https://github.com/txp666/xiaozhi-esp32/blob/main/main/protocols/websocket_protocol.cc): `main/protocols/websocket_protocol.cc`
- [MQTT and UDP](https://github.com/txp666/xiaozhi-esp32/blob/main/main/protocols/mqtt_protocol.cc): `main/protocols/mqtt_protocol.cc`
- **AI service**

### Device interfaces

- [Board hardware](https://github.com/txp666/xiaozhi-esp32/blob/main/main/boards/common/board.h): `main/boards/common/board.h`
- [Display and UI](https://github.com/txp666/xiaozhi-esp32/blob/main/main/display/lcd_display.cc): `main/display/lcd_display.cc`
- [Camera input](https://github.com/txp666/xiaozhi-esp32/blob/main/main/boards/common/camera.h): `main/boards/common/camera.h`
- [Network interfaces](https://github.com/txp666/xiaozhi-esp32/blob/main/main/boards/common/board.h): `main/boards/common/board.h`

### MCP and personalization

- [MCP tools](https://github.com/txp666/xiaozhi-esp32/blob/main/main/mcp_server.cc): `main/mcp_server.cc`
- [Robot controls](https://github.com/txp666/xiaozhi-esp32/blob/main/main/boards/otto-robot/otto_controller.cc): `main/boards/otto-robot/otto_controller.cc`
- [Custom assets](https://github.com/txp666/xiaozhi-esp32/blob/main/main/assets.cc): `main/assets.cc`

### Other components

- **User**

## Connections

- User → Application: interacts with (evidence: `README.md`)
- Application → Board hardware: initializes (evidence: `main/application.cc`)
- Application → Audio service: starts (evidence: `main/application.cc`)
- Board hardware → Audio codec: provides (evidence: `main/boards/common/board.h`)
- Audio service → Audio codec: uses
- Audio service → Audio engines: selects (evidence: `main/audio/audio_service.cc`)
- Audio engines → Audio codec: processes audio
- Audio engines → Wake words: detects (evidence: `main/audio/engines/afe_audio_engine.cc`)
- Application → Protocol interface: initializes (evidence: `main/application.cc`)
- Protocol interface → WebSocket transport: implemented by
- Protocol interface → MQTT and UDP: implemented by
- WebSocket transport → AI service: exchanges messages (evidence: `README.md`)
- MQTT and UDP → AI service: exchanges audio and messages (evidence: `README.md`)
- Application → Display and UI: sets up UI (evidence: `main/application.cc`)
- Board hardware → Network interfaces: provides (evidence: `main/boards/common/board.h`)
- User → Camera input: provides vision input (evidence: `README.md`)
- Camera input → Application: feeds vision (evidence: `README.md`)
- Application → MCP tools: integrates (evidence: `main/application.cc`)
- MCP tools → Robot controls: dispatches tools (evidence: `main/boards/otto-robot/otto_controller.cc`)
- Application → Custom assets: checks asset version (evidence: `main/application.cc`)
- Application → Device settings: configures runtime (evidence: `main/application.cc`)
- Application → Voice notifications: starts playback
- Audio service → Voice notifications: plays notification audio
- User → Network interfaces: provisions device (evidence: `README.md`)
