docs: 添加 CLAUDE.md 项目指南文件
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
477b952223
commit
dad4087bca
1 file changed
+107
@@ -0,0 +1,107 @@
|
||||
# CLAUDE.md
|
||||
|
||||
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
||||
|
||||
## 项目概述
|
||||
|
||||
News Aggregator - 基于配置的资讯聚合系统,自动收集、整理、推送每日报告。支持多数据源采集、AI 内容处理、多渠道推送和 AI Agent 对话。
|
||||
|
||||
## 常用命令
|
||||
|
||||
### 后端 (backend/)
|
||||
|
||||
```bash
|
||||
npm run dev # 启动开发服务器 (tsx watch)
|
||||
npm run build # 构建生产版本
|
||||
npm run test # 运行测试
|
||||
npm run test:watch # 监听模式测试
|
||||
npm run prisma:generate # 生成 Prisma Client
|
||||
npm run prisma:migrate # 执行数据库迁移
|
||||
npm run prisma:studio # 打开 Prisma Studio
|
||||
```
|
||||
|
||||
### 前端 (frontend/)
|
||||
|
||||
```bash
|
||||
npm run dev # 启动开发服务器 (Vite)
|
||||
npm run build # 构建生产版本 (vue-tsc + vite build)
|
||||
```
|
||||
|
||||
## 架构概览
|
||||
|
||||
### 后端分层架构
|
||||
|
||||
```
|
||||
backend/src/
|
||||
├── web/routes/ # API 路由层 - Fastify 路由定义
|
||||
├── services/ # 业务服务层 - 核心业务逻辑
|
||||
├── collectors/ # 采集器 - 数据源采集实现
|
||||
├── distributors/ # 分发器 - 推送渠道实现
|
||||
├── config/ # 配置 - 环境变量和数据库连接
|
||||
├── types/ # 类型定义
|
||||
└── utils/ # 工具函数
|
||||
```
|
||||
|
||||
### 核心抽象模式
|
||||
|
||||
**采集器 (Collector)**:继承 `BaseCollector`,实现 `collect()`、`validateConfig()`、`getType()` 方法
|
||||
- `ApiCollector` - REST API 采集
|
||||
- `PlaywrightCollector` - 网页爬取
|
||||
- `RssCollector` - RSS/Atom 订阅
|
||||
|
||||
**分发器 (Distributor)**:继承 `BaseDistributor`,实现 `distribute()`、`validateConfig()`、`getType()` 方法
|
||||
- `EmailDistributor` - 邮件推送
|
||||
- `DingtalkDistributor` - 钉钉机器人
|
||||
- `WechatDistributor` - 企业微信
|
||||
- `SlackDistributor` - Slack
|
||||
|
||||
**服务层**:继承 `BaseService<T, CreateInput, UpdateInput>`,提供 CRUD 和分页查询
|
||||
|
||||
### AI Agent 架构
|
||||
|
||||
```
|
||||
services/agent/
|
||||
├── agent.service.ts # 核心服务 - 流式对话入口
|
||||
├── context/
|
||||
│ ├── context-loader.ts # 上下文加载 - 报告/资讯/主题
|
||||
│ └── prompt-builder.ts # 系统提示词构建
|
||||
├── conversation/
|
||||
│ └── conversation.manager.ts # 对话管理 - 消息存储
|
||||
└── tools/ # 工具系统 (Vercel AI SDK)
|
||||
```
|
||||
|
||||
使用 Vercel AI SDK (`ai` 包) 的 `streamText` 实现流式对话。
|
||||
|
||||
### 前端架构
|
||||
|
||||
```
|
||||
frontend/src/
|
||||
├── views/ # 页面组件
|
||||
├── components/ # 公共组件
|
||||
├── stores/ # Pinia 状态管理
|
||||
├── api/ # API 请求封装
|
||||
└── router/ # Vue Router 路由
|
||||
```
|
||||
|
||||
### 数据模型关系
|
||||
|
||||
- `Topic` (主题) 关联多个 `Source` (数据源) 和 `Channel` (推送渠道)
|
||||
- `Source` 产生 `Article` (资讯),记录 `CollectionLog` (采集日志)
|
||||
- `Topic` 生成 `Report` (报告),通过 `Channel` 推送并记录 `PushLog`
|
||||
- `Conversation` (对话) 关联 `Topic`,可选关联 `Report` 或 `Article`
|
||||
|
||||
## 环境配置
|
||||
|
||||
复制 `backend/.env.example` 到 `backend/.env`,配置:
|
||||
- `DATABASE_URL` - MySQL 连接字符串
|
||||
- `PORT` - 服务端口 (默认 3000)
|
||||
|
||||
## 提交规范
|
||||
|
||||
```
|
||||
<type>: <subject>
|
||||
|
||||
Co-Authored-By: Claude <model>
|
||||
```
|
||||
|
||||
类型:feat / fix / docs / style / refactor / test / chore
|
||||
Reference in new issue
Block a user