phauthentic / event-sourcing
An event sourcing library for PHP. Framework agnostic, simple, SOLID and easy to use.
Requires
- php: ^8.2
- phauthentic/event-store: dev-master
- phauthentic/snapshot-store: dev-master
Requires (Dev)
- ext-pdo: *
- phpmd/phpmd: ^2.15
- phpro/grumphp-shim: ^2.5
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^9.6
- psr/container: ^1.0||^2.0
- psr/log: ^2.0||^3.0
- ramsey/uuid: ^4.7
- squizlabs/php_codesniffer: ^4.0
- symfony/messenger: ^6.0||^7.0
- symfony/var-dumper: ^6.0||^7.1
Suggests
- psr/container: If you want to use the repository factory.
- psr/log: If you want to use any of the components that use a PSR logger.
This package is auto-updated.
Last update: 2024-04-23 23:38:49 UTC
README
⚠ Do not use it in production! This is still in development! ⚠
A framework-agnostic event sourcing system.
Consider this library a framework to create your own flavor of event sourcing within your application. The library tries to provide different styles and flavors that you can freely combine to implement event sourcing in your application.
We consider the repository the main element in the system that connects the extraction of events from the actual aggregate the persistence of the aggregate taking snapshots and emitting events.
It features different ways of extracting information from your aggregates, pick your flavor:
- Via Attributes
- Via Interfaces
- Via Reflection
What is Event Sourcing?
Event sourcing is a software architecture pattern that emphasizes capturing and persisting the state of an application as a sequence of events rather than storing the current state directly. In event sourcing, every state-changing operation, or event, is stored in an append-only log. The current state of an entity is reconstructed by replaying these events in sequence.
This approach provides a comprehensive audit trail of all changes, enabling traceability, versioning, and the ability to rebuild the system's state at any point in time. Event sourcing promotes a decentralized and scalable model, facilitating event-driven architectures and supporting the evolution of domain models over time, making it particularly suitable for complex business domains and systems where temporal aspects and historical data are crucial.
When to NOT use it
Event sourcing comes with additional complexity. You should NOT use event sourcing when you don't need it. It is a powerful tool, but it is not a silver bullet. It is not a one-size-fits-all solution. Event sourcing is a good solution for scenarious like audit logging, undo/redo functionality, and complex business rules.
If you have no good reason to use it, then don't.
Installation
composer require phauthentic/event-sourcing
Documentation
Please start by reading the docs folder in this repository.
Other Event Sourcing Libraries
If you don't like this library, you might get happy with one of those. We think that different libraries for the same purpose approach the same problem from different angles and probably for different skill levels and audiences. Therefor we are happy to provide you with a list of alternatives.
It would be nice if you could tell us why you preferred another library, thank you!
Event Sauce
A wide used an well know library.
Prooph Event Sourcing
A very well engineered library, but it seems to be unmaintained. Some might even call it over-engineered, however it is a very good library.
Patchlevel Event Sourcing
A library that is very tightly coupled with Symfony and Doctrine. It has a lot of dependencies and is not as flexible as the other libraries.
License
Copyright Florian Krämer
Licensed under the MIT license.