# 100askteam/xiaozhi-linux architecture

> Architecture diagram of the GitHub repository 100askteam/xiaozhi-linux, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/100askteam/xiaozhi-linux
- Repository: https://github.com/100askteam/xiaozhi-linux

## Overview

##### Major Components
- Control Center: This module (in the “control_center” folder) implements the core logic, interfaces and communication methods (e.g., HTTP, WebSocket client, UDP IPC, JSON utilities, UUID generation) that tie the various subsystems together.
- Sound App: The “sound_app” module handles audio-related functionalities – including recording, audio playback, audio encoding (Opus), and UDP IPC for data exchange.
- Graphical User Interface (GUI): Found in the “gui” folder, this component integrates LVGL and includes additional support libraries, demos, and configuration files. It provides the front-end user experience.

##### Interactions and Data Flow
- The Control Center serves as a central hub that interfaces with both the Sound App and the GUI.
- Sound App and Control Center exchange audio data and command signals using IPC via UDP (noted by the ipc_udp.* files in both modules).
- External services (if any) such as network communications (HTTP/WebSocket) are handled by the control_center.

##### Architectural Patterns and Design Principles
- Modular Separation: The project cleanly separates core functionality, audio processing, and graphical output. This separation enables platform-specific adaptations (BSP for different hardware platforms) without disrupting common core features.
- Layered Architecture: At the lower level, sound_app and control_center handle “backend” processing, while the gui layer is responsible for user interaction, likely driven by an event-loop paradigm (supported by LVGL).
- Communication via IPC: The use of UDP-based inter-process communication suggests a loosely coupled design where modules can communicate asynchronously.
- Use of Common Libraries: The GUI leverages LVGL and its many demos and configuration files. The control_center uses modern C++ utilities (JSON, UUID, HTTP, WebSocket) to manage flows.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% User Interface Layer
    subgraph "User Interface Layer"
        GUI["GUI: LVGL-based UI and demos"]:::guiColor
    end

    %% Core Processing Layer
    subgraph "Core Processing Layer"
        CC["Control Center: HTTP,WebSocket,JSON,UDPIPC"]:::controlcolor
    end

    %% Audio Processing Layer
    subgraph "Audio Processing Layer"
        SA["Sound App: Record,Playback,Opus,UDPIPC"]:::audioColor
    end

    %% Supporting Documentation
    subgraph "Supporting Documentation"
        DOCS["Docs: Architecture & Assets"]:::docsColor
    end

    %% Connections
    GUI -->|"UserCmds"| CC
    CC <-->|"UDP_IPC"| SA
    DOCS ---|"ref"| GUI
    DOCS ---|"ref"| CC
    DOCS ---|"ref"| SA

    %% Click Events
    click CC "https://github.com/100askteam/xiaozhi-linux/tree/master/control_center/"
    click SA "https://github.com/100askteam/xiaozhi-linux/tree/master/sound_app/"
    click GUI "https://github.com/100askteam/xiaozhi-linux/tree/master/gui/"
    click DOCS "https://github.com/100askteam/xiaozhi-linux/tree/master/docs/"

    %% Styles
    classDef controlcolor fill:#ADD8E6,stroke:#0000FF,stroke-width:2px;
    classDef audioColor fill:#90EE90,stroke:#008000,stroke-width:2px;
    classDef guiColor fill:#FFA07A,stroke:#FF4500,stroke-width:2px;
    classDef docsColor fill:#D3D3D3,stroke:#808080,stroke-width:2px;
```
