TravelContentCreator/docs/MIGRATION_PLAN.md

192 lines
6.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 迁移与清理工作计划
> 本文档记录待迁移、待清理的旧文件和模块
---
## 1. Prompt 迁移状态
### 已迁移到 `prompts/` (YAML 格式)
| 旧路径 | 新路径 | 状态 |
|-------|-------|------|
| `resource/prompt/generateTopics/` | `prompts/topic_generate/v1.0.0.yaml` | ✅ 已迁移 |
| `resource/prompt/generateContent/system.txt` | `prompts/content_generate/v1.0.0.yaml` | ✅ 已迁移 |
| `resource/prompt/judgeContent/` | `prompts/content_judge/v1.0.0.yaml` | ✅ 已迁移 |
| `resource/prompt/integration/` | `prompts/integration/v1.0.0.yaml` | ✅ 已迁移 |
| `resource/prompt/Style/` | `prompts/style/*.yaml` | ✅ 已迁移 |
| `resource/prompt/Demand/` | `prompts/audience/*.yaml` | ✅ 已迁移 |
### 待迁移 → 已完成 ✅
| 旧路径 | 新路径 | 状态 |
|-------|-------|------|
| `resource/prompt/generateContent/posterContentSystem.txt` | `prompts/poster_content/v1.0.0.yaml` | ✅ 已迁移 |
| `resource/prompt/Refer/*` | `prompts/reference/` | ✅ 已复制 |
### 待删除 (迁移完成后)
```
resource/prompt/generateTopics/ # 已迁移
resource/prompt/generateContent/ # 部分已迁移
resource/prompt/judgeContent/ # 已迁移
resource/prompt/integration/ # 已迁移
resource/prompt/Style/ # 已迁移
resource/prompt/Demand/ # 已迁移
```
---
## 2. 旧模块使用情况
### 仍在使用旧 prompt 路径的文件
| 文件 | 引用次数 | 说明 |
|-----|---------|------|
| `core/config/models.py` | 10 | 配置模型定义 |
| `api/services/content_integration_service.py` | 2 | 内容整合服务 |
| `domain/aigc/shared/component_factory.py` | 1 | 组件工厂 |
| `domain/aigc/shared/prompt_builder.py` | 1 | Prompt 构建器 |
**建议**:这些文件需要更新为使用 PromptRegistry
---
## 3. 可废弃的旧功能
### 数据库相关 (V2 引擎不使用)
| 文件 | 行数 | 说明 |
|-----|-----|------|
| `api/services/database_service.py` | 1054 | 数据库服务 |
| `infrastructure/database/connection.py` | - | 数据库连接 |
**状态**V2 引擎不访问数据库,但旧代码可能依赖,暂时保留
### 旧配置文件 (已删除)
- ~~`config/content_gen.json`~~ ✅ 已删除
- ~~`config/topic_gen.json`~~ ✅ 已删除
- ~~`config/mysql/`~~ ✅ 已删除
---
## 4. 巨型文件拆分计划
### 需要拆分的文件
| 文件 | 行数 | 优先级 | 拆分建议 |
|-----|-----|-------|---------|
| `demo_refactored_templates.py` | 4219 | 🔴 高 | 删除 (demo 文件) |
| `poster_template.py` | 3421 | 🔴 高 | 删除 (已迁移到 poster/) |
| `api/services/poster.py` | 3031 | 🔴 高 | 拆分为多个模块 |
| `poster/templates/vibrant_template.py` | 1756 | 🟡 中 | 模板类拆分 |
| `api/services/database_service.py` | 1054 | 🟡 中 | 可能废弃 |
| `core/xhs_spider/apis/xhs_pc_apis.py` | 1019 | 🟡 中 | 按功能拆分 |
### `api/services/poster.py` 拆分方案
```
api/services/poster/
├── __init__.py # 导出
├── service.py # 主服务类 (~300行)
├── template_manager.py # 模板管理 (~400行)
├── image_processor.py # 图片处理 (~500行)
├── text_renderer.py # 文字渲染 (~400行)
├── fabric_exporter.py # Fabric.js 导出 (~400行)
└── psd_generator.py # PSD 生成 (~500行)
```
---
## 5. 根目录清理
### 可删除的文件
| 文件 | 说明 |
|-----|------|
| `demo_refactored_templates.py` | Demo 文件160KB |
| `poster_template.py` | 旧模板153KB |
| `test_response.json` | 测试响应766KB |
| `test_size_adjustment_result.png` | 测试图片 |
| `test_stroke_final_png.png` | 测试图片 |
| `test_stroke_final_result.json` | 测试结果 |
| `response_with_psd.json` | 测试响应 |
| `database_test.log` | 测试日志 |
| `database_service_改进报告.md` | 临时文档 |
| `文件下载S3协议修复报告.md` | 临时文档 |
| `认证接口统一修复报告.md` | 临时文档 |
| `udo systemctl start travel-api-test` | 错误文件名 |
### 可移动到 docs/ 的文件
| 文件 | 目标 |
|-----|------|
| `海报Fabric.js前端对接文档.md` | `docs/FABRIC_INTEGRATION.md` |
| `psd_usage_guide.md` | `docs/PSD_USAGE.md` |
| `PSD_API_Usage.md` | `docs/PSD_API.md` |
---
## 6. 工作计划
### Phase 1: 清理根目录 (低风险) ✅ 已完成
- [x] 删除 demo/测试文件
- [x] 移动文档到 docs/
- [x] 删除临时报告文件
### Phase 2: 迁移剩余 Prompt ✅ 已完成
- [x] 迁移 `posterContentSystem.txt` 到 YAML
- [x] 将 Refer 目录复制到 `prompts/reference/`
- [x] 实现 PromptRegistry
- [x] 实现 V2 引擎 (topic_generate, content_generate, poster_generate)
- [x] 实现 /api/v2/aigc/execute 接口
- [x] 删除旧的数据库访问代码
- [x] 实现 /api/v2/aigc/config/styles 接口
- [x] 实现 /api/v2/aigc/config/audiences 接口
- [x] 实现 /api/v2/aigc/config/all 接口
- [x] 完善 Prompt YAML 的 meta 信息 (icon, description, order)
- [x] 添加接口文档 (docs/ARCHITECTURE_ANALYSIS.md)
### Phase 3: 更新旧模块引用 ✅ 已完成
- [x] 更新 `core/config/models.py` 使用 PromptRegistry
- [x] 更新 `api/services/content_integration_service.py`
- [x] 删除 `domain/aigc/shared/prompt_builder.py`
- [x] 删除 `utils/prompts.py`
- [x] 删除 `tweet/` 目录
- [x] 删除 `api/services/prompt_service.py`
- [x] 删除 `api/services/prompt_builder.py`
- [x] 重写 `api/routers/prompt.py` 使用 PromptRegistry
### Phase 4: 拆分巨型文件 (待定)
- [ ] 拆分 `api/services/poster.py` (3031行)
- [ ] 拆分 `poster/templates/vibrant_template.py` (1756行)
### Phase 5: 清理旧 Prompt 目录 ✅ 已完成
- [x] 删除 `resource/prompt/`
---
## 7. 风险评估
| 操作 | 风险 | 说明 |
|-----|------|------|
| 删除 demo 文件 | 🟢 低 | 不影响生产 |
| 删除旧 prompt | 🟡 中 | 需确认无引用 |
| 拆分 poster.py | 🟡 中 | 需要测试 |
| 删除 database_service | 🔴 高 | 旧代码可能依赖 |
---
## 8. 执行顺序建议
1. **立即执行** - 删除根目录测试文件
2. **本周** - 迁移剩余 Prompt更新引用
3. **下周** - 拆分 poster.py
4. **联调后** - 删除旧 prompt 目录和 database_service