feat: expand AI workflow support and refresh docs

This commit is contained in:
2026-03-12 13:47:42 +08:00
parent 8688422578
commit 4ecab597f4
28 changed files with 4806 additions and 1907 deletions

View File

@@ -1,109 +1,103 @@
# 📁 Server 目录说明
# ServerFastAPI 后端)
## 目录结构
当前目录是 DesignerCEP 的主后端服务。
```
## 1. 当前目录结构(关键)
```text
Server/
├── app/ ← 后端代码(FastAPI
│ ├── api/ ← API 路由
│ ├── core/ ← 核心配置
│ ├── models/ ← 数据库模型
│ ├── schemas/ ← 数据验证
│ ├── services/ 业务逻辑
│ ├── main.py ← 后端入口
│ └── db.py ← 数据库连接
├── static/ ← ⭐ 前端静态文件(重要!)
│ └── app/ ← 前端构建产物放这里
│ ├── index.html ← 前端入口
│ ├── assets/ ← JS/CSS/图片
│ └── ...
── archives/ ← Core 版本压缩包(历史版本
│ ├── core-v1.0.0.zip
│ ├── core-v1.0.1.zip
│ └── ...
├── tests/ ← 测试代码
├── routers/ ← 额外的路由(如果有)
├── docker-compose.yml ← Docker 编排配置
├── Dockerfile ← 后端镜像构建
├── requirements.txt ← Python 依赖
├── mysql.cnf ← MySQL 配置
├── .dockerignore ← Docker 忽略文件
└── designercep.db ← SQLite 数据库(本地开发用)
├── app/ # FastAPI 代码
│ ├── api/v1/ # 接口路由
│ ├── core/ # 配置与安全
│ ├── models/ # ORM 模型
│ ├── schemas/ # Pydantic Schema
│ ├── services/ # 业务服务
│ ├── db.py # SQLAlchemy 初始化与 seed
│ └── main.py # 应用入口
├── archives/ # 上传版本包归档目录
├── debug_images/ # 调试图片输出
├── docker-compose.yml # Docker 编排backend + mysql + pma + portainer
├── Dockerfile # 后端镜像
├── requirements.txt # Python 依赖
├── start.sh # 容器启动脚本
├── .env.example # 配置模板(推荐复制后本地填写)
── .env # 运行配置(敏感
```
---
## ⭐ 前端文件应该放在这里
### 构建前端后,复制到这里:
```
Server/static/app/
├── index.html ← 前端入口(重要!)
├── assets/ ← JS/CSS 等资源
│ ├── index-xxx.js
│ ├── index-xxx.css
│ └── ...
├── CSInterface.js ← CEP 桥接文件
└── vite.svg ← 图标等
```
### 操作步骤:
```bash
# 1. 构建前端(在 Designer 目录)
cd Designer
npm run build:core
# 2. 复制到 Server/static/app/
# Windows:
xcopy /E /Y dist_core\* ..\Server\static\app\
# Linux/Mac:
cp -r dist_core/* ../Server/static/app/
```
---
## 🐳 Docker 部署
### 启动服务
## 2. 本地运行
```bash
cd Server
docker-compose up -d
copy .env.example .env
pip install -r requirements.txt
uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
```
### 查看日志
检查服务:
```bash
docker-compose logs -f
curl http://localhost:8000/health
```
### 停止服务
## 3. Docker 运行
```bash
cd Server
docker-compose up -d --build
docker-compose ps
docker-compose logs -f backend
```
停止服务:
```bash
docker-compose down
```
---
## 4. 配置说明(来自 `app/core/config.py`
## 📋 部署清单
主要环境变量(优先使用 `AI_*`
- [ ] 前端文件已复制到 `static/app/`
- [ ] `.env` 文件已配置
- [ ] MySQL 密码已修改
- [ ] SECRET_KEY 已修改
- [ ] ALLOWED_ORIGINS 已配置
- [ ] Docker 服务已启动
- [ ] 访问 https://app.aidg168.uk/ 测试
- `ENV`development / production
- `DATABASE_URL`
- `SECRET_KEY`
- `ADMIN_TOKEN`
- `ALLOWED_ORIGINS`
- `SMTP_*`
- `QINIU_*`
- `AI_API_KEY``AI_BASE_URL``AI_MODEL`
- `AI_VISION_MODEL``AI_IMAGE_EDIT_MODEL`
- `QINIU_DOMAIN`
---
## 5. 数据库迁移
**重要**:前端文件必须放在 `Server/static/app/` 目录!
推荐使用 Alembic
```bash
cd Server
.venv\Scripts\python -m alembic upgrade head
```
新增字段后生成迁移:
```bash
.venv\Scripts\python -m alembic revision --autogenerate -m "describe_change"
```
## 6. 接口前缀与入口
- API 前缀:`/api/v1`
- 健康检查:`GET /health`
- 启动入口:`app/main.py`
## 7. 关于静态文件
当前仓库中没有 `Server/static/app/` 目录。
在线部署场景下,前端静态资源由 Caddy/Nginx 单独托管(仓库根目录 `Caddyfile` 示例为 `/var/www/app`)。
## 8. 安全注意事项
- `Server/.env` 含真实密钥,不应继续明文共享。
- 启动时如果检测到默认密钥,后端会输出配置警告。
- 部署前请至少轮换:`SECRET_KEY``ADMIN_TOKEN`、数据库密码、AI 与云存储密钥。