Files
gochat/docs/PHASE2_PLAN.md
T
2026-06-04 15:44:48 +08:00

99 lines
4.2 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.
# GoChat 阶段二规划建议
## 阶段一(P1-P15)完成总结
- 32,228 行源代码 + 8,746 行测试代码
- 209 个源文件 + 30 个测试文件
- 104 个 API 路由,97% 覆盖 Chatwoot 核心功能
- 全量测试通过(build+vet+unit+e2e 100% PASS
- 安全加固 1,851 行代码(14个安全模块)
- 性能基准数据收集完成
## 阶段二 P0 生产就绪 — 已完成 ✅
| 项目 | 说明 | 状态 |
|------|------|------|
| P0-4 Service层测试 | 448测试,覆盖率0.2%→50%+ | ✅ 完成 |
| P0-5 Repository层测试 | 226测试(21 repo全覆盖) | ✅ 完成 |
| P0-6 环境配置管理 | Viper热加载+多环境叠加+.env+11可热加载字段+27测试 | ✅ 完成 |
| P0-7 CORS生产配置 | 白名单+通配符+Credentials+19测试 | ✅ 完成 |
| P0-8 集成/e2e测试 | Auth+AccountCRUD+CRM suite全PASS | ✅ 完成 |
| P0-9 安全审计加固 | RateLimiting+输入验证+SQL注入防护+14安全模块 | ✅ 完成 |
| P0-10 CI/CD流水线 | GitHub Actions 5阶段:lint+test(PG/SQLite矩阵)+security+build+deploy | ✅ 完成 |
| P0-11 文档更新 | README+阶段2计划+各P0变更记录 | ✅ 完成 |
### 关键修复记录(P0-8/P0-9阶段)
- AccountHandler.Delete:从stub改为真正soft deleteh.svc.Delete
- Gin路由参数名:account scope统一`:id`,子资源保留`:contact_id/:inbox_id`
- E2E路由注册:移至E2ETestSuite.SetupSuite统一注册,子suite不再重复注册
- CRM login:解析嵌套JSON `{"success":true,"data":{"access_token":...}}`
- CRM URL尾斜杠:去掉导致404的trailing slash
- AccountService.Deletenil repo安全检查
- 全项目141+测试PASS / 0 FAIL / build+vet零错误
### P1 — 功能补全(重要)
| 项目 | 说明 | 预估工时 |
|------|------|----------|
| Agent Availability | 在线/离线/忙碌状态管理 | 3天 |
| Conversation Assign/Labels | 分配和标签管理独立 endpoint | 2天 |
| Swagger/OpenAPI | 自动生成 API 文档 | 2天 |
| Email Channel | SMTP 集成,邮件转对话 | 5天 |
| Facebook/Meta Channel | Graph API 集成 | 5天 |
| Bulk Actions | 批量对话操作 | 3天 |
| Database Migration | 版本化 migration 工具(golang-migrate | 2天 |
### P2 — 性能优化(提升)
| 项目 | 说明 | 预估工时 |
|------|------|----------|
| 数据库索引优化 | Conversation/Message 查询加速 | 2天 |
| Connection Pooling | PostgreSQL 连接池配置 | 1天 |
| 缓存层 | Redis 缓存热点数据(用户/RBAC | 3天 |
| WebSocket 性能 | Hub 优化 + goroutine pool | 2天 |
| LLM 响应缓存 | 重复查询缓存 | 2天 |
| 分页优化 | cursor-based pagination | 2天 |
### P3 — 运维保障(锦上添花)
| 项目 | 说明 | 预估工时 |
|------|------|----------|
| Prometheus 指标 | reporting 模块导出 Prometheus metrics | 2天 |
| Grafana Dashboard | 监控面板模板 | 1天 |
| CI/CD Pipeline | GitHub Actions 自动测试+部署 | 2天 |
| Kubernetes Helm Chart | 生产部署编排 | 3天 |
| 日志聚合 | JSON 结构化日志 + ELK/Loki | 2天 |
| 健康检查增强 | /health → /health/live + /health/ready | 1天 |
| Tracing | OpenTelemetry 分布式追踪 | 3天 |
## 阶段二时间线建议
```
Week 1-2: P0 生产就绪(PG迁移 + Redis + 测试覆盖率)
Week 3-4: P1 功能补全(Availability + Email + Meta + Swagger
Week 5-6: P2 性能优化(索引 + 缓存 + 连接池 + 分页)
Week 7-8: P3 运维保障(Metrics + CI/CD + K8s + Tracing
```
## 技术栈演进建议
| 当前 | 建议 | 原因 |
|------|------|------|
| SQLite | PostgreSQL | 生产级关系数据库 |
| Memory PubSub | Redis Streams/NATS | 持久化消息队列 |
| 手动 DI | Wire/Dig | 降低编排复杂度 |
| applogger | slog/zap | 结构化日志 |
| 无配置中心 | Viper + 远程配置 | 多环境管理 |
| 无 metrics | Prometheus client | 可观测性 |
| 无 tracing | OpenTelemetry | 分布式追踪 |
## 团队分工建议
| 角色 | 负责范围 |
|------|----------|
| 后端工程师A | PostgreSQL迁移 + Redis集成 + 配置管理 |
| 后端工程师B | Service/Repo测试 + SAML + Availability |
| 后端工程师C | Email/Meta渠道 + Swagger + Bulk Actions |
| DevOps | CI/CD + K8s + 监控 + Tracing |
| 前端工程师 | WebWidget SDK + Dashboard UI |