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 5 hours ago.
0
Like this article? Let the author know and give them a clap!

Other articles you might like

Article Hero Image November 24th 2025

The Difference Between ?: and ?? in PHP

Introduction In PHP, I often see the ternary operator (?:) and null coalescing operator (??) being u...

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
Article Hero Image February 4th 2026

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...

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.