Laravel spatie event sourcing
Skill albertoarena/claude-laravel-event-sourcing/skill/laravel-spatie-event-sourcing
A Claude Code skill that helps you design and generate event-sourced domain code for Laravel using Spatie event sourcing
npx -y skills add albertoarena/claude-laravel-event-sourcing --skill laravel-spatie-event-sourcingAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 2 stars2 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Use this skill any time a user works with Laravel and event sourcing together — whether setting up spatie/laravel-event-sourcing for the first time, designing a new event-sourced domain (aggregates, events, projectors, reactors), generating code for bounded contexts, or debugging issues with AggregateRoot, StoredEvent, or projectors. Trigger on: "event sourcing" + "Laravel", spatie ES references, requests to model domain lifecycles as events, or questions about aggregate roots and projectors in PHP/Laravel. Do NOT use for: refactoring existing CRUD into ES, Laravel's built-in Event::dispatch system, CQRS without event sourcing, or non-spatie packages.
SKILL.md
6.5 KB, as published. Nobody here has run it
Laravel Spatie Event Sourcing — Skill
Generate event-sourced domain code for Laravel using spatie/laravel-event-sourcing, following a two-gate workflow: Design first, then implement with tests.
Quick reference
references/design-heuristics.md— Event naming, aggregate boundaries, projector/reactor rules, anti-patternsreferences/adr-template.md— ADR template for Gate 1references/tdd-patterns.md— Pest and PHPUnit test patternsreferences/commands-pattern.md— Command + handler patterns (plain and bus-dispatched)references/spatie-api-cheatsheet.md— Key Spatie ES classes and methodsassets/templates/*.stub— Code generation stubs
Project bootstrap (one-time, automatic)
On first invocation in a project, run scripts/verify-setup.sh from this skill's directory. It checks:
- PHP 8.2+ is installed (required by
spatie/laravel-event-sourcingv7) spatie/laravel-event-sourcingis incomposer.json- The
stored_eventsandsnapshotstables exist (migrations have run) config/event-sourcing.phphas been published- A test framework is installed (Pest preferred, PHPUnit fallback)
If anything is missing, print the single command that fixes it and stop. Do not auto-install packages or run migrations on behalf of the user — they need to confirm first.
If everything passes, check for .claude/event-sourcing.md in the project root. If it doesn't exist, ask the user one configuration question:
"I'll create a project config at
.claude/event-sourcing.md. Two quick choices:
- Command dispatch style: plain handler classes invoked directly, or Laravel's command bus (
Bus::dispatch)?- Test framework: Pest or PHPUnit?"
Write their answers to that file. On future invocations, read it silently and proceed.
The two-gate workflow
This skill operates in two gates with a hard stop between them. The user must approve the design before any code gets written.
Gate 1 — Design (ADR)
Start with domain analysis. Ask 3–5 focused questions (skip any the user already answered):
- What feature or bounded context are we building? (one sentence)
- What state does it hold, and what state transitions matter?
- What external actions trigger those transitions?
- What read models does the application need?
- What side effects happen on state changes? (emails, external API calls, other aggregates)
Then produce an ADR using the template in references/adr-template.md. The ADR covers:
- Proposed aggregate(s) with justification for each boundary
- Commands that trigger each aggregate method
- Events recorded by each method (past-tense, domain-meaningful names — read
references/design-heuristics.mdfor naming rules) - Projectors and their read models (sync vs queued, with reasoning)
- Reactors and their side effects
- Invariants the aggregate enforces
- Explicitly punted concerns (data migration, snapshots, etc.)
- Anti-patterns actively avoided
Stop here. Present the ADR and wait for the user to approve, request changes, or edit inline. Iterate until they say something like "approved", "looks good", or "let's build it."
Do not write any implementation code during Gate 1.
Gate 2 — Implementation + verification
Once the ADR is approved, generate everything in one uninterrupted flow. No mid-implementation questions — if something is ambiguous, that's an ADR defect; go back to Gate 1.
Generation order:
- Create the directory structure under
app/Domain/<Context>/ - Write tests FIRST (Pest or PHPUnit per project config) — aggregate tests, projector tests, reactor tests
- Write command DTOs
- Write command handlers (plain or bus-dispatched per project config)
- Write the aggregate root
- Write event classes
- Write projector(s) and read-model migration(s) — migrations must use a UUID primary key (
$table->uuid('uuid')->primary()), no auto-increment, and include$table->timestamps() - Write reactor(s)
- Register projectors and reactors in
config/event-sourcing.php - Run the test suite (
./vendor/bin/pestor./vendor/bin/phpunit) - Report: list of files created + test output
Use the stub templates in assets/templates/ as starting points. Read references/tdd-patterns.md for test structure and references/commands-pattern.md for command/handler patterns.
Stop here. Present the results. The user approves, requests changes, or moves to the next feature.
Directory conventions
app/Domain/<Context>/
├── Aggregates/
│ └── <Name>Aggregate.php
├── Commands/
│ └── <Verb><Noun>Command.php
├── CommandHandlers/
│ └── <Verb><Noun>Handler.php
├── Events/
│ └── <Noun><PastTenseVerb>.php
├── Projectors/
│ └── <Noun>Projector.php
├── Reactors/
│ └── Send<Noun><Action>Reactor.php
└── ReadModels/
└── <Noun>.php
tests/Feature/<Context>/
├── <Name>AggregateTest.php
├── <Noun>ProjectorTest.php
└── <Noun>ReactorTest.php
database/migrations/
└── <timestamp>_create_<read_model>_table.php
Scope boundary
This skill is for greenfield event sourcing only. If the user asks to refactor existing CRUD code into event sourcing, politely decline and explain that CRUD-to-ES migration is a different (and much harder) problem that this skill doesn't cover. Suggest they design the event-sourced version from scratch alongside the existing code instead.
When things go wrong
- Tests fail after generation: Read the failure output, fix the code, rerun. Don't ask the user to debug generated code — that's our job.
- Ambiguity during Gate 2: Return to Gate 1 and update the ADR. Don't make assumptions mid-implementation.
- User wants to change the design after seeing code: No problem — update the ADR, regenerate the affected files, rerun tests.