Summary
リポジトリインターフェースの配置場所に関するガイド。クリーンアーキテクチャにおいて リポジトリインターフェースをドメイン層ではなくユースケース層に配置すべき理由を解説。 ドメインモデルとリポジトリの結合防止、構造による設計意図の強制を主眼とする。…
j5ik2o/okite-ai
>- リポジトリインターフェースの? リポジトリインターフェースをドメイン層ではなくユースケース層に? ドメインモデルとリポジトリの結合防止、構造による設計意図の強制を主眼とする。 トリガー:「リポジトリをどこに置く」「リポジトリインターフェースの? 「クリーンアーキテクチャでリポジトリ」等のリポジトリ?
npx skills add j5ik2o/okite-ai --skill repository-placement
リポジトリインターフェースの配置場所に関するガイド。クリーンアーキテクチャにおいて リポジトリインターフェースをドメイン層ではなくユースケース層に配置すべき理由を解説。 ドメインモデルとリポジトリの結合防止、構造による設計意図の強制を主眼とする。…
Related neighbors and high-traction skills in the same topics — useful to compare before installing.
claude-api — an installable skill for AI agents, published by affaan-m/ecc.
2.4K installsfrontend-design — an installable skill for AI agents, published by affaan-m/ecc.
1.8K installsBuild a repository that makes findings findable, reusable, and cumulative across teams. Use whe…
1.1K installsAdd one or more Git repositories to Cyrus configuration so it can process issues from those rep…
35 installsSync local skills repository with upstream changes from obra/superpowers-skills
414 installsUnderstand and use repositories in Umbraco backoffice (foundational concept)
333 installsOther skills from j5ik2o/okite-ai · top by installs.
npx skills add j5ik2o/okite-ai
Declared targets from SKILL.md / docs. Unmarked agents are not listed — the skill may still install via the CLI.
main
Files included with this skill beyond the listing page.
SKILL.md
5,655 B
SUMMARY.md
659 B
リポジトリインターフェースはユースケース層に置く。ドメイン層には置かない。
同じ層にあると、ドメインモデルがリポジトリを使いやすくなる:
// ❌ 集約の中でリポジトリを使ってしまう
class Order {
Order withRelatedOrder(OrderId relatedId, OrderRepository repo) {
Order related = repo.findById(relatedId); // ← 同じ層にあるから気軽に使える
return this.withAddedRelatedOrder(related);
}
}
// ❌ ドメインサービスがリポジトリだらけになる
class OrderDomainService {
private OrderRepository orderRepo;
private CustomerRepository customerRepo;
private ProductRepository productRepo;
private InventoryRepository inventoryRepo;
// リポジトリの注入が増え続ける
}
// ドメイン層にこれがあるということは...
interface OrderRepository {
void save(Order order); // ← 「保存」という概念を知っている
Order findById(OrderId id); // ← 「取得」という概念を知っている
}
ドメインモデルは純粋なビジネスルールだけを持つべき。
[ドメイン層] ← リポジトリをimportできない = 結合しない
↑
[ユースケース層] ← リポジトリインターフェース定義(出力ポート)
↑
[インターフェースアダプタ層] ← リポジトリ実装(入力/出力アダプタ)
物理的な距離がガードレールになる:
// ✅ 集約は他の集約をIDで参照
class Order {
private final CustomerId customerId; // Customer実体ではなくID
private final List<ProductId> productIds;
}
// ユースケース層でリポジトリを使って解決
class PlaceOrderUseCase {
private OrderRepository orderRepo;
private CustomerRepository customerRepo;
void execute(PlaceOrderCommand cmd) {
Customer customer = customerRepo.findById(cmd.customerId);
// ユースケース層で必要なエンティティを取得
}
}
domain/
order/
Order.java
OrderRepository.java ← ❌ ここにある
interface-adapters/
repositories/
OrderRepository.java ← ❌ ここにある
domain/
order/
Order.java
OrderId.java
usecases/ (または application/, interactor/)
order/
OrderRepository.java ← インターフェース定義
interface-adapters/ (または adapters/, infra/)
repositories/
JpaOrderRepository.java ← 実装
DDDの伝統的解釈では、リポジトリはドメインの一部(集約のライフサイクル管理)とされる。
しかし実践上は、ドメイン層に置くと結合が生まれやすい。クリーンアーキテクチャの規約では、 リポジトリインターフェースはユースケース層の出力ポートとして扱う。
| アプローチ | メリット | デメリット |
|---|---|---|
| ドメイン層に配置 | DDDの教科書通り | 結合が生まれやすい |
| ユースケース層に配置 | 規約に一致/依存方向が明確 | DDDの純粋主義と異なる |
推奨: ユースケース層に配置し、構造でガードする。
このスキルを使用する際は、以下のスキルも併せて参照すること:
clean-architecture: リポジトリ配置の基盤となる4層アーキテクチャaggregate-design: リポジトリが対応する集約の設計ルールrepository-design: リポジトリの命名・CQS・メソッド設計