aslan-server/claude/ai-context/ARCHITECTURE.md
2026-03-22 23:19:22 +08:00

3.4 KiB
Raw Blame History

架构说明

一、子服务内部分层DDD + CQRS

每个子服务(如 rc-service-other都遵循以下固定分层

{service}-adapter          # 适配层Controller对外 REST API
{service}-application      # 应用层ServiceImpl、CmdExe、QryExe、Manager、Scheduler
{service}-client           # 客户端接口层Service 接口、Cmd、CO、枚举
{service}-domain           # 领域层Entity、领域服务接口纯业务无框架依赖
{service}-infrastructure   # 基础设施层DAO、DatabaseService、Gateway、缓存、MQ
{service}-inner-endpoint   # 内部服务端点:供其他微服务 Feign 调用的实现
{service}-start            # 启动模块Spring Boot 入口、application.yml

二、层次调用链

HTTP 请求
   ↓
Controlleradapter
   ↓
ServiceImplapplication
   ↓
CmdExe / QryExeapplication
   ↓ 简单场景            ↓ 复杂场景
DatabaseService        Gateway封装锁+缓存+多数据源)
   ↓                      ↓
  DAO               DAO / Redis / MongoDB

强制规则

  • Controller 只调用 Service
  • Service 只调用 CmdExe/QryExe
  • CmdExe 可直接调用 DatabaseService简单或 Gateway复杂
  • 禁止跨层调用

三、跨服务调用Feign

调用方服务
  └── 注入 Feign 客户端(来自 rc-inner-api/{service}-inner/{service}-inner-api

rc-inner-api/
└── {service}-inner/
    ├── {service}-inner-api/      # Feign 接口定义endpoint 包)
    ├── {service}-inner-model/    # 传输数据模型model 包)
    └── (实现在 {service}-inner-endpoint 子服务中)

四、文件路径速查(以 other 服务为例)

文件类型 路径
Controller other-adapter/src/.../adapter/app/{模块}/
Service 接口 other-client/src/.../app/service/{模块}/
Cmd / QryCmd other-client/src/.../app/dto/cmd/{模块}/
CO返回对象 other-client/src/.../app/dto/clientobject/{模块}/
CmdExe other-application/src/.../app/command/{模块}/
QryExe other-application/src/.../app/command/{模块}/query/
ServiceImpl other-application/src/.../app/service/{模块}/
Manager other-application/src/.../app/manager/{模块}/
Gateway 接口+实现 other-infrastructure/src/.../infra/gateway/{模块}/
DAO other-infrastructure/src/.../infra/database/rds/dao/
Entity other-infrastructure/src/.../infra/database/rds/entity/
DatabaseService other-infrastructure/src/.../infra/database/rds/service/
MongoDB other-infrastructure/src/.../infra/database/mongo/
Cache other-infrastructure/src/.../infra/database/cache/
Inner API 接口 rc-inner-api/other-inner/other-inner-api/endpoint/{模块}/
Inner Model rc-inner-api/other-inner/other-inner-model/model/{模块}/
Inner 实现 other-inner-endpoint/src/.../app/inner/service/{模块}/

五、常见功能模块目录名

user / room / activity / game / family / gift / task / material / ranking / vip


六、Gateway 使用原则

需要 Gateway 的场景:分布式锁、缓存+DB 双写、多数据源聚合、复杂事务协调

不需要 Gateway 的场景:简单 CRUD、单表查询、无缓存的简单操作

原则:简单直接,复杂封装,不过度设计