Craft Event Driven Model

Crafting Event-Driven Models. Side effects via observers.

attac-t 3a6823c 2 files · 3.9 KB Updated

File contents

Skill: Craft Event-Driven Model

"Models emit events. Subscribers handle consequences."

The Standard

  1. Dispatch Domain Events: $dispatchesEvents maps model events to domain events.
  2. Subscribers Handle Logic: Calculations, notifications, logging—outside the model.
  3. Keep Models Thin: Model changes state. Events trigger side effects.
  4. Test Events Separately: Model tests don't test subscriber behavior.

The Anti-Patterns

❌ Don't ✅ Do Why
Logic in boot() Event + Subscriber Testable, traceable
Direct method calls Dispatch event Loose coupling
Fat model observers Focused subscribers Single responsibility
Skip event for "simple" Always event for side effects Consistency

Real-World Examples

See examples.md.

attac-t/the-foundry/tree/main/plugins/laravel-ddd/skills/craft-event-driven-model commit 3a6823cd04

Frequently asked questions

npx skillmds@latest add attac-t/craft-event-driven-model