PHP Classes

How to Generate Classes to Implement PHP Event Sourcing Using the Package Laravel Event Sourcing Generator: Generate classes for event sourcing

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2026-05-24 (7 days ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
laravel-event-sourci 1.0MIT/X Consortium ...5Libraries, Code Generation, Design Pa...
Description 

Author

This package can generate classes for event sourcing.

It implements a command for Laravel Artisan that can take the name of an application domain and generates code for several types of classes.

Currently it can generate the following:

- Classes to implement Create, Update and Delete actions

- Data transfer object classes for model data

- Domain classes for events Created, Updated and Deleted

- Projections classes to read the model objects

- Projectors classes to implement event handlers that update projections

It may also generate code optionally for the following:

- Aggregates

- Reactors

- Side-effect handlers

- Notifications

- Failed Events

Picture of Alberto Arena
Name: Alberto Arena <contact>
Classes: 3 packages by
Country: Italy Italy
Innovation award
Innovation award
Nominee: 2x

Instructions

Please read this document to learn how to use a Laravel Artisan command to generate event sourcing code.

Documentation

Laravel event sourcing generator

build-test Latest Version on Packagist Total Downloads License Code Size

Laravel event sourcing generator scaffolds complete domain structures for Spatie's Laravel Event Sourcing, providing a single Artisan command to generate events, projections, projectors, aggregates, reactors, actions, DTOs, notifications, and PHPUnit tests.

New to event sourcing? Check out Spatie's documentation to understand projections, aggregates, and reactors.

Using Claude Code? Install the companion claude-laravel-event-sourcing skill to scaffold domains conversationally.

Table of Contents

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Feel free to fork, improve and create a pull request.

Please see CONTRIBUTING for details.

Installation

Compatibility

| What | Version | |-----------------------------------------------------------------------------|-------------| | PHP | 8.3 / 8.4 | | Laravel | 10.x / 11.x | | Spatie's event sourcing | 7.x |

Install

composer require albertoarena/laravel-event-sourcing-generator

Quick Start

Generate a basic domain structure:

php artisan make:event-sourcing-domain Animal --domain=Animal

This creates a complete event-sourced domain with events, projections, projectors, and actions in app/Domain/Animal/Animal/.

For more advanced features, see the Usage section below.

What Gets Generated

Running the command creates this structure in your app/Domain/{DomainName}/{ModelName}/ directory:

Always Generated: - Actions/ - Create/Update/Delete action classes - DataTransferObjects/ - DTOs for model data - Events/ - Domain events (Created, Updated, Deleted) - Projections/ - Read model (Eloquent model) - Projectors/ - Event handlers that update projections

Optional (with flags): - Aggregates/ - Aggregate root (--aggregate=1, requires uuid primary key) - Reactors/ - Side-effect handlers (--reactor=1) - Notifications/ - Event notifications (--notifications=database,mail,slack,teams) - Notifications/Concerns/ - Shared notification traits - tests/Domain/{DomainName}/{ModelName}/ - PHPUnit tests (--unit-test)

With Failed Events (--failed-events=1): - Additional events: {Model}CreationFailed, {Model}UpdateFailed, {Model}DeletionFailed - Corresponding notifications if --notifications is also specified

Usage

php artisan make:event-sourcing-domain <model> [options]

Basic Options: - -d|--domain=<domain> - The name of the domain - --namespace=<namespace> - The namespace or root folder (default: "Domain") - --root=<root> - The name of the root folder (default: "app")

Migration Options: - -m|--migration=<migration> - Existing migration for the model (with or without timestamp prefix, or table name) - --migration-exclude=<pattern> - Migration pattern to exclude (supports regex)

Feature Flags: - -a|--aggregate=<0|1> - Generate aggregate (requires uuid primary key) - -r|--reactor=<0|1> - Generate reactor - -u|--unit-test - Generate PHPUnit tests - --failed-events=<0|1> - Generate failed event classes - --notifications=<types> - Generate notifications (database,mail,slack,teams, or no)

Model Configuration: - -p|--primary-key=<uuid|id> - Primary key type (default: uuid) - --indentation=<spaces> - Indentation spaces for generated code (default: 4)

Show help

php artisan help make:event-sourcing-domain

Basic usage

Documentation about basic usage

Generate a model with same name of the domain

php artisan make:event-sourcing-domain Animal \
  --domain=Animal

Generate a model with different domain

Read documentation with examples

php artisan make:event-sourcing-domain Tiger \
  --domain=Animal

Generate a model with different domain and namespace

Read documentation with examples

php artisan make:event-sourcing-domain Tiger \
  --domain=Animal \
  --namespace=CustomDomain 

Generate a model from existing migration

Read documentation with examples

php artisan make:event-sourcing-domain Animal \
  --migration=create_animal_table \
  --unit-test

Generate a model from existing migration using pattern and exclude specific one

Read documentation with examples

php artisan make:event-sourcing-domain Animal \
  --migration=animal \
  --migration-exclude=drop_last_column_from_animals \
  --unit-test

Generate a model from existing migration using pattern and exclude using regex

Read documentation with examples

php artisan make:event-sourcing-domain Animal \
  --migration=animal \
  --migration-exclude="/drop_.*_from_animals/" \
  --unit-test

Generate a model from existing migration with failed events and notifications

php artisan make:event-sourcing-domain Animal \
  --migration=create_animal_table \
  --failed-events=1 \
  --notifications=database,mail,slack

Domain and namespace

Read documentation about directory structure

Specify the name of the domain

Read documentation with examples

php artisan make:event-sourcing-domain Animal --domain=Tiger
php artisan make:event-sourcing-domain Animal --domain=Lion

Specify the namespace

Read documentation with examples

php artisan make:event-sourcing-domain Tiger --namespace=MyDomain --domain=Animal

Advanced usage

Set primary key

Read documentation with examples

Default primary key is uuid. That will work with Aggregate class.

It is possible to use id as primary key:

php artisan make:event-sourcing-domain Animal --primary-key=id

When importing migrations, primary key will be automatically loaded from file.

Generate PHPUnit tests

Read documentation with examples

php artisan make:event-sourcing-domain Animal --unit-test

Generate aggregates

Read documentation with examples

php artisan make:event-sourcing-domain Animal --aggregate=1

This is available only for models using uuid as primary key.

Generate reactors

Read documentation with examples

php artisan make:event-sourcing-domain Animal --reactor=1

Generate failed events

Read documentation with examples

php artisan make:event-sourcing-domain Animal --failed-events=1

Generate notifications

Read documentation with examples

php artisan make:event-sourcing-domain Animal --notifications=<NOTIFICATIONS>

Specify indentation

Read documentation with examples

php artisan make:event-sourcing-domain Animal --indentation=2

Specify the path of root folder

Read documentation with examples

php artisan make:event-sourcing-domain Animal --root=src

Limitations and future enhancements

Blueprint column types

Read documentation


  Files folder image Files (93)  
File Role Description
Files folder image.claude (1 directory)
Files folder image.github (1 directory)
Files folder imagedocs (5 files, 1 directory)
Files folder imagesrc (4 directories)
Files folder imagestubs (28 files)
Files folder imagetests (1 file, 4 directories)
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file CLAUDE.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file CONTRIBUTING.md Data Auxiliary data
Accessible without login Plain text file coverage.svg Data Auxiliary data
Accessible without login Plain text file LICENSE.md Lic. License text
Accessible without login Plain text file phpstan.neon Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file pint.json Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file testbench.yaml Data Auxiliary data

  Files folder image Files (93)  /  .claude  
File Role Description
Files folder imageplans (1 file, 1 directory)

  Files folder image Files (93)  /  .claude  /  plans  
File Role Description
Files folder imagealberto (1 file)
  Accessible without login Plain text file developers.json Data Auxiliary data

  Files folder image Files (93)  /  .claude  /  plans  /  alberto  
File Role Description
  Accessible without login Plain text file 2026-05-19-expand-contributing-guide.md Data Auxiliary data

  Files folder image Files (93)  /  .github  
File Role Description
Files folder imageworkflows (1 file)

  Files folder image Files (93)  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file test.yml Data Auxiliary data

  Files folder image Files (93)  /  docs  
File Role Description
Files folder imageplans (1 file)
  Accessible without login Plain text file advanced-usage.md Data Auxiliary data
  Accessible without login Plain text file basic-usage.md Data Auxiliary data
  Accessible without login Plain text file domain-and-namespace.md Data Auxiliary data
  Accessible without login Plain text file migrations.md Data Auxiliary data
  Accessible without login Plain text file unit-tests.md Data Auxiliary data

  Files folder image Files (93)  /  docs  /  plans  
File Role Description
  Accessible without login Plain text file branch-protection-ruleset.md Data Auxiliary data

  Files folder image Files (93)  /  src  
File Role Description
Files folder imageConsole (1 directory)
Files folder imageDomain (5 directories)
Files folder imageExceptions (4 files)
Files folder imageProviders (1 file)

  Files folder image Files (93)  /  src  /  Console  
File Role Description
Files folder imageCommands (1 file)

  Files folder image Files (93)  /  src  /  Console  /  Commands  
File Role Description
  Plain text file MakeEventSourcingDomainCommand.php Class Class source

  Files folder image Files (93)  /  src  /  Domain  
File Role Description
Files folder imageBlueprint (2 directories)
Files folder imageCommand (3 directories)
Files folder imageMigrations (1 file)
Files folder imagePhpParser (1 file, 3 directories)
Files folder imageStubs (3 files, 1 directory)

  Files folder image Files (93)  /  src  /  Domain  /  Blueprint  
File Role Description
Files folder imageConcerns (2 files)
Files folder imageContracts (1 file)

  Files folder image Files (93)  /  src  /  Domain  /  Blueprint  /  Concerns  
File Role Description
  Plain text file HasBlueprintColumnType.php Class Class source
  Plain text file HasBlueprintFake.php Class Class source

  Files folder image Files (93)  /  src  /  Domain  /  Blueprint  /  Contracts  
File Role Description
  Plain text file BlueprintUnsupportedInterface.php Class Class source

  Files folder image Files (93)  /  src  /  Domain  /  Command  
File Role Description
Files folder imageConcerns (1 file)
Files folder imageContracts (2 files)
Files folder imageModels (1 file)

  Files folder image Files (93)  /  src  /  Domain  /  Command  /  Concerns  
File Role Description
  Plain text file CanCreateDirectories.php Class Class source

  Files folder image Files (93)  /  src  /  Domain  /  Command  /  Contracts  
File Role Description
  Plain text file AcceptedNotificationInterface.php Class Class source
  Plain text file DefaultSettingsInterface.php Class Class source

  Files folder image Files (93)  /  src  /  Domain  /  Command  /  Models  
File Role Description
  Plain text file CommandSettings.php Class Class source

  Files folder image Files (93)  /  src  /  Domain  /  Migrations  
File Role Description
  Plain text file Migration.php Class Class source

  Files folder image Files (93)  /  src  /  Domain  /  PhpParser  
File Role Description
Files folder imageConcerns (2 files)
Files folder imageModels (4 files)
Files folder imageTraversers (1 file)
  Plain text file MigrationParser.php Class Class source

  Files folder image Files (93)  /  src  /  Domain  /  PhpParser  /  Concerns  
File Role Description
  Plain text file HasMethodNode.php Class Class source
  Plain text file HasSchemaUpNode.php Class Class source

  Files folder image Files (93)  /  src  /  Domain  /  PhpParser  /  Models  
File Role Description
  Plain text file EnterNode.php Class Class source
  Plain text file MigrationCreateProperties.php Class Class source
  Plain text file MigrationCreateProperty.php Class Class source
  Plain text file MigrationCreatePropertyType.php Class Class source

  Files folder image Files (93)  /  src  /  Domain  /  PhpParser  /  Traversers  
File Role Description
  Plain text file BlueprintClassNodeVisitor.php Class Class source

  Files folder image Files (93)  /  src  /  Domain  /  Stubs  
File Role Description
Files folder imageModels (1 file)
  Plain text file StubReplacer.php Class Class source
  Plain text file StubResolver.php Class Class source
  Plain text file Stubs.php Class Class source

  Files folder image Files (93)  /  src  /  Domain  /  Stubs  /  Models  
File Role Description
  Plain text file StubCallback.php Class Class source

  Files folder image Files (93)  /  src  /  Exceptions  
File Role Description
  Plain text file MigrationDoesNotExistException.php Class Class source
  Plain text file MigrationInvalidException.php Class Class source
  Plain text file MigrationInvalidPrimaryKeyException.php Class Class source
  Plain text file ParserFailedException.php Class Class source

  Files folder image Files (93)  /  src  /  Providers  
File Role Description
  Plain text file PackageServiceProvider.php Class Class source

  Files folder image Files (93)  /  stubs  
File Role Description
  Plain text file actions.create.with-aggregate.stub Class Class source
  Plain text file actions.create.without-aggregate.stub Class Class source
  Plain text file actions.delete.with-aggregate.stub Class Class source
  Plain text file actions.delete.without-aggregate.stub Class Class source
  Plain text file actions.update.with-aggregate.stub Class Class source
  Plain text file actions.update.without-aggregate.stub Class Class source
  Plain text file aggregate.stub Class Class source
  Plain text file data-transfer-object.stub Class Class source
  Plain text file events.created.stub Class Class source
  Plain text file events.creation_failed.stub Class Class source
  Plain text file events.deleted.stub Class Class source
  Plain text file events.deletion_failed.stub Class Class source
  Plain text file events.updated.stub Class Class source
  Plain text file events.update_failed.stub Class Class source
  Plain text file notifications.conc..._data_as_array.stub Class Class source
  Plain text file notifications.conc...s_notification.stub Class Class source
  Plain text file notifications.conc...k_notification.stub Class Class source
  Plain text file notifications.created.stub Class Class source
  Plain text file notifications.creation_failed.stub Class Class source
  Plain text file notifications.deleted.stub Class Class source
  Plain text file notifications.deletion_failed.stub Class Class source
  Plain text file notifications.updated.stub Class Class source
  Plain text file notifications.update_failed.stub Class Class source
  Plain text file projection.stub Class Class source
  Plain text file projector.stub Class Class source
  Plain text file reactor.stub Class Class source
  Accessible without login Plain text file stub-mapping.json Data Auxiliary data
  Plain text file test.stub Class Class source

  Files folder image Files (93)  /  tests  
File Role Description
Files folder imageConcerns (3 files)
Files folder imageDomain (2 directories)
Files folder imageMocks (1 file)
Files folder imageUnit (2 directories)
  Plain text file TestCase.php Class Class source

  Files folder image Files (93)  /  tests  /  Concerns  
File Role Description
  Plain text file AssertsDomainGenerated.php Class Class source
  Plain text file CreatesMockMigration.php Class Class source
  Plain text file WithMockPackages.php Class Class source

  Files folder image Files (93)  /  tests  /  Domain  
File Role Description
Files folder imageMigrations (1 file, 1 directory)
Files folder imagePhpParser (1 directory)

  Files folder image Files (93)  /  tests  /  Domain  /  Migrations  
File Role Description
Files folder imageContracts (1 file)
  Plain text file ModifyMigration.php Class Class source

  Files folder image Files (93)  /  tests  /  Domain  /  Migrations  /  Contracts  
File Role Description
  Plain text file MigrationOptionInterface.php Class Class source

  Files folder image Files (93)  /  tests  /  Domain  /  PhpParser  
File Role Description
Files folder imageTraversers (1 file)

  Files folder image Files (93)  /  tests  /  Domain  /  PhpParser  /  Traversers  
File Role Description
  Plain text file BlueprintClassModifyNodeVisitor.php Class Class source

  Files folder image Files (93)  /  tests  /  Mocks  
File Role Description
  Plain text file MockFilesystem.php Class Class source

  Files folder image Files (93)  /  tests  /  Unit  
File Role Description
Files folder imageConsole (1 directory)
Files folder imageDomain (1 directory)

  Files folder image Files (93)  /  tests  /  Unit  /  Console  
File Role Description
Files folder imageCommands (8 files)

  Files folder image Files (93)  /  tests  /  Unit  /  Console  /  Commands  
File Role Description
  Plain text file MakeEventSourcingD...dAggregatesTest.php Class Class source
  Plain text file MakeEventSourcingD...ommandBasicTest.php Class Class source
  Plain text file MakeEventSourcingD...ailedEventsTest.php Class Class source
  Plain text file MakeEventSourcingD...andFailuresTest.php Class Class source
  Plain text file MakeEventSourcingD...dMigrationsTest.php Class Class source
  Plain text file MakeEventSourcingD...tificationsTest.php Class Class source
  Plain text file MakeEventSourcingD...andReactorsTest.php Class Class source
  Plain text file MakeEventSourcingD...ndUnitTestsTest.php Class Class source

  Files folder image Files (93)  /  tests  /  Unit  /  Domain  
File Role Description
Files folder imagePhpParser (1 directory)

  Files folder image Files (93)  /  tests  /  Unit  /  Domain  /  PhpParser  
File Role Description
Files folder imageModels (2 files)

  Files folder image Files (93)  /  tests  /  Unit  /  Domain  /  PhpParser  /  Models  
File Role Description
  Plain text file MigrationCreatePropertiesTest.php Class Class source
  Plain text file MigrationCreatePropertyTypeTest.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads  
 100%
Total:0
This week:0