|
| 1 | +- client: 独立(只需要依赖组件) |
| 2 | +- domain: 独立 |
| 3 | +- infrastructure: 实现 domain(可以使用 client) |
| 4 | +- app: 实现 client | 依赖 infrastructure->domain |
| 5 | +- adapter: 使用 app -> app |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | +## COLA 架构: 框架(提升应用质量) |
| 12 | + |
| 13 | +| 层次 | 包名 | 功能 | extra | 必选 | |
| 14 | +| :----------------- | :---------- | :---------------------------------- | :--------------------- | :--- | |
| 15 | +| Adapter 层(VO/DTO) | openapi | 封装 http, rpc 接口 | | 否 | |
| 16 | +| | controller | 处理 http 请求 | 浏览器 | 否 | |
| 17 | +| | scheduler | 处理定时任务 | 定时任务 | 否 | |
| 18 | +| | consumer | 处理外部 message | 消息 | 否 | |
| 19 | +| App 层(DTO) | executor | 处理 request, 包括 command 和 query | | 是 | |
| 20 | +| | service | 与 domain 交互负责编排任务 | | 是 | |
| 21 | +| Domain 层(Entity) | gateway | 领域网关, 解耦利器 | 粗略的理解成一种 SPI | 是 | |
| 22 | +| | model | 领域模型 | | 否 | |
| 23 | +| | ability | 领域能力, DomainManager | 领域对外暴露的服务能力 | 否 | |
| 24 | +| Infra 层(DO) | gatewayimpl | 网关实现 | | 是 | |
| 25 | +| | mapper | ibatis 数据库映射 | | 否 | |
| 26 | +| | config | 配置信息 | | 否 | |
| 27 | +| Driven adapter | db | 数据库 | | 否 | |
| 28 | +| | search | 搜索引擎 | | 否 | |
| 29 | +| | rpc | 外部接口 | | 否 | |
| 30 | +| Client SDK | api | 服务对外透出的 API | | 是 | |
| 31 | +| | dto | 服务对外的 DTO | | 是 | |
| 32 | + |
| 33 | +## COLA 组件: 框架功能(可复用组件 + 提升研发效率) |
| 34 | + |
| 35 | +| 组件名称 | 功能 | 依赖 | |
| 36 | +| :------------------------------- | :-------------------------------------------------- | :------------------ | |
| 37 | +| cola-component-catchlog-starter | 异常处理和日志组件 | exception、dto 组件 | |
| 38 | +| cola-component-domain-starter | Spring 托管的领域实体组件 | 无 | |
| 39 | +| cola-component-dto | 定义了 DTO 格式, 包括分页 | 无 | |
| 40 | +| cola-component-exception | 定义了异常格式, 主要有 BizException 和 SysException | |
| 41 | +| cola-component-extension-starter | 扩展点组件 | 无 | |
| 42 | +| cola-component-statemachine | 状态机组件 | 无 | |
| 43 | +| cola-component-test-container | 测试容器组件 | 无 | |
| 44 | + |
| 45 | +## 相关细节 |
| 46 | + |
| 47 | +1. 包的划分: 综合考虑功能和领域两个维度包结构定义 |
| 48 | +  |
| 49 | + |
| 50 | +  |
| 51 | + |
| 52 | +2. 防腐层: Anti-Corruption |
| 53 | + |
| 54 | + - ddd 的概念: 应用不要直接依赖外域的信息,要把外域的信息转换成自己领域上下文(Context)的实体再去使用,从而实现本域和外部依赖的解耦 |
| 55 | + - 在 COLA 中将数据库等都泛化为外部依赖, 利用依赖倒置(变成了不直接依赖数据库等-依赖数据库的抽象), 统一使用 gateway 来实现业务领域和外部依赖的解耦: Domain 层定义 Gateway + Infrastructure 提供实现 |
| 56 | + |
| 57 | +  |
| 58 | +  |
| 59 | + |
| 60 | + - pros: 降低了对外域信息依赖的耦合 |
| 61 | + - pros: 是通过上下文映射, 确保本领域边界上下文下领域知识的完整性,实现了统一语言 |
| 62 | + |
| 63 | +## client - app - adaptor |
| 64 | + |
| 65 | +1. client 定义接口(类似与 openapi 定义|类似于 app 实现的接口) |
| 66 | + ```java |
| 67 | + interface CustomerServiceI { |
| 68 | + listByName(); |
| 69 | + } |
| 70 | + ``` |
| 71 | +2. app 实现接口 |
| 72 | + ```java |
| 73 | + @Service |
| 74 | + public class CustomerServiceImpl implements CustomerServiceI { |
| 75 | + @Resource private CustomerListByNameQryExe customerListByNameQryExe; |
| 76 | + @Override |
| 77 | + public MultiResponse<CustomerDTO> listByName(CustomerListByNameQry customerListByNameQry) { |
| 78 | + return customerListByNameQryExe.execute(customerListByNameQry); |
| 79 | + } |
| 80 | + } |
| 81 | + ``` |
| 82 | +3. adaptor 调用 client 接口提供 controller/openapi 等服务 |
| 83 | + ```java |
| 84 | + @RestController |
| 85 | + public class CustomerController { |
| 86 | + @Autowired private CustomerServiceI customerService; |
| 87 | + @GetMapping(value = "/customer") |
| 88 | + public MultiResponse<CustomerDTO> listCustomerByName(@RequestParam(required = false) String name){ |
| 89 | + CustomerListByNameQry customerListByNameQry = new CustomerListByNameQry(); |
| 90 | + customerListByNameQry.setName(name); |
| 91 | + return customerService.listByName(customerListByNameQry); |
| 92 | + } |
| 93 | + } |
| 94 | + ``` |
0 commit comments