# xiejinhe/xianyu-auto-reply architecture

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

- Interactive diagram: https://gitdiagram.com/xiejinhe/xianyu-auto-reply
- Repository: https://github.com/xiejinhe/xianyu-auto-reply

## Overview

闲鱼自动回复系统由主 Web 前端、业务 API、实时消息服务和定时任务服务组成，并另有独立返佣子系统。典型流程是用户在界面管理账号或业务配置，主 API 处理请求并使用共享数据；实时聊天和自动回复由 WebSocket 服务处理，订单、发货及维护任务由调度服务执行。README 明确了主要能力与服务职责；未采样的业务实现仅按 README 和文件树归纳，相关边使用 README 作为证据。

Main entry points: [`backend-web/app/api/routes`](https://github.com/xiejinhe/xianyu-auto-reply/tree/main/backend-web/app/api/routes) (业务接口), [`scheduler/app/services/scheduler`](https://github.com/xiejinhe/xianyu-auto-reply/tree/main/scheduler/app/services/scheduler) (定时业务任务), [`promotion/backend/app/services`](https://github.com/xiejinhe/xianyu-auto-reply/tree/main/promotion/backend/app/services) (选品与发布规则), [`scheduler/app/services/scheduler_service.py`](https://github.com/xiejinhe/xianyu-auto-reply/blob/main/scheduler/app/services/scheduler_service.py) (任务调度器)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["主系统界面"]
  node_main_ui["管理界面<br/>[App.tsx]"]
  node_chat_ui["在线聊天界面<br/>[ChatNew.tsx]"]
  node_publish_ui["商品发布界面"]
end

subgraph group_api["主业务 API"]
  node_api_routes["业务接口"]
  node_account_mgmt["账号管理"]
  node_listing["商品发布与采集"]
  node_orders["订单与发货<br/>[order_service.py]"]
  node_notifications["通知与风控"]
end

subgraph group_runtime["实时与调度"]
  node_chat_service["闲鱼实时连接<br/>[im_client.py]"]
  node_ai_reply["AI 自动回复<br/>[ai_reply_engine.py]"]
  node_delivery_rules["发货规则检查<br/>[rule_engine.py]"]
  node_scheduler["任务调度器"]
  node_scheduled_tasks["定时业务任务"]
end

subgraph group_shared["共享数据与能力"]
  node_mysql[("MySQL 数据")]
  node_redis[("Redis")]
  node_models["共享数据模型"]
  node_common_services["共享业务能力"]
end

subgraph group_promotion["返佣子系统"]
  node_promotion_ui["返佣管理界面<br/>[App.tsx]"]
  node_promotion_api["返佣业务 API<br/>[main.py]"]
  node_promotion_rules["选品与发布规则"]
  node_promotion_data[("返佣素材与规则数据")]
end

node_operator(("运营用户"))
node_xianyu(("闲鱼平台"))

node_operator -->|"操作"| node_main_ui
node_main_ui -->|"请求接口"| node_api_routes
node_chat_ui -->|"请求聊天"| node_api_routes
node_publish_ui -->|"提交发布"| node_api_routes
node_api_routes -->|"管理账号"| node_account_mgmt
node_api_routes -->|"处理发布采集"| node_listing
node_api_routes -->|"处理订单"| node_orders
node_api_routes -->|"管理通知风控"| node_notifications
node_api_routes -.->|"调用实时服务"| node_chat_service
node_chat_service -->|"收发消息"| node_xianyu
node_ai_reply -.->|"生成回复"| node_xianyu
node_scheduler -->|"调度任务"| node_scheduled_tasks
node_scheduled_tasks -->|"执行自动发货"| node_orders
node_scheduled_tasks -->|"刷新 Cookie"| node_account_mgmt
node_scheduled_tasks -->|"执行订单与评价操作"| node_xianyu
node_delivery_rules -->|"读取规则"| node_mysql
node_api_routes -->|"读写业务数据"| node_mysql
node_scheduler -->|"读取任务配置"| node_mysql
node_api_routes -->|"使用缓存"| node_redis
node_mysql -->|"持久化模型"| node_models
node_common_services -.->|"提供平台能力"| node_xianyu
node_operator -->|"管理返佣商品"| node_promotion_ui
node_promotion_ui -->|"请求接口"| node_promotion_api
node_promotion_api -->|"管理与执行规则"| node_promotion_rules
node_promotion_rules -.->|"维护素材规则"| node_promotion_data
node_promotion_rules -->|"抓取并发布"| node_xianyu
node_promotion_rules -.->|"复用发布能力"| node_common_services

click node_main_ui "https://github.com/xiejinhe/xianyu-auto-reply/blob/main/frontend/src/App.tsx"
click node_chat_ui "https://github.com/xiejinhe/xianyu-auto-reply/blob/main/frontend/src/pages/chat-new/ChatNew.tsx"
click node_publish_ui "https://github.com/xiejinhe/xianyu-auto-reply/tree/main/frontend/src/pages"
click node_api_routes "https://github.com/xiejinhe/xianyu-auto-reply/tree/main/backend-web/app/api/routes"
click node_account_mgmt "https://github.com/xiejinhe/xianyu-auto-reply/tree/main/backend-web/app/api/routes"
click node_listing "https://github.com/xiejinhe/xianyu-auto-reply/blob/main/backend-web/app/services/product_publish_service.py"
click node_orders "https://github.com/xiejinhe/xianyu-auto-reply/blob/main/backend-web/app/services/order_service.py"
click node_notifications "https://github.com/xiejinhe/xianyu-auto-reply/blob/main/backend-web/app/services/notification_service.py"
click node_chat_service "https://github.com/xiejinhe/xianyu-auto-reply/blob/main/backend-web/app/services/chat_new/im_client.py"
click node_ai_reply "https://github.com/xiejinhe/xianyu-auto-reply/blob/main/websocket/app/services/xianyu/ai_reply_engine.py"
click node_delivery_rules "https://github.com/xiejinhe/xianyu-auto-reply/blob/main/websocket/app/services/xianyu/delivery_rules/rule_engine.py"
click node_scheduler "https://github.com/xiejinhe/xianyu-auto-reply/blob/main/scheduler/app/services/scheduler_service.py"
click node_scheduled_tasks "https://github.com/xiejinhe/xianyu-auto-reply/tree/main/scheduler/app/services/scheduler"
click node_models "https://github.com/xiejinhe/xianyu-auto-reply/tree/main/common/models"
click node_common_services "https://github.com/xiejinhe/xianyu-auto-reply/tree/main/common/services"
click node_promotion_ui "https://github.com/xiejinhe/xianyu-auto-reply/blob/main/promotion/frontend/src/App.tsx"
click node_promotion_api "https://github.com/xiejinhe/xianyu-auto-reply/blob/main/promotion/backend/main.py"
click node_promotion_rules "https://github.com/xiejinhe/xianyu-auto-reply/tree/main/promotion/backend/app/services"
click node_promotion_data "https://github.com/xiejinhe/xianyu-auto-reply/tree/main/common/models"

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_main_ui,node_chat_ui,node_publish_ui toneBlue
class node_api_routes,node_account_mgmt,node_listing,node_orders,node_notifications toneAmber
class node_chat_service,node_ai_reply,node_delivery_rules,node_scheduler,node_scheduled_tasks toneMint
class node_mysql,node_redis,node_models,node_common_services toneRose
class node_promotion_ui,node_promotion_api,node_promotion_rules,node_promotion_data,node_operator,node_xianyu toneIndigo
```

## Components

### 主系统界面

- [管理界面](https://github.com/xiejinhe/xianyu-auto-reply/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [在线聊天界面](https://github.com/xiejinhe/xianyu-auto-reply/blob/main/frontend/src/pages/chat-new/ChatNew.tsx): `frontend/src/pages/chat-new/ChatNew.tsx`
- [商品发布界面](https://github.com/xiejinhe/xianyu-auto-reply/tree/main/frontend/src/pages): `frontend/src/pages`

### 主业务 API

- [业务接口](https://github.com/xiejinhe/xianyu-auto-reply/tree/main/backend-web/app/api/routes): `backend-web/app/api/routes`
- [账号管理](https://github.com/xiejinhe/xianyu-auto-reply/tree/main/backend-web/app/api/routes): `backend-web/app/api/routes`
- [商品发布与采集](https://github.com/xiejinhe/xianyu-auto-reply/blob/main/backend-web/app/services/product_publish_service.py): `backend-web/app/services/product_publish_service.py`
- [订单与发货](https://github.com/xiejinhe/xianyu-auto-reply/blob/main/backend-web/app/services/order_service.py): `backend-web/app/services/order_service.py`
- [通知与风控](https://github.com/xiejinhe/xianyu-auto-reply/blob/main/backend-web/app/services/notification_service.py): `backend-web/app/services/notification_service.py`

### 实时与调度

- [闲鱼实时连接](https://github.com/xiejinhe/xianyu-auto-reply/blob/main/backend-web/app/services/chat_new/im_client.py): `backend-web/app/services/chat_new/im_client.py`
- [AI 自动回复](https://github.com/xiejinhe/xianyu-auto-reply/blob/main/websocket/app/services/xianyu/ai_reply_engine.py): `websocket/app/services/xianyu/ai_reply_engine.py`
- [发货规则检查](https://github.com/xiejinhe/xianyu-auto-reply/blob/main/websocket/app/services/xianyu/delivery_rules/rule_engine.py): `websocket/app/services/xianyu/delivery_rules/rule_engine.py`
- [任务调度器](https://github.com/xiejinhe/xianyu-auto-reply/blob/main/scheduler/app/services/scheduler_service.py): `scheduler/app/services/scheduler_service.py`
- [定时业务任务](https://github.com/xiejinhe/xianyu-auto-reply/tree/main/scheduler/app/services/scheduler): `scheduler/app/services/scheduler`

### 共享数据与能力

- **MySQL 数据**
- **Redis**
- [共享数据模型](https://github.com/xiejinhe/xianyu-auto-reply/tree/main/common/models): `common/models`
- [共享业务能力](https://github.com/xiejinhe/xianyu-auto-reply/tree/main/common/services): `common/services`

### 返佣子系统

- [返佣管理界面](https://github.com/xiejinhe/xianyu-auto-reply/blob/main/promotion/frontend/src/App.tsx): `promotion/frontend/src/App.tsx`
- [返佣业务 API](https://github.com/xiejinhe/xianyu-auto-reply/blob/main/promotion/backend/main.py): `promotion/backend/main.py`
- [选品与发布规则](https://github.com/xiejinhe/xianyu-auto-reply/tree/main/promotion/backend/app/services): `promotion/backend/app/services`
- [返佣素材与规则数据](https://github.com/xiejinhe/xianyu-auto-reply/tree/main/common/models): `common/models`

### Other components

- **运营用户**
- **闲鱼平台**

## Connections

- 运营用户 → 管理界面: 操作 (evidence: `README.md`)
- 管理界面 → 业务接口: 请求接口 (evidence: `README.md`)
- 在线聊天界面 → 业务接口: 请求聊天 (evidence: `README.md`)
- 商品发布界面 → 业务接口: 提交发布 (evidence: `README.md`)
- 业务接口 → 账号管理: 管理账号 (evidence: `README.md`)
- 业务接口 → 商品发布与采集: 处理发布采集 (evidence: `README.md`)
- 业务接口 → 订单与发货: 处理订单 (evidence: `README.md`)
- 业务接口 → 通知与风控: 管理通知风控 (evidence: `README.md`)
- 业务接口 → 闲鱼实时连接: 调用实时服务 (evidence: `README.md`)
- 闲鱼实时连接 → 闲鱼平台: 收发消息 (evidence: `README.md`)
- AI 自动回复 → 闲鱼平台: 生成回复 (evidence: `README.md`)
- 任务调度器 → 定时业务任务: 调度任务 (evidence: `scheduler/app/services/scheduler_service.py`)
- 定时业务任务 → 订单与发货: 执行自动发货 (evidence: `README.md`)
- 定时业务任务 → 账号管理: 刷新 Cookie (evidence: `README.md`)
- 定时业务任务 → 闲鱼平台: 执行订单与评价操作 (evidence: `README.md`)
- 发货规则检查 → MySQL 数据: 读取规则 (evidence: `websocket/app/services/xianyu/delivery_rules/rule_engine.py`)
- 业务接口 → MySQL 数据: 读写业务数据 (evidence: `README.md`)
- 任务调度器 → MySQL 数据: 读取任务配置 (evidence: `README.md`)
- 业务接口 → Redis: 使用缓存 (evidence: `README.md`)
- MySQL 数据 → 共享数据模型: 持久化模型
- 共享业务能力 → 闲鱼平台: 提供平台能力 (evidence: `README.md`)
- 运营用户 → 返佣管理界面: 管理返佣商品 (evidence: `README.md`)
- 返佣管理界面 → 返佣业务 API: 请求接口 (evidence: `README.md`)
- 返佣业务 API → 选品与发布规则: 管理与执行规则 (evidence: `README.md`)
- 选品与发布规则 → 返佣素材与规则数据: 维护素材规则 (evidence: `README.md`)
- 选品与发布规则 → 闲鱼平台: 抓取并发布 (evidence: `README.md`)
- 选品与发布规则 → 共享业务能力: 复用发布能力 (evidence: `README.md`)
