Event sourcing with a little help from AI
Photo by Daniel McCullough on Unsplash
Event sourcing in Laravel gives you a complete history of your domain, but the hardest part isn't writing the code: it's making the design decisions. Which events cross a boundary? Where does a projector end and a reactor begin? What invariants should the aggregate enforce?
I built a Claude Code skill that treats these decisions as a conversation before generating any code.
The problem with scaffolding My earlier artisan-based generator could produce aggregates, events, and projectors from a migration. It worked well for simple cases and crossed 8,000 Packagist downloads. But event sourcing stops being simple quickly — real domains have invariants, side effects, and read models that a CLI flag can't capture.
Design first, then code
The skill works in two gates.
Gate 1 - Design. Claude asks five focused questions about your domain: what the feature does, what state transitions matter, what triggers commands, whether you need read models, and what side effects are involved. From your answers it produces an Architecture Decision Record listing the aggregates, commands, events, projectors, and reactors. Nothing is generated until you approve.
Gate 2 - Implementation. After approval, Claude generates the full domain: tests first (TDD), then commands, handlers, aggregates, events, projectors with migrations, reactors, and config registration. It runs the test suite and reports the results.
If it hits an ambiguity the ADR didn't cover, it pauses and asks.
What gets generated
app/Domain/<Context>/
├── Aggregates/
├── Commands/
├── CommandHandlers/
├── Events/
├── Projectors/
├── Reactors/
└── ReadModels/
tests/Feature/<Context>/
database/migrations/
Everything compiles and tests run green out of the box.
Scope and constraints
The skill is deliberately narrow: greenfield domains only, Laravel 10+ with spatie/laravel-event-sourcing v7. It won't refactor existing CRUD into event sourcing. Keeping the scope tight keeps the output reliable.
Getting started
Install into your project's .claude/skills/ directory:
mkdir -p .claude/skills
git clone https://github.com/albertoarena/claude-laravel-event-sourcing.git /tmp/claude-les
cp -r /tmp/claude-les/skill/laravel-spatie-event-sourcing .claude/skills/
rm -rf /tmp/claude-les
Then open Claude Code and describe your domain. The skill handles the rest.
Requirements: Laravel 10+, PHP 8.2+, Spatie event sourcing v7, Pest or PHPUnit.
The skill is at v0.2.0 — issues and feedback welcome on GitHub.
Other articles you might like
The Difference Between ?: and ?? in PHP
Introduction In PHP, I often see the ternary operator (?:) and null coalescing operator (??) being u...
From 400-Line Import Controllers to 20-Line Configs in Laravel
The "Import Nightmares" We All Know If you've built business applications with Laravel, yo...
How Big Tech Generates Initial-Based Avatars — And How You Can Do the Same in Laravel
If you’ve ever created an account on platforms like Google, GitHub, Slack, or Notion, you’ve seen it...
The Laravel portal for problem solving, knowledge sharing and community building.