Support the ongoing development of Laravel.io →
Article Hero Image

Event sourcing with a little help from AI

28 Apr, 2026 2 min read

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.

Last updated 1 month ago.
1
Like this article? Let the author know and give them a clap!

Other articles you might like

Article Hero Image May 30th 2026

Evals in Laravel: How to Prove Your AI Output Is Actually Good

You shipped the ticket classifier last quarter. It works. The tests are green and they've stayed gre...

Read article
Article Hero Image October 29th 2025

Run PHPUnit and Pest Tests Without Vite Assets in Laravel

Introduction A common way to build your Laravel application's frontend assets is with Vite (by runni...

Read article
Article Hero Image February 5th 2026

From 400-Line Import Controllers to 20-Line Configs in Laravel

The &quot;Import Nightmares&quot; We All Know If you've built business applications with Laravel, yo...

Read article

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2026 Laravel.io - All rights reserved.