$ recombobulate _
home / tips / ask-claude-to-implement-an-event-sourcing-pattern
0

Ask Claude to Implement an Event Sourcing Pattern

bagwaa @bagwaa · Mar 26, 2026 · Workflows
ask-claude-to-implement-an-event-sourcing-pattern

Event sourcing is one of those patterns that's conceptually clear but tricky to wire up correctly from scratch. Claude can design the whole structure for your domain.

claude "Implement a basic event sourcing setup in Laravel for a BankAccount aggregate. Include: a DomainEvent base class, AccountOpened/MoneyDeposited/MoneyWithdrawn events, an EventStore using a database table, and the BankAccount aggregate that rebuilds state by replaying events."

Claude will design cohesive, minimal classes — not a framework — keeping the core pattern clear:

class BankAccount
{
    private float $balance = 0;
    private array $recordedEvents = [];

    public static function reconstitute(array $events): self
    {
        $account = new self();
        foreach ($events as $event) {
            $account->apply($event);
        }
        return $account;
    }

    private function apply(DomainEvent $event): void
    {
        match($event::class) {
            MoneyDeposited::class => $this->balance += $event->amount,
            MoneyWithdrawn::class => $this->balance -= $event->amount,
            default => null,
        };
    }
}

Ask Claude to extend it with projections, snapshots, or a process manager once the core is solid. Build incrementally.

Event sourcing pays dividends in auditability — Claude helps you get the foundation right.

~/recombobulate $ tip --comments --count=0

Log in to leave a comment.

~/recombobulate $ tip --related --limit=3
0
Scan Pending Changes for Security Issues with /security-review

The /security-review command scans your uncommitted changes for injection vectors, auth gaps, hardcoded secrets, and other common vulnerabilities.

bagwaa @bagwaa · 1 hour ago
0
Run Setup Scripts on Every Session with the SessionStart Hook

The SessionStart hook fires when any session begins or resumes, making it ideal for loading environment variables and running one-time setup scripts.

bagwaa @bagwaa · 1 hour ago
0
Write Property-Based Tests with fast-check and Claude

Ask Claude to write property-based tests for your functions using fast-check — it identifies the mathematical invariants in your code and generates tests that cover inputs you'd never enumerate by hand.

bagwaa @bagwaa · 2 hours ago