albertoarena/laravel-event-sourcing-generator
Composer 安装命令:
composer require albertoarena/laravel-event-sourcing-generator
包简介
Laravel event sourcing domain generator
README 文档
README
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
- Contributing
- Installation
- Quick Start
- What Gets Generated
- Usage
- Limitations and future enhancements
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 / 8.5 |
| Laravel | 11.x (deprecated) / 12.x / 13.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 classesDataTransferObjects/- DTOs for model dataEvents/- 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
--notificationsis 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
albertoarena/laravel-event-sourcing-generator 适用场景与选型建议
albertoarena/laravel-event-sourcing-generator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.05k 次下载、GitHub Stars 达 24, 最近一次更新时间为 2024 年 11 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 albertoarena/laravel-event-sourcing-generator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 albertoarena/laravel-event-sourcing-generator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 10.05k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 24
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-11-25