ddd-cola について
Java と Spring Boot のプロジェクトを COLA V5 とドメイン駆動設計で構成するためのスキルです。各レイヤーの役割、依存方向、ポートやユースケースハンドラーの規約を示します。
主な機能
- 01COLA のレイヤー構成
- 02Adapter、Application、Domain、Infrastructure の役割
- 03依存性逆転の指針
- 04ポートと Gateway の規約
- 05コマンドと Executor の命名規則
活用シーン
- 01COLA による Java プロジェクトの構成
- 02ビジネスロジックと Adapter の分離
- 03ドメインのポートとインフラ実装の定義
- 04Spring 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 architecture, clean object-oriented layered architecture, COLA V5, adapter layer, application layer, domain layer, infrastructure layer, DDD, dependency inversion
コメント
Markdown 対応