关于 ddd-cola
帮助 Java 和 Spring Boot 项目采用 COLA V5 与领域驱动设计组织结构,说明各层职责、依赖方向,以及端口和用例处理器的约定。
主要功能
- 01COLA 分层项目结构
- 02Adapter、Application、Domain、Infrastructure 职责
- 03依赖反转指导
- 04端口与 Gateway 约定
- 05命令和 Executor 命名规范
适用场景
- 01使用 COLA 组织 Java 项目
- 02将业务逻辑与 Adapter 分离
- 03定义领域端口及基础设施实现
- 04组织 Spring Boot 用例处理器
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ partme-ai/ full-stack-skills --skill ddd-cola安装后在 Claude Code 中输入/ddd-cola确认已加载。
附带文件LICENSE.txt
详细介绍
适用场景
当用户希望进行以下操作时,使用此技能:
- 使用 COLA 架构(Adapter、Application、Domain、Infrastructure)构建项目
- 应用 COLA 分层架构,明确各层职责
- 使用 COLA 实现领域驱动设计,同时保持领域层纯粹并遵循依赖倒置原则
- 按照 COLA V5 约定组织 Java/Spring Boot 项目
如何使用此技能
工作流
- 了解各层职责:Adapter 处理输入/输出;Application 编排用例;Domain 承载业务逻辑;Infrastructure 实现持久化和外部服务
- 设置包结构,遵循 COLA 约定
- 确保依赖方向正确:Domain 不依赖任何层;Application 依赖 Domain;Adapter 和 Infrastructure 依赖 Application 与 Domain
- 在 Domain 或 Application 中定义端口,并在 Infrastructure 中实现
分层结构
com.example.app/
├── adapter/
│ ├── controller/ # HTTP/RPC/message inbound handlers
│ └── scheduler/ # Scheduled tasks
├── app/
│ ├── executor/ # Use case executors (command handlers)
│ └── service/ # Application services (orchestration, transactions)
├── domain/
│ ├── model/ # Entities, Value Objects, Aggregates
│ │ ├── entity/
│ │ └── valueobject/
│ ├── service/ # Domain services
│ └── gateway/ # Repository and external service interfaces (ports)
└── infrastructure/
├── persistence/ # Repository implementations (JPA, MyBatis)
├── external/ # External API clients
└── config/ # Spring configuration and bean wiring
依赖方向
Adapter → Application → Domain ← Infrastructure
示例:用例执行器
// Domain gateway (port)
public interface OrderGateway {
void save(Order order);
Optional<Order> findById(String id);
}
// Application executor
@Component
public class CreateOrderExecutor {
private final OrderGateway orderGateway;
public CreateOrderExecutor(OrderGateway orderGateway) {
this.orderGateway = orderGateway;
}
@Transactional
public OrderDto execute(CreateOrderCmd cmd) {
Order order = Order.create(cmd.getItems(), cmd.getCustomerId());
orderGateway.save(order);
return OrderDto.from(order);
}
}
// Infrastructure implementation
@Repository
public class OrderGatewayImpl implements OrderGateway {
private final OrderMapper orderMapper;
@Override
public void save(Order order) {
orderMapper.insert(OrderDO.fromDomain(order));
}
}
最佳实践
- 领域逻辑只能放在 Domain 层;Application 层只负责编排和管理事务边界
- 在 Domain 或 Application 中定义端口(接口),并在 Infrastructure 中实现
- 避免在 Adapter 层编写业务逻辑;在边界处转换 DTO 和领域对象
- 遵循 COLA 命名约定:命令使用
Cmd,处理程序使用Executor,端口使用Gateway
资源
- COLA GitHub:https://github.com/alibaba/COLA
- COLA 架构指南:https://blog.csdn.net/significantfrank/article/details/110934799
关键词
cola、cola 架构、面向对象的整洁分层架构、COLA V5、适配器层、应用层、领域层、基础设施层、DDD、依赖倒置
评论
支持 Markdown