# chatchat-space/langchain-chatchat architecture

> Architecture diagram of the GitHub repository chatchat-space/langchain-chatchat, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/chatchat-space/langchain-chatchat
- Repository: https://github.com/chatchat-space/langchain-chatchat

## Overview

LangChain-Chatchat is an offline-capable RAG, chat, and agent application exposed through FastAPI and a WebUI, with a Python SDK for clients. The principal workflow accepts a user question, routes it to chat handling, retrieves relevant knowledge when requested, and uses a configured language model to produce a response. Knowledge-base management and ingestion, file RAG, agents and tools, OpenAI-compatible model APIs, and persistent conversation/configuration state are distinct supporting capabilities. The README documents the retrieval stages; source-index references show route-to-handler and SDK relationships, but many internal calls were not sampled.

Main entry points: [`libs/chatchat-server/chatchat/server/api_server/chat_routes.py`](https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/server/api_server/chat_routes.py) (Chat Routes), [`libs/chatchat-server/chatchat/server/file_rag`](https://github.com/chatchat-space/langchain-chatchat/tree/master/libs/chatchat-server/chatchat/server/file_rag) (File RAG), [`libs/chatchat-server/chatchat/server/chat/chat.py`](https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/server/chat/chat.py) (Chat Handling), [`libs/chatchat-server/chatchat/server/chat/kb_chat.py`](https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/server/chat/kb_chat.py) (Knowledge Chat)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User Interfaces"]
  node_api["HTTP API<br/>[server_app.py]"]
  node_chat_routes["Chat Routes<br/>[chat_routes.py]"]
  node_kb_routes["KB Routes<br/>[kb_routes.py]"]
  node_openai_routes["OpenAI Routes<br/>[openai_routes.py]"]
  node_webui["WebUI<br/>[webui.py]"]
  node_sdk["Python SDK<br/>[api_client.py]"]
end

subgraph group_chat["Chat and Agents"]
  node_chat_core["Chat Handling<br/>[chat.py]"]
  node_kb_chat["Knowledge Chat<br/>[kb_chat.py]"]
  node_file_chat["File Chat<br/>[file_chat.py]"]
  node_agent["Agent Runtime<br/>[all_tools_agent.py]"]
  node_agent_tools["Agent Tools<br/>[tools_registry.py]"]
end

subgraph group_knowledge["Knowledge Retrieval"]
  node_kb_manage["Knowledge Management<br/>[kb_doc_api.py]"]
  node_kb_service["Knowledge Services<br/>[base.py]"]
  node_file_rag["File RAG"]
  node_vector_store[("Vector Store")]
end

subgraph group_models["Models and Tools"]
  node_model_api["Model API<br/>[openai_routes.py]"]
  node_embeddings["Embeddings"]
end

subgraph group_state["Configuration and State"]
  node_settings["Settings<br/>[settings.py]"]
  node_database[("Application Database")]
  node_schemas["API Schemas<br/>[api_schemas.py]"]
end

node_user(("User"))
node_external_model{{"Model Provider"}}

node_user -->|"submits request"| node_api
node_user -->|"uses"| node_webui
node_api -.->|"routes chat"| node_chat_routes
node_chat_routes -->|"dispatches chat"| node_chat_core
node_chat_routes -->|"dispatches KB chat"| node_kb_chat
node_chat_routes -->|"dispatches file chat"| node_file_chat
node_kb_routes -->|"manages documents"| node_kb_manage
node_chat_core -.->|"uses agent"| node_agent
node_agent -.->|"invokes tools"| node_agent_tools
node_kb_chat -.->|"retrieves context"| node_file_rag
node_file_chat -.->|"processes files"| node_file_rag
node_user -->|"uploads documents"| node_kb_manage
node_kb_manage -->|"loads and splits"| node_file_rag
node_file_rag -->|"vectorizes text"| node_embeddings
node_embeddings -->|"indexes vectors"| node_vector_store
node_kb_chat -->|"searches vectors"| node_vector_store
node_chat_core -.->|"requests completion"| node_model_api
node_openai_routes -.->|"forwards request"| node_external_model
node_model_api -.->|"calls model"| node_external_model
node_sdk -.->|"sends HTTP requests"| node_api
node_chat_routes -->|"uses request schemas"| node_schemas
node_openai_routes -->|"uses request schemas"| node_schemas
node_kb_routes -.->|"accesses persistent state"| node_database
node_settings -.->|"configures backends"| node_vector_store

click node_api "https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/server/api_server/server_app.py"
click node_chat_routes "https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/server/api_server/chat_routes.py"
click node_kb_routes "https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/server/api_server/kb_routes.py"
click node_openai_routes "https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/server/api_server/openai_routes.py"
click node_webui "https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/webui.py"
click node_sdk "https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/python-sdk/open_chatcaht/api_client.py"
click node_chat_core "https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/server/chat/chat.py"
click node_kb_chat "https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/server/chat/kb_chat.py"
click node_file_chat "https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/server/chat/file_chat.py"
click node_agent "https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/langchain_chatchat/agents/all_tools_agent.py"
click node_agent_tools "https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/server/agent/tools_factory/tools_registry.py"
click node_kb_manage "https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/server/knowledge_base/kb_doc_api.py"
click node_kb_service "https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/server/knowledge_base/kb_service/base.py"
click node_file_rag "https://github.com/chatchat-space/langchain-chatchat/tree/master/libs/chatchat-server/chatchat/server/file_rag"
click node_vector_store "https://github.com/chatchat-space/langchain-chatchat/tree/master/libs/chatchat-server/chatchat/server/knowledge_base/kb_service"
click node_model_api "https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/server/api_server/openai_routes.py"
click node_embeddings "https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/server/localai_embeddings.py"
click node_settings "https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/settings.py"
click node_database "https://github.com/chatchat-space/langchain-chatchat/tree/master/libs/chatchat-server/chatchat/server/db"
click node_schemas "https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/server/api_server/api_schemas.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_api,node_chat_routes,node_kb_routes,node_openai_routes,node_webui,node_sdk,node_user toneBlue
class node_chat_core,node_kb_chat,node_file_chat,node_agent,node_agent_tools toneAmber
class node_kb_manage,node_kb_service,node_file_rag,node_vector_store toneMint
class node_model_api,node_embeddings toneRose
class node_settings,node_database,node_schemas,node_external_model toneIndigo
```

## Components

### User Interfaces

- [HTTP API](https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/server/api_server/server_app.py): `libs/chatchat-server/chatchat/server/api_server/server_app.py`
- [Chat Routes](https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/server/api_server/chat_routes.py): `libs/chatchat-server/chatchat/server/api_server/chat_routes.py`
- [KB Routes](https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/server/api_server/kb_routes.py): `libs/chatchat-server/chatchat/server/api_server/kb_routes.py`
- [OpenAI Routes](https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/server/api_server/openai_routes.py): `libs/chatchat-server/chatchat/server/api_server/openai_routes.py`
- [WebUI](https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/webui.py): `libs/chatchat-server/chatchat/webui.py`
- [Python SDK](https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/python-sdk/open_chatcaht/api_client.py): `libs/python-sdk/open_chatcaht/api_client.py`

### Chat and Agents

- [Chat Handling](https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/server/chat/chat.py): `libs/chatchat-server/chatchat/server/chat/chat.py`
- [Knowledge Chat](https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/server/chat/kb_chat.py): `libs/chatchat-server/chatchat/server/chat/kb_chat.py`
- [File Chat](https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/server/chat/file_chat.py): `libs/chatchat-server/chatchat/server/chat/file_chat.py`
- [Agent Runtime](https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/langchain_chatchat/agents/all_tools_agent.py): `libs/chatchat-server/langchain_chatchat/agents/all_tools_agent.py`
- [Agent Tools](https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/server/agent/tools_factory/tools_registry.py): `libs/chatchat-server/chatchat/server/agent/tools_factory/tools_registry.py`

### Knowledge Retrieval

- [Knowledge Management](https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/server/knowledge_base/kb_doc_api.py): `libs/chatchat-server/chatchat/server/knowledge_base/kb_doc_api.py`
- [Knowledge Services](https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/server/knowledge_base/kb_service/base.py): `libs/chatchat-server/chatchat/server/knowledge_base/kb_service/base.py`
- [File RAG](https://github.com/chatchat-space/langchain-chatchat/tree/master/libs/chatchat-server/chatchat/server/file_rag): `libs/chatchat-server/chatchat/server/file_rag`
- [Vector Store](https://github.com/chatchat-space/langchain-chatchat/tree/master/libs/chatchat-server/chatchat/server/knowledge_base/kb_service): `libs/chatchat-server/chatchat/server/knowledge_base/kb_service`

### Models and Tools

- [Model API](https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/server/api_server/openai_routes.py): `libs/chatchat-server/chatchat/server/api_server/openai_routes.py`
- [Embeddings](https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/server/localai_embeddings.py): `libs/chatchat-server/chatchat/server/localai_embeddings.py`

### Configuration and State

- [Settings](https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/settings.py): `libs/chatchat-server/chatchat/settings.py`
- [Application Database](https://github.com/chatchat-space/langchain-chatchat/tree/master/libs/chatchat-server/chatchat/server/db): `libs/chatchat-server/chatchat/server/db`
- [API Schemas](https://github.com/chatchat-space/langchain-chatchat/blob/master/libs/chatchat-server/chatchat/server/api_server/api_schemas.py): `libs/chatchat-server/chatchat/server/api_server/api_schemas.py`

### Other components

- **User**
- **Model Provider**

## Connections

- User → HTTP API: submits request (evidence: `README.md`)
- User → WebUI: uses (evidence: `README.md`)
- HTTP API → Chat Routes: routes chat
- Chat Routes → Chat Handling: dispatches chat (evidence: `libs/chatchat-server/chatchat/server/api_server/chat_routes.py`)
- Chat Routes → Knowledge Chat: dispatches KB chat (evidence: `libs/chatchat-server/chatchat/server/api_server/chat_routes.py`)
- Chat Routes → File Chat: dispatches file chat (evidence: `libs/chatchat-server/chatchat/server/api_server/chat_routes.py`)
- KB Routes → Knowledge Management: manages documents (evidence: `libs/chatchat-server/chatchat/server/api_server/kb_routes.py`)
- Chat Handling → Agent Runtime: uses agent
- Agent Runtime → Agent Tools: invokes tools
- Knowledge Chat → File RAG: retrieves context
- File Chat → File RAG: processes files
- User → Knowledge Management: uploads documents (evidence: `README.md`)
- Knowledge Management → File RAG: loads and splits (evidence: `README.md`)
- File RAG → Embeddings: vectorizes text (evidence: `README.md`)
- Embeddings → Vector Store: indexes vectors (evidence: `README.md`)
- Knowledge Chat → Vector Store: searches vectors (evidence: `README.md`)
- Chat Handling → Model API: requests completion
- OpenAI Routes → Model Provider: forwards request (evidence: `libs/chatchat-server/chatchat/server/api_server/openai_routes.py`)
- Model API → Model Provider: calls model
- Python SDK → HTTP API: sends HTTP requests
- Chat Routes → API Schemas: uses request schemas (evidence: `libs/chatchat-server/chatchat/server/api_server/chat_routes.py`)
- OpenAI Routes → API Schemas: uses request schemas (evidence: `libs/chatchat-server/chatchat/server/api_server/openai_routes.py`)
- KB Routes → Application Database: accesses persistent state
- Settings → Vector Store: configures backends (evidence: `libs/chatchat-server/chatchat/server/knowledge_base/kb_service/es_kb_service.py`)
