feat:重构UI
This commit is contained in:
84
CLAUDE.md
Normal file
84
CLAUDE.md
Normal file
@@ -0,0 +1,84 @@
|
||||
# CLAUDE.md
|
||||
|
||||
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
||||
|
||||
## 项目概述
|
||||
|
||||
AI 翻译网站 - Monorepo 架构,前端 Next.js + 后端 FastAPI,支持流式输出(SSE)、Redis 缓存/限流、PostgreSQL 数据存储。
|
||||
|
||||
## 常用命令
|
||||
|
||||
### 后端开发 (apps/api)
|
||||
|
||||
```bash
|
||||
cd apps/api
|
||||
pip install -e . # 安装依赖
|
||||
pip install -e ".[dev]" # 安装开发依赖
|
||||
uvicorn app.main:app --reload # 启动开发服务器 (localhost:8000)
|
||||
python scripts/init_db.py [用户名] [密码] # 初始化数据库管理员账户
|
||||
|
||||
# 测试与代码检查
|
||||
pytest # 运行测试
|
||||
ruff check . # 代码检查
|
||||
ruff format . # 代码格式化
|
||||
```
|
||||
|
||||
### 前端开发 (apps/web)
|
||||
|
||||
```bash
|
||||
cd apps/web
|
||||
npm install # 安装依赖
|
||||
npm run dev # 启动开发服务器 (localhost:3000)
|
||||
npm run build # 构建生产版本
|
||||
npm run lint # ESLint 检查
|
||||
```
|
||||
|
||||
### Docker 部署 (infra)
|
||||
|
||||
```bash
|
||||
cd infra
|
||||
cp .env.example .env # 配置环境变量
|
||||
docker-compose up -d # 启动所有服务
|
||||
```
|
||||
|
||||
## 架构概览
|
||||
|
||||
```
|
||||
apps/
|
||||
web/ # Next.js 14 前端 (TypeScript + Tailwind CSS)
|
||||
api/ # FastAPI 后端 (Python 3.11+, async)
|
||||
infra/ # Docker Compose 配置
|
||||
```
|
||||
|
||||
### 后端结构 (apps/api/app)
|
||||
|
||||
- `main.py` - FastAPI 应用入口,配置中间件和路由
|
||||
- `core/` - 配置(config.py)、日志(logging.py)、数据库(database.py)
|
||||
- `api/` - 路由层:translate.py(翻译)、admin.py(管理)、ai_provider.py、stats.py
|
||||
- `services/` - 业务逻辑:llm.py(LLM调用)、cache.py(Redis缓存)、rate_limit.py(限流)、auth.py、stats.py
|
||||
- `schemas/` - Pydantic 请求/响应模型
|
||||
- `models/` - SQLAlchemy ORM 模型
|
||||
|
||||
### 核心 API 端点
|
||||
|
||||
- `POST /api/v1/translate` - 非流式翻译
|
||||
- `POST /api/v1/translate/stream` - SSE 流式翻译
|
||||
- `GET /health` - 健康检查
|
||||
|
||||
### 数据流
|
||||
|
||||
1. 请求 → 限流检查(Redis) → 缓存查询(Redis)
|
||||
2. 缓存命中 → 直接返回
|
||||
3. 缓存未命中 → LLM 调用 → 写入缓存 → 返回
|
||||
|
||||
## 环境变量
|
||||
|
||||
后端 `.env` 关键配置:
|
||||
- `LLM_API_KEY` - LLM 服务 API Key(必需)
|
||||
- `LLM_MODEL` - 模型名称(默认 gpt-4o-mini)
|
||||
- `LLM_BASE_URL` - 自定义 API 地址(可选)
|
||||
- `DATABASE_URL` - MySQL 连接串
|
||||
- `REDIS_URL` - Redis 连接串
|
||||
|
||||
前端 `.env.local`:
|
||||
- `NEXT_PUBLIC_API_BASE_URL` - 后端 API 地址
|
||||
Reference in New Issue
Block a user