# cczhong11/xiaogpt architecture

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

- Interactive diagram: https://gitdiagram.com/cczhong11/xiaogpt
- Repository: https://github.com/cczhong11/xiaogpt

## Overview

##### Main Components and Their Roles
- LangChain Integration: Represent the ‘xiaogpt/langchain’ folder, which adds extra layers of functionality (like on-the-fly search or advanced conversation management) when the --use_langchain flag is applied.
- TTS Modules: Show the ‘xiaogpt/tts’ folder, which abstracts various text-to-speech implementations. List or group different files like base.py, file.py, live.py, and mi.py that implement different methods for interacting with Xiaomi or third-party TTS providers.
- External Services & APIs: Include external services such as:
- ChatGPT, ChatGLM, Gemini, Doubao, Moonshot, 01 API, Llama, and others (as noted in the README).
- TTS providers like Edge, Azure, OpenAI, Fish Audio, etc.

##### Relationships and Data Flow
- Within the Bot Manager, show how a selected bot sends requests to external APIs (e.g., ChatGPT or Gemini) and receives responses.
- The response flow should continue from the Bot module to the TTS modules, converting textual replies into speech output that is finally sent to the Xiaomi AI Speaker.
- Feedback loops (for sustained conversations) as noted in the README (via commands like “开始持续对话” and “结束持续对话”).

##### Architectural Patterns & Design Principles
- Modular Separation: The project is modularized by separating bot implementations, TTS methods, CLI handling, and configuration. This suggests a clean separation of concerns.
- Plug-In Style: The ability to choose different bots and TTS engines by command-line options or config (for example, switching between chatgptapi, gemini, etc.) implies a plug-in or strategy design pattern.

##### Relevant Technologies and Frameworks
- Python 3.8+ is the runtime environment.
- PDM for dependency management (see pyproject.toml and pdm.lock).
- Docker is used for containerization, which can be represented in a “Deployment” section.
- GitHub Actions workflows indicate automated build and release via CI.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CLI Interface Layer
    subgraph "CLI Interface Layer"
        cliMain["CLI Main (xiaogpt.py)"]:::cli
        cliMod["CLI Module (cli.py)"]:::cli
    end

    %% Core Processing Layer
    subgraph "Core Processing Layer"
        subgraph "Configuration"
            configLoader["Config Loader (config.py)"]:::config
            configYAML["Config YAML (xiao_config.yaml.example)"]:::config
        end
        botManager["Bot Manager"]:::internal
        langChain["LangChain Integration"]:::internal
        ttsEngine["TTS Engine"]:::internal
    end

    %% External Services Layer
    subgraph "External Services Layer"
        extChat["External Chat APIs"]:::external
        extTTS["External TTS Providers"]:::external
        device["Xiaomi AI Speaker"]:::external
    end

    %% CI/CD & Deployment
    subgraph "CI/CD & Deployment"
        ciWorkflows["CI Workflows (.github/workflows)"]:::ci
        docker["Docker Deployment (Dockerfile)"]:::ci
    end

    %% Connections from CLI to Configuration
    cliMain -->|"parses"| configLoader
    cliMod  -->|"parses"| configLoader
    cliMain -->|"parses"| configYAML
    cliMod  -->|"parses"| configYAML

    %% Connections from Configuration to Core Modules
    configLoader -->|"selects_Bot"| botManager
    configLoader -->|"selects_TTS"| ttsEngine
    configLoader -->|"enables_LangChain"| langChain

    %% LangChain augments Bot Manager
    langChain -->|"augments"| botManager

    %% Bot Manager calls External Chat APIs and sends response to TTS Engine
    botManager -->|"calls_API"| extChat
    botManager -->|"outputs_Response"| ttsEngine

    %% TTS Engine converts text to speech via External TTS Providers and outputs to Device
    ttsEngine -->|"converts_toSpeech"| extTTS
    extTTS -->|"sends_to"| device

    %% Click Events
    click cliMain "https://github.com/cczhong11/xiaogpt/blob/main/xiaogpt.py"
    click cliMod "https://github.com/cczhong11/xiaogpt/blob/main/xiaogpt/cli.py"
    click configLoader "https://github.com/cczhong11/xiaogpt/blob/main/xiaogpt/config.py"
    click configYAML "https://github.com/cczhong11/xiaogpt/blob/main/xiao_config.yaml.example"
    click botManager "https://github.com/cczhong11/xiaogpt/tree/main/xiaogpt/bot"
    click langChain "https://github.com/cczhong11/xiaogpt/tree/main/xiaogpt/langchain"
    click ttsEngine "https://github.com/cczhong11/xiaogpt/tree/main/xiaogpt/tts"
    click ciWorkflows "https://github.com/cczhong11/xiaogpt/tree/main/.github/workflows"
    click docker "https://github.com/cczhong11/xiaogpt/tree/main/Dockerfile"

    %% Styles
    classDef cli fill:#f9e,stroke:#333,stroke-width:2px;
    classDef config fill:#bbf,stroke:#333,stroke-width:2px;
    classDef internal fill:#cde,stroke:#333,stroke-width:2px;
    classDef external fill:#cfc,stroke:#333,stroke-width:2px;
    classDef ci fill:#ffc,stroke:#333,stroke-width:2px;
```
