Files
digital-psychology/.ai/architecture/go-services.md
T
jackyu66gitandCursor 19d3cd5945 refactor(ECR-001): 接入 ESS 并完成结构对齐 Phase A–E
绑定 ESS 双轨治理,拆分超大 H5 页与 Go 引擎,抽出 membership 服务,
并将 star/fortune 重命名为 outlook(JSON 双写兼容);同时修复 /psy API 代理与首页 + 菜单层级。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-05 17:51:40 +08:00

51 lines
2.4 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.
# Go 服务边界(冻结)
单二进制 `apps/api`;按包拆分,**禁止**跨层:Handler → Service → Repository。
详见 [../architecture.md](../architecture.md)。
---
## Packages under `internal/service/`
| Package | 职责 | P1 | 实现态(2026-08 |
|---|---|---|---|
| `user` | 注册/游客升级/Session | Yes | 多在 profile/auth 路径;无独立包名时勿重复造轮 |
| `profile` | 个人档案 CRUD、切换 | Yes | `service/profile` |
| `portrait` | 生成个人画像 → GrowthReport | Yes | 计算在 `internal/portrait`;用例经 report/handler 路径 |
| `scale` | 探索测试定义与计分 | Yes | `service/scale` + `internal/scale` |
| `relation` | RelationInsight | Yes **必做** | `service/relation` + `internal/relation` |
| `report` | GrowthReport 读取 + **权益裁剪** | Yes | `service/report` |
| `ask` | Thread/MessageP1 规则引擎 + 额度 | YesDemo | `service/ask` + `internal/ask` |
| `companion` | SolarTerm 读、Mood 写 | Shell | `service/companion` |
| `membership` | 成长会员状态与额度 | Yes | `service/membership`ECR-001 Phase C 已从 report 抽出) |
| `order` | Order + pay-mock + DeepAccess 发放 | Yes | 用例在 `service/membership`(同 Phase C;未单独拆包) |
| `imagecard` | 意象卡片 | P2 | `service/imagecard` |
### Engine vs Service
| Kind | Path | Can | Cannot |
|---|---|---|---|
| Engine | `internal/{portrait,relation,star,ask,scale,rhythm,…}` | 纯计算 / 组装报告结构 | 引用 `gin.Context`;做权益解锁 |
| Service | `internal/service/*` | 用例编排、鉴权后业务、调 repo/engine | SQL 直写;跳过归属校验 |
`internal/handler/`:每域一组 handler,只做 bind/validate/调用 service。
`internal/repository/`SQL;无 business unlock 规则(规则在 service/report + membership)。
星座周期展望引擎包:`internal/star/outlook`(原 `fortune`ECR-002)。对外 JSON 暂双写 `fortune`/`outlook` 键以兼容旧客户端。
---
## 跨域规则
- **权益判定**只在 `report` / `ask` / `membership` service,不在 handler、不在 H5。
- `portrait``relation``growth_reports`;读一律走 `report.Get`(带裁剪)。
- `ask` 强制校验 `profile` 归属当前 user。
---
## 禁止
- 新建 `decode` / `match` / `unlock` / `fortune` 包名
- Handler 直连 DB
- 在 JSON 字段名使用 `luck` / `fortune` / `ji_xiong`