# li2589920489/ai-cs-agent architecture

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

- Interactive diagram: https://gitdiagram.com/li2589920489/ai-cs-agent
- Repository: https://github.com/li2589920489/ai-cs-agent

## Overview

This is an ecommerce customer-support application with a Next.js buyer/agent workspace and a FastAPI backend. The main workflow is message intake, Triage handoff to a business agent, tool-backed order/product/policy work, and a streamed reply or human escalation. Separate branches cover knowledge administration and retrieval, tenant authentication, MCP exposure, and Taobao/Douyin integrations. Edges reflect README statements or the supplied source index and excerpts; unsampled routes and integrations are represented only where documented.

Main entry points: [`python-backend/chat_service.py`](https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/chat_service.py) (Chat orchestration), [`python-backend/main.py`](https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/main.py) (FastAPI routes), [`python-backend/ecommerce/tools.py`](https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/ecommerce/tools.py) (Business tools), [`python-backend/rag/pipeline.py`](https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/rag/pipeline.py) (RAG retrieval)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Customer experience"]
  node_workspace["Support workspace<br/>[page.tsx]"]
  node_chat_ui["Chat interface<br/>[chat-panel.tsx]"]
  node_stream_client["Stream decoder<br/>[chat-stream.ts]"]
end

subgraph group_conversation["Conversation and agents"]
  node_api["FastAPI routes<br/>[main.py]"]
  node_chat_service["Chat orchestration<br/>[chat_service.py]"]
  node_ecom_agents["Ecommerce agents<br/>[agents.py]"]
  node_airline_agents["Airline agents<br/>[agents.py]"]
  node_chat_context["Conversation context<br/>[context.py]"]
end

subgraph group_capabilities["Business capabilities"]
  node_business_tools["Business tools<br/>[tools.py]"]
  node_orders[("Order and returns<br/>[order_store.py]")]
  node_escalation["Human escalation<br/>[main.py]"]
end

subgraph group_knowledge["Knowledge and retrieval"]
  node_knowledge_api[("Knowledge management<br/>[knowledge_store.py]")]
  node_doc_import["Document import<br/>[doc_importer.py]"]
  node_rag["RAG retrieval<br/>[pipeline.py]"]
  node_embedding["Text embeddings<br/>[embedding.py]"]
  node_bm25["BM25 retrieval<br/>[bm25.py]"]
  node_reranker["Result reranking<br/>[reranker.py]"]
end

subgraph group_platform["Persistence and integrations"]
  node_auth["Tenant authentication<br/>[auth.py]"]
  node_memory[("Session memory<br/>[memory_store.py]")]
  node_mcp["MCP tools<br/>[mcp_server.py]"]
  node_taobao["Taobao adapter<br/>[taobao_adapter.py]"]
  node_douyin["Douyin adapter<br/>[douyin_adapter.py]"]
end

node_buyer(("Buyer / agent"))

node_buyer -->|"uses"| node_workspace
node_workspace -->|"renders"| node_chat_ui
node_chat_ui -->|"streams through"| node_stream_client
node_stream_client -->|"posts messages"| node_api
node_api -->|"invokes"| node_chat_service
node_chat_service -->|"runs triage"| node_ecom_agents
node_chat_service -->|"builds context"| node_chat_context
node_chat_service -->|"uses sessions"| node_memory
node_ecom_agents -->|"dispatches tools"| node_business_tools
node_business_tools -->|"reads and updates"| node_orders
node_business_tools -->|"queries knowledge"| node_knowledge_api
node_business_tools -->|"searches"| node_rag
node_rag -->|"embeds queries"| node_embedding
node_rag -->|"retrieves terms"| node_bm25
node_rag -->|"reranks results"| node_reranker
node_api -->|"protects routes"| node_auth
node_api -->|"serves management"| node_knowledge_api
node_api -->|"imports documents"| node_doc_import
node_api -->|"manages tickets"| node_escalation
node_chat_service -->|"supports legacy flow"| node_airline_agents
node_mcp -.->|"exposes tools"| node_knowledge_api
node_mcp -.->|"exposes tools"| node_orders
node_taobao -->|"shares chat logic"| node_chat_service
node_douyin -->|"shares chat logic"| node_chat_service

