# tienhuyiot/xiaozhi-esp32_vietnam architecture

> Architecture diagram of the GitHub repository tienhuyiot/xiaozhi-esp32_vietnam, 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/tienhuyiot/xiaozhi-esp32_vietnam
- Repository: https://github.com/tienhuyiot/xiaozhi-esp32_vietnam

## Overview

Xiaozhi ESP32 Vietnam is an ESP32 voice-chat and IoT device firmware. The main workflow is user speech → board audio capture and wake-word/audio processing → application-managed network protocol → AI speech response → audio playback and display. The README documents streaming ASR/LLM/TTS, WebSocket or MQTT+UDP, MCP control, music/radio, weather, and OTA. Some subsystem links are documented rather than verified in sampled implementation excerpts; these use README evidence where applicable.

Main entry points: [`main/application.cc`](https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/application.cc) (Application), [`main/audio/audio_service.cc`](https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/audio/audio_service.cc) (Audio Service), [`main/boards/common/board.h`](https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/boards/common/board.h) (Board Hardware), [`main/protocols/protocol.h`](https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/protocols/protocol.h) (Protocol Interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_device["Device Platform"]
  node_board["Board Hardware<br/>[board.h]"]
  node_application["Application<br/>[application.cc]"]
  node_settings[("Settings<br/>[settings.h]")]
end

subgraph group_voice["Voice Conversation"]
  node_audio["Audio Service<br/>[audio_service.cc]"]
  node_codec["Audio Codecs<br/>[audio_codec.h]"]
  node_wake["Wake Words"]
  node_processor["Audio Processing"]
end

subgraph group_network["Network Services"]
  node_protocol["Protocol Interface<br/>[protocol.h]"]
  node_websocket["WebSocket"]
  node_mqtt["MQTT<br/>[mqtt_protocol.cc]"]
  node_mcp["MCP Server<br/>[mcp_server.h]"]
  node_ota["OTA Update<br/>[ota.cc]"]
  node_ota_server["OTA Web Server<br/>[ota_server.h]"]
end

subgraph group_features["User Features"]
  node_mcp_features["MCP Features"]
  node_music["Online Music<br/>[esp32_music.cc]"]
  node_radio["Radio<br/>[esp32_radio.cc]"]
  node_sd_music["SD Music<br/>[esp32_sd_music.cc]"]
  node_stream_player["Audio Stream Player"]
  node_weather["Weather Service<br/>[weather_service.cc]"]
end

subgraph group_ui["Display and Media"]
  node_spectrum["Spectrum Display"]
  node_weather_ui["Weather Display<br/>[weather_ui.h]"]
  node_display["Display<br/>[display.h]"]
  node_lcd["LCD Display<br/>[lcd_display.cc]"]
end

node_user(("Device User"))
node_ai_service(("AI Voice Service"))

node_user -->|"speaks to"| node_board
node_board -->|"provides hardware"| node_application
node_application -->|"initializes"| node_audio
node_application -->|"gets codec"| node_board
node_audio -->|"captures and plays"| node_codec
node_audio -->|"uses"| node_wake
node_audio -->|"uses"| node_processor
node_audio -->|"sends and receives audio"| node_protocol
node_application -->|"selects protocol"| node_websocket
node_application -->|"selects protocol"| node_mqtt
node_protocol -->|"streams conversation"| node_ai_service
node_ai_service -->|"returns speech"| node_protocol
node_application -->|"uses tools"| node_mcp
node_application -->|"registers features"| node_mcp_features
node_application -->|"initializes playback"| node_music
node_application -->|"initializes playback"| node_radio
node_application -->|"initializes playback"| node_sd_music
node_sd_music -->|"uses"| node_stream_player
node_application -->|"sets up visualization"| node_spectrum
node_application -->|"integrates service"| node_weather
node_weather -->|"updates display"| node_weather_ui
node_weather_ui -->|"renders weather"| node_display
node_application -->|"updates interface"| node_display
node_display -->|"implemented by"| node_lcd
node_application -->|"starts upgrade"| node_ota
node_application -->|"integrates server"| node_ota_server
node_application -.->|"reads configuration"| node_settings

click node_board "https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/boards/common/board.h"
click node_application "https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/application.cc"
click node_settings "https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/settings.h"
click node_audio "https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/audio/audio_service.cc"
click node_codec "https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/audio/audio_codec.h"
click node_wake "https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/tree/develop_vn/main/audio/wake_words"
click node_processor "https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/tree/develop_vn/main/audio/processors"
click node_protocol "https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/protocols/protocol.h"
click node_websocket "https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/protocols/websocket_protocol.cc"
click node_mqtt "https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/protocols/mqtt_protocol.cc"
click node_mcp "https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/mcp_server.h"
click node_mcp_features "https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/features/mcp_server_features.cc"
click node_music "https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/features/music/esp32_music.cc"
click node_radio "https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/features/music/esp32_radio.cc"
click node_sd_music "https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/features/music/esp32_sd_music.cc"
click node_stream_player "https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/features/music/audio_stream_player.h"
click node_spectrum "https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/features/spectrum/spectrum_manager.cc"
click node_weather "https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/features/weather/weather_service.cc"
click node_weather_ui "https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/features/weather/weather_ui.h"
click node_display "https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/display/display.h"
click node_lcd "https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/display/lcd_display.cc"
click node_ota "https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/ota.cc"
click node_ota_server "https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/ota_server.h"

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_board,node_application,node_settings,node_user toneBlue
class node_audio,node_codec,node_wake,node_processor toneAmber
class node_protocol,node_websocket,node_mqtt,node_mcp,node_ota,node_ota_server toneMint
class node_mcp_features,node_music,node_radio,node_sd_music,node_stream_player,node_weather toneRose
class node_spectrum,node_weather_ui,node_display,node_lcd,node_ai_service toneIndigo
```

## Components

### Device Platform

- [Board Hardware](https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/boards/common/board.h): `main/boards/common/board.h`
- [Application](https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/application.cc): `main/application.cc`
- [Settings](https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/settings.h): `main/settings.h`

### Voice Conversation

- [Audio Service](https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/audio/audio_service.cc): `main/audio/audio_service.cc`
- [Audio Codecs](https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/audio/audio_codec.h): `main/audio/audio_codec.h`
- [Wake Words](https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/tree/develop_vn/main/audio/wake_words): `main/audio/wake_words`
- [Audio Processing](https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/tree/develop_vn/main/audio/processors): `main/audio/processors`

### Network Services

- [Protocol Interface](https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/protocols/protocol.h): `main/protocols/protocol.h`
- [WebSocket](https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/protocols/websocket_protocol.cc): `main/protocols/websocket_protocol.cc`
- [MQTT](https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/protocols/mqtt_protocol.cc): `main/protocols/mqtt_protocol.cc`
- [MCP Server](https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/mcp_server.h): `main/mcp_server.h`
- [OTA Update](https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/ota.cc): `main/ota.cc`
- [OTA Web Server](https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/ota_server.h): `main/ota_server.h`

### User Features

- [MCP Features](https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/features/mcp_server_features.cc): `main/features/mcp_server_features.cc`
- [Online Music](https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/features/music/esp32_music.cc): `main/features/music/esp32_music.cc`
- [Radio](https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/features/music/esp32_radio.cc): `main/features/music/esp32_radio.cc`
- [SD Music](https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/features/music/esp32_sd_music.cc): `main/features/music/esp32_sd_music.cc`
- [Audio Stream Player](https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/features/music/audio_stream_player.h): `main/features/music/audio_stream_player.h`
- [Weather Service](https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/features/weather/weather_service.cc): `main/features/weather/weather_service.cc`

### Display and Media

- [Spectrum Display](https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/features/spectrum/spectrum_manager.cc): `main/features/spectrum/spectrum_manager.cc`
- [Weather Display](https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/features/weather/weather_ui.h): `main/features/weather/weather_ui.h`
- [Display](https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/display/display.h): `main/display/display.h`
- [LCD Display](https://github.com/tienhuyiot/xiaozhi-esp32_vietnam/blob/develop_vn/main/display/lcd_display.cc): `main/display/lcd_display.cc`

### Other components

- **Device User**
- **AI Voice Service**

## Connections

- Device User → Board Hardware: speaks to
- Board Hardware → Application: provides hardware (evidence: `main/application.cc`)
- Application → Audio Service: initializes (evidence: `main/application.cc`)
- Application → Board Hardware: gets codec (evidence: `main/application.cc`)
- Audio Service → Audio Codecs: captures and plays (evidence: `main/audio/audio_service.cc`)
- Audio Service → Wake Words: uses (evidence: `main/audio/audio_service.cc`)
- Audio Service → Audio Processing: uses (evidence: `main/audio/audio_service.cc`)
- Audio Service → Protocol Interface: sends and receives audio
- Application → WebSocket: selects protocol (evidence: `main/application.cc`)
- Application → MQTT: selects protocol (evidence: `main/application.cc`)
- Protocol Interface → AI Voice Service: streams conversation
- AI Voice Service → Protocol Interface: returns speech
- Application → MCP Server: uses tools (evidence: `main/application.cc`)
- Application → MCP Features: registers features (evidence: `main/application.cc`)
- Application → Online Music: initializes playback (evidence: `main/application.cc`)
- Application → Radio: initializes playback
- Application → SD Music: initializes playback
- SD Music → Audio Stream Player: uses
- Application → Spectrum Display: sets up visualization (evidence: `main/application.cc`)
- Application → Weather Service: integrates service
- Weather Service → Weather Display: updates display (evidence: `main/features/weather/weather_service.cc`)
- Weather Display → Display: renders weather (evidence: `main/features/weather/weather_ui.h`)
- Application → Display: updates interface (evidence: `main/application.cc`)
- Display → LCD Display: implemented by
- Application → OTA Update: starts upgrade (evidence: `main/application.cc`)
- Application → OTA Web Server: integrates server (evidence: `main/application.cc`)
- Application → Settings: reads configuration (evidence: `main/application.cc`)
