← スキル一覧に戻る

ddd-aggregate-design
by forgoty
Collection of dotfiles
⭐ 0🍴 0📅 2026年1月25日
SKILL.md
name: ddd-aggregate-design description: Design rich domain aggregates with proper encapsulation, domain events, and the Export pattern. Use when implementing DDD aggregates with event sourcing patterns.
Rich Domain Aggregate Design
Design and implement rich domain aggregates with proper encapsulation, domain events, and the Export pattern.
When to Use This Skill
- Designing new domain aggregates from scratch
- Refactoring anemic models to rich domain models
- Adding domain events to existing aggregates
- Reviewing aggregate design for encapsulation
Core Rules
Read DDD-RULES.md for all aggregate design rules. Key principles:
- Hide all fields - All struct fields must be private
- Actionable methods only - Expose domain operations, not getters
- Domain Events - Track state changes through events
- Export pattern - Use
Export()to expose state externally - Factory functions - Create aggregates only through validated factories
Quick Reference (Go Examples)
Factory Function Pattern
func NewOrder(customerID CustomerID, items []OrderItem) (*Order, error) {
if len(items) == 0 {
return nil, ErrEmptyOrder
}
o := &Order{
id: NewOrderID(),
status: OrderStatusPending,
events: &eventRegister{},
}
o.addEvent(applayer.NewEvent(OrderCreated{OrderID: o.id}))
return o, nil
}
Actionable Method Pattern
func (o *Order) Ship(warehouse WarehouseID) error {
if o.status == OrderStatusCancelled {
return ErrOrderAlreadyCancelled
}
if o.status == OrderStatusShipped {
return nil // Idempotent
}
oldStatus := o.status
o.status = OrderStatusShipped
o.addEvent(applayer.NewEvent(OrderShipped{OldStatus: oldStatus}))
return nil
}
Export Pattern
func (o *Order) Export() ExportedOrder {
return ExportedOrder{
ID: o.id.String(),
Status: string(o.status),
}
}
func (o *Order) ID() OrderID { return o.id } // Only identity getter allowed
スコア
総合スコア
45/100
リポジトリの品質指標に基づく評価
✓SKILL.md
SKILL.mdファイルが含まれている
+20
○LICENSE
ライセンスが設定されている
0/10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
✓最近の活動
3ヶ月以内に更新
+5
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
✓タグ
1つ以上のタグが設定されている
+5
レビュー
💬
レビュー機能は近日公開予定です


