# xiaofangstudio/ai-xiaofang architecture

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

- Interactive diagram: https://gitdiagram.com/xiaofangstudio/ai-xiaofang
- Repository: https://github.com/xiaofangstudio/ai-xiaofang

## Overview

AI 小方 is a local Chinese AI assistant. The documented main workflow is Web or CLI input → local judgment and routing → llama.cpp expression → self-review and output; the Web also manages conversations and multimodal input. The README describes several Covi 2 subsystems whose implementation files are absent from this tree, so those nodes have null paths and documented relationships cite the README. The sampled code is mostly Covi 1 and earlier; its historical runtime and training tool are shown separately, not as the current request pipeline.

Main entry points: [`Web界面/app.js`](https://github.com/xiaofangstudio/ai-xiaofang/blob/main/Web%E7%95%8C%E9%9D%A2/app.js) (Web interface), [`历史版本/v0.4search/xiaofang_data_v04search.py`](https://github.com/xiaofangstudio/ai-xiaofang/blob/main/%E5%8E%86%E5%8F%B2%E7%89%88%E6%9C%AC/v0.4search/xiaofang_data_v04search.py) (Legacy knowledge data), [`历史版本/v0.1/xiaofang.py`](https://github.com/xiaofangstudio/ai-xiaofang/blob/main/%E5%8E%86%E5%8F%B2%E7%89%88%E6%9C%AC/v0.1/xiaofang.py) (Early runtime), [`历史版本/v0.2/xiaofang.py`](https://github.com/xiaofangstudio/ai-xiaofang/blob/main/%E5%8E%86%E5%8F%B2%E7%89%88%E6%9C%AC/v0.2/xiaofang.py) (Early runtime v0.2)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interaction["User interaction"]
  node_web["Web interface<br/>[app.js]"]
  node_cli["CLI interface"]
  node_history["Conversation controls<br/>[app.js]"]
end

subgraph group_assistant["Assistant pipeline"]
  node_intake["Input judgment"]
  node_intent["Intent routing"]
  node_expression["Qwen expression"]
  node_review["Output review"]
  node_runtime["llama.cpp server"]
end

subgraph group_capabilities["Assistant capabilities"]
  node_vision["Image and video"]
  node_search["Web search"]
  node_memory[("Memory and learning")]
  node_plugins["Skills and skins"]
  node_settings["Persistent settings"]
end

subgraph group_legacy["Earlier versions"]
  node_legacy["Covi 1 runtime<br/>[xiaofang_covi1.py]"]
  node_legacydata[("Legacy knowledge data")]
  node_legacyv1["Early runtime<br/>[xiaofang.py]"]
  node_legacyv2["Early runtime v0.2<br/>[xiaofang.py]"]
  node_flash["Flash runtime"]
  node_flashdata[("Flash knowledge data")]
  node_training["Novel training tool<br/>[学习小说.py]"]
end

node_user(("User"))

node_user -->|"sends input"| node_web
node_user -->|"sends input"| node_cli
node_web -->|"submits input"| node_intake
node_cli -.->|"submits input"| node_intake
node_intake -->|"routes request"| node_intent
node_intent -->|"requests generation"| node_runtime
node_runtime -->|"streams tokens"| node_expression
node_expression -->|"returns draft"| node_review
node_review -.->|"delivers answer"| node_web
node_web -->|"attaches media"| node_vision
node_intent -.->|"may search"| node_search
node_review -.->|"trains on answer"| node_memory
node_web -->|"manages chats"| node_history
node_web -.->|"offers skills"| node_plugins
node_web -.->|"changes settings"| node_settings
node_legacyv1 -->|"imports data"| node_legacydata
node_legacyv2 -->|"imports data"| node_legacydata
node_flash -->|"uses knowledge"| node_flashdata
node_training -->|"trains weights"| node_legacy

click node_web "https://github.com/xiaofangstudio/ai-xiaofang/blob/main/Web%E7%95%8C%E9%9D%A2/app.js"
click node_history "https://github.com/xiaofangstudio/ai-xiaofang/blob/main/Web%E7%95%8C%E9%9D%A2/app.js"
click node_settings "https://github.com/xiaofangstudio/ai-xiaofang/blob/main/xiaofang_settings.py"
click node_legacy "https://github.com/xiaofangstudio/ai-xiaofang/blob/main/xiaofang_covi1.py"
click node_legacydata "https://github.com/xiaofangstudio/ai-xiaofang/blob/main/%E5%8E%86%E5%8F%B2%E7%89%88%E6%9C%AC/v0.4search/xiaofang_data_v04search.py"
click node_legacyv1 "https://github.com/xiaofangstudio/ai-xiaofang/blob/main/%E5%8E%86%E5%8F%B2%E7%89%88%E6%9C%AC/v0.1/xiaofang.py"
click node_legacyv2 "https://github.com/xiaofangstudio/ai-xiaofang/blob/main/%E5%8E%86%E5%8F%B2%E7%89%88%E6%9C%AC/v0.2/xiaofang.py"
click node_flash "https://github.com/xiaofangstudio/ai-xiaofang/blob/main/%E5%8E%86%E5%8F%B2%E7%89%88%E6%9C%AC/v1.7_flash/xiaofang_v17alpha.py"
click node_flashdata "https://github.com/xiaofangstudio/ai-xiaofang/blob/main/%E5%8E%86%E5%8F%B2%E7%89%88%E6%9C%AC/v1.7_flash/xiaofang_data_v17alpha.py"
click node_training "https://github.com/xiaofangstudio/ai-xiaofang/blob/main/%E5%8E%86%E5%8F%B2%E7%89%88%E6%9C%AC/_%E8%AE%AD%E7%BB%83%E8%84%9A%E6%9C%AC%E5%AD%98%E6%A1%A3/%E5%AD%A6%E4%B9%A0%E5%B0%8F%E8%AF%B4.py"

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_web,node_cli,node_history,node_user toneBlue
class node_intake,node_intent,node_expression,node_review,node_runtime toneAmber
class node_vision,node_search,node_memory,node_plugins,node_settings toneMint
class node_legacy,node_legacydata,node_legacyv1,node_legacyv2,node_flash,node_flashdata,node_training toneRose
```

## Components

### User interaction

- [Web interface](https://github.com/xiaofangstudio/ai-xiaofang/blob/main/Web%E7%95%8C%E9%9D%A2/app.js): `Web界面/app.js`
- **CLI interface**
- [Conversation controls](https://github.com/xiaofangstudio/ai-xiaofang/blob/main/Web%E7%95%8C%E9%9D%A2/app.js): `Web界面/app.js`

### Assistant pipeline

- **Input judgment**
- **Intent routing**
- **Qwen expression**
- **Output review**
- **llama.cpp server**

### Assistant capabilities

- **Image and video**
- **Web search**
- **Memory and learning**
- **Skills and skins**
- [Persistent settings](https://github.com/xiaofangstudio/ai-xiaofang/blob/main/xiaofang_settings.py): `xiaofang_settings.py`

### Earlier versions

- [Covi 1 runtime](https://github.com/xiaofangstudio/ai-xiaofang/blob/main/xiaofang_covi1.py): `xiaofang_covi1.py`
- [Legacy knowledge data](https://github.com/xiaofangstudio/ai-xiaofang/blob/main/%E5%8E%86%E5%8F%B2%E7%89%88%E6%9C%AC/v0.4search/xiaofang_data_v04search.py): `历史版本/v0.4search/xiaofang_data_v04search.py`
- [Early runtime](https://github.com/xiaofangstudio/ai-xiaofang/blob/main/%E5%8E%86%E5%8F%B2%E7%89%88%E6%9C%AC/v0.1/xiaofang.py): `历史版本/v0.1/xiaofang.py`
- [Early runtime v0.2](https://github.com/xiaofangstudio/ai-xiaofang/blob/main/%E5%8E%86%E5%8F%B2%E7%89%88%E6%9C%AC/v0.2/xiaofang.py): `历史版本/v0.2/xiaofang.py`
- [Flash runtime](https://github.com/xiaofangstudio/ai-xiaofang/blob/main/%E5%8E%86%E5%8F%B2%E7%89%88%E6%9C%AC/v1.7_flash/xiaofang_v17alpha.py): `历史版本/v1.7_flash/xiaofang_v17alpha.py`
- [Flash knowledge data](https://github.com/xiaofangstudio/ai-xiaofang/blob/main/%E5%8E%86%E5%8F%B2%E7%89%88%E6%9C%AC/v1.7_flash/xiaofang_data_v17alpha.py): `历史版本/v1.7_flash/xiaofang_data_v17alpha.py`
- [Novel training tool](https://github.com/xiaofangstudio/ai-xiaofang/blob/main/%E5%8E%86%E5%8F%B2%E7%89%88%E6%9C%AC/_%E8%AE%AD%E7%BB%83%E8%84%9A%E6%9C%AC%E5%AD%98%E6%A1%A3/%E5%AD%A6%E4%B9%A0%E5%B0%8F%E8%AF%B4.py): `历史版本/_训练脚本存档/学习小说.py`

### Other components

- **User**

## Connections

- User → Web interface: sends input
- User → CLI interface: sends input
- Web interface → Input judgment: submits input
- CLI interface → Input judgment: submits input
- Input judgment → Intent routing: routes request
- Intent routing → llama.cpp server: requests generation
- llama.cpp server → Qwen expression: streams tokens
- Qwen expression → Output review: returns draft
- Output review → Web interface: delivers answer
- Web interface → Image and video: attaches media
- Intent routing → Web search: may search
- Output review → Memory and learning: trains on answer
- Web interface → Conversation controls: manages chats (evidence: `Web界面/app.js`)
- Web interface → Skills and skins: offers skills
- Web interface → Persistent settings: changes settings
- Early runtime → Legacy knowledge data: imports data (evidence: `历史版本/v0.1/xiaofang.py`)
- Early runtime v0.2 → Legacy knowledge data: imports data (evidence: `历史版本/v0.2/xiaofang.py`)
- Flash runtime → Flash knowledge data: uses knowledge (evidence: `历史版本/v1.7_flash/xiaofang_v17alpha.py`)
- Novel training tool → Covi 1 runtime: trains weights (evidence: `历史版本/_训练脚本存档/学习小说.py`)
