Design rich domain aggregates with proper encapsulation, domain events, and the Export pattern. Use when implementing DDD aggregates with event sourcing patterns.
68
82%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
Design and implement rich domain aggregates with proper encapsulation, domain events, and the Export pattern.
Read DDD-RULES.md for all aggregate design rules. Key principles:
Export() to expose state externallyfunc 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
}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
}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 allowed0d0cc99
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.