Claude Codeで集約を設計する:集約境界の決定・不変条件の保護・集約間の参照

はじめに 「集約の境界をどこで引くか迷う」「集約Aから集約Bの内部を変更している」——DDDの集約設計で不変条件を守り、集約間の正しい参照方法を設計をClaude Codeに生成させる。 CLAUDE.mdに集約設計ルールを書く ## 集約設計ルール ### 集約境界の決定基準 - 同時に変更される必要があるエンティティをひとまとめにする - 集約は小さく保つ(大きすぎると競合が多発) - ...

By · · 1 min read
Claude Codeで集約を設計する:集約境界の決定・不変条件の保護・集約間の参照

Source: DEV Community

はじめに 「集約の境界をどこで引くか迷う」「集約Aから集約Bの内部を変更している」——DDDの集約設計で不変条件を守り、集約間の正しい参照方法を設計をClaude Codeに生成させる。 CLAUDE.mdに集約設計ルールを書く ## 集約設計ルール ### 集約境界の決定基準 - 同時に変更される必要があるエンティティをひとまとめにする - 集約は小さく保つ(大きすぎると競合が多発) - 集約のルート(Aggregate Root)のみが外部から直接参照される ### 不変条件 - 集約内の全エンティティの整合性を保証するビジネスルール - 不変条件の検証は集約ルートのメソッドで行う - 外部から集約の内部エンティティを直接変更しない ### 集約間の参照 - 集約間はIDのみで参照(直接の集約オブジェクト参照禁止) - 複数集約にまたがる操作はアプリケーション層(ユースケース)で調整 - 集約間の整合性は結果整合(eventual consistency) 集約設計実装の生成 集約設計のベストプラクティスを実装してください。 要件: - 集約ルートによる不変条件の保護 - 内部エンティティへのアクセス制限 - 集約間のID参照 - コレクション変更の制御 生成ファイル: src/domain/aggregates/ 生成される集約設計実装 // src/domain/aggregates/order/order.ts — 集約ルート // エラー: OrderItemは集約内部エンティティ(外部から直接操作しない) class OrderItem { private constructor( private readonly _id: string, private readonly _productId: string, // 商品集約のID参照(集約オブジェクトは持たない) private _quantity: number, private readonly _price: Money ) {} static create(productId: string, quantity: number, price: Money): OrderItem { if (quantity <= 0) throw new DomainError('Quantity

Related Posts

Similar Topics

#ai (34)#webdev (21)#fix (18)#feat (18)#javascript (14)#opensource (13)#chore (10)#mcp (9)#api (9)#large language models (4)#modernization (6)#react (6)#tutorial (6)#backbonejs (6)#css (6)#nextjs (6)#node (6)#es6 (6)#programming (6)#redis (2)

Trending on ShareHub

  1. Understanding Modern JavaScript Frameworks in 2026
    by Alex Chen · Feb 12, 2026 · 0 likes
  2. The System Design Primer
    by Sarah Kim · Feb 12, 2026 · 0 likes
  3. Just shipped my first open-source project!
    by Alex Chen · Feb 12, 2026 · 0 likes
  4. OpenAI Blog
    by Sarah Kim · Feb 12, 2026 · 0 likes
  5. Building Accessible Web Applications: A Practical Guide
    by Alex Chen · Feb 12, 2026 · 0 likes
  6. Rapper Lil Poppa dead at 25, days after releasing new music
    Rapper Lil Poppa dead at 25, days after releasing new music
    by Anonymous User · Feb 19, 2026 · 0 likes
  7. write-for-us
    by Volt Raven · Mar 7, 2026 · 0 likes
  8. Before the Coffee Gets Cold: Heartfelt Story of Time Travel and Second Chances
    Before the Coffee Gets Cold: Heartfelt Story of Time Travel and Second Chances
    by Anonymous User · Feb 12, 2026 · 0 likes
    #coffee gets cold #the #time travel
  9. Best DoorDash Promo Code Reddit Finds for Top Discounts
    Best DoorDash Promo Code Reddit Finds for Top Discounts
    by Anonymous User · Feb 12, 2026 · 0 likes
    #doordash #promo #reddit
  10. Premium SEO Services That Boost Rankings & Revenue | VirtualSEO.Expert
    by Anonymous User · Feb 12, 2026 · 0 likes
  11. NBC under fire for commentary about Team USA women's hockey team
    NBC under fire for commentary about Team USA women's hockey team
    by Anonymous User · Feb 18, 2026 · 0 likes
  12. Where to Watch The Nanny: Streaming and Online Viewing Options
    Where to Watch The Nanny: Streaming and Online Viewing Options
    by Anonymous User · Feb 12, 2026 · 0 likes
    #streaming #the nanny #where
  13. How Much Is Kindle Unlimited? Subscription Cost and Plan Details
    How Much Is Kindle Unlimited? Subscription Cost and Plan Details
    by Anonymous User · Feb 12, 2026 · 0 likes
    #kindle unlimited #subscription #unlimited
  14. Russian skater facing backlash for comment about Amber Glenn
    Russian skater facing backlash for comment about Amber Glenn
    by Anonymous User · Feb 18, 2026 · 0 likes
  15. Google News
    Google News
    by Anonymous User · Feb 18, 2026 · 0 likes

Latest on ShareHub

Browse Topics

#artificial intelligence (31568)#data science (24018)#ai (17130)#generative ai (15034)#crypto (15004)#machine learning (14681)#bitcoin (14252)#featured (13563)#news & insights (13064)#crypto news (11089)

Around the Network