click node_workspace "https://github.com/li2589920489/ai-cs-agent/blob/main/ui/app/page.tsx"
click node_chat_ui "https://github.com/li2589920489/ai-cs-agent/blob/main/ui/components/chat-panel.tsx"
click node_stream_client "https://github.com/li2589920489/ai-cs-agent/blob/main/ui/lib/chat-stream.ts"
click node_api "https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/main.py"
click node_chat_service "https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/chat_service.py"
click node_ecom_agents "https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/ecommerce/agents.py"
click node_airline_agents "https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/airline/agents.py"
click node_chat_context "https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/ecommerce/context.py"
click node_business_tools "https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/ecommerce/tools.py"
click node_orders "https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/order_store.py"
click node_escalation "https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/main.py"
click node_auth "https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/auth.py"
click node_knowledge_api "https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/knowledge_store.py"
click node_doc_import "https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/doc_importer.py"
click node_rag "https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/rag/pipeline.py"
click node_embedding "https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/rag/embedding.py"
click node_bm25 "https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/rag/bm25.py"
click node_reranker "https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/rag/reranker.py"
click node_memory "https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/memory_store.py"
click node_mcp "https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/mcp_server.py"
click node_taobao "https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/taobao_adapter.py"
click node_douyin "https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/douyin_adapter.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_workspace,node_chat_ui,node_stream_client toneBlue
class node_api,node_chat_service,node_ecom_agents,node_airline_agents,node_chat_context toneAmber
class node_business_tools,node_orders,node_escalation toneMint
class node_knowledge_api,node_doc_import,node_rag,node_embedding,node_bm25,node_reranker toneRose
class node_auth,node_memory,node_mcp,node_taobao,node_douyin,node_buyer toneIndigo
```

## Components

### Customer experience

- [Support workspace](https://github.com/li2589920489/ai-cs-agent/blob/main/ui/app/page.tsx): `ui/app/page.tsx`
- [Chat interface](https://github.com/li2589920489/ai-cs-agent/blob/main/ui/components/chat-panel.tsx): `ui/components/chat-panel.tsx`
- [Stream decoder](https://github.com/li2589920489/ai-cs-agent/blob/main/ui/lib/chat-stream.ts): `ui/lib/chat-stream.ts`

### Conversation and agents

- [FastAPI routes](https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/main.py): `python-backend/main.py`
- [Chat orchestration](https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/chat_service.py): `python-backend/chat_service.py`
- [Ecommerce agents](https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/ecommerce/agents.py): `python-backend/ecommerce/agents.py`
- [Airline agents](https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/airline/agents.py): `python-backend/airline/agents.py`
- [Conversation context](https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/ecommerce/context.py): `python-backend/ecommerce/context.py`

### Business capabilities

- [Business tools](https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/ecommerce/tools.py): `python-backend/ecommerce/tools.py`
- [Order and returns](https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/order_store.py): `python-backend/order_store.py`
- [Human escalation](https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/main.py): `python-backend/main.py`

### Knowledge and retrieval

- [Knowledge management](https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/knowledge_store.py): `python-backend/knowledge_store.py`
- [Document import](https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/doc_importer.py): `python-backend/doc_importer.py`
- [RAG retrieval](https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/rag/pipeline.py): `python-backend/rag/pipeline.py`
- [Text embeddings](https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/rag/embedding.py): `python-backend/rag/embedding.py`
- [BM25 retrieval](https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/rag/bm25.py): `python-backend/rag/bm25.py`
- [Result reranking](https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/rag/reranker.py): `python-backend/rag/reranker.py`

### Persistence and integrations

- [Tenant authentication](https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/auth.py): `python-backend/auth.py`
- [Session memory](https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/memory_store.py): `python-backend/memory_store.py`
- [MCP tools](https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/mcp_server.py): `python-backend/mcp_server.py`
- [Taobao adapter](https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/taobao_adapter.py): `python-backend/taobao_adapter.py`
- [Douyin adapter](https://github.com/li2589920489/ai-cs-agent/blob/main/python-backend/douyin_adapter.py): `python-backend/douyin_adapter.py`

### Other components

- **Buyer / agent**

## Connections

- Buyer / agent → Support workspace: uses
- Support workspace → Chat interface: renders (evidence: `ui/app/page.tsx`)
- Chat interface → Stream decoder: streams through (evidence: `ui/lib/chat-stream.ts`)
- Stream decoder → FastAPI routes: posts messages
- FastAPI routes → Chat orchestration: invokes (evidence: `python-backend/main.py`)
- Chat orchestration → Ecommerce agents: runs triage (evidence: `python-backend/chat_service.py`)
- Chat orchestration → Conversation context: builds context (evidence: `python-backend/chat_service.py`)
- Chat orchestration → Session memory: uses sessions (evidence: `python-backend/chat_service.py`)
- Ecommerce agents → Business tools: dispatches tools (evidence: `python-backend/ecommerce/agents.py`)
- Business tools → Order and returns: reads and updates (evidence: `python-backend/ecommerce/tools.py`)
- Business tools → Knowledge management: queries knowledge (evidence: `python-backend/ecommerce/tools.py`)
- Business tools → RAG retrieval: searches (evidence: `python-backend/ecommerce/tools.py`)
- RAG retrieval → Text embeddings: embeds queries (evidence: `python-backend/rag/pipeline.py`)
- RAG retrieval → BM25 retrieval: retrieves terms (evidence: `python-backend/rag/pipeline.py`)
- RAG retrieval → Result reranking: reranks results (evidence: `python-backend/rag/pipeline.py`)
- FastAPI routes → Tenant authentication: protects routes (evidence: `python-backend/main.py`)
- FastAPI routes → Knowledge management: serves management (evidence: `python-backend/main.py`)
- FastAPI routes → Document import: imports documents (evidence: `python-backend/main.py`)
- FastAPI routes → Human escalation: manages tickets (evidence: `python-backend/main.py`)
- Chat orchestration → Airline agents: supports legacy flow (evidence: `python-backend/chat_service.py`)
- MCP tools → Knowledge management: exposes tools
- MCP tools → Order and returns: exposes tools
- Taobao adapter → Chat orchestration: shares chat logic (evidence: `python-backend/taobao_adapter.py`)
- Douyin adapter → Chat orchestration: shares chat logic
