This project demonstrates:
- How to integrate Filament PHP (admin panel) with Verbs (event sourcing package)
- Implementation of a simple Todo application that uses event sourcing
- Complete event history stored in
verb_events
table - Ability to rebuild application state from events using
php artisan verbs:replay
- Practical example of event sourcing benefits (auditability, time-travel debugging, resilience)
- Filament PHP with Verbs: Event Sourcing in Laravel
This repository demonstrates the integration of Filament PHP (a powerful admin panel framework) with Verbs (an event sourcing package for Laravel) through a Todo application example. This project showcases how to implement event sourcing principles in a Laravel application with a beautiful admin interface.
Event sourcing is an architectural pattern that stores all changes to an application's state as a sequence of events. Instead of just storing the current state, it maintains a complete history of all actions that led to the current state. This provides:
- Complete audit trail of all system changes
- Ability to rebuild the system state at any point in time
- Enhanced debugging capabilities
- Resilience to schema changes
Follow these steps to set up the project:
-
Clone the repository:
git clone https://github.com/tisuchi/filament-with-verbs.git
-
Navigate to the project directory:
cd filament-with-verbs
-
Set up the environment:
cp .env.example .env php artisan key:generate
-
Set up the database and seed initial data:
php artisan migrate:fresh --seed
-
Start the development server:
php artisan serve
-
Access the application at http://localhost:8000
Access the admin panel at http://localhost:8000/admin with these credentials:
Credential | Value |
---|---|
user@example.com |
|
Password | password |
The dashboard provides an overview of the application:
The Todo section allows you to create, update, and manage your tasks:
The Verbs package implements event sourcing by creating three additional tables alongside your domain tables:
Stores all events that occur in the system. Each row represents a single event (like TodoCreated, TodoCompleted, etc.) with its data payload.
Contains point-in-time snapshots of entity states to optimize rebuilding state from events. This prevents having to replay all events from the beginning.
Links events to the specific entities they affect, creating a relationship between states and their events.
The actual domain table that stores the current state of todo items. This is derived from applying all events.
One of the powerful features of event sourcing is the ability to replay events to rebuild state. Here's how to demonstrate this:
-
First, clear the current state by truncating the
todos
table (this simulates data loss in the domain table) -
Run the replay command to rebuild the state from events:
php artisan verbs:replay
-
Confirm that you want to run all events:
-
Successful replay notification:
-
Verify that the
todos
table has been fully reconstructed with exactly the same data that was there before:
This demonstrates the power of event sourcing - even if you lose your entire domain table, you can rebuild it completely from the stored events!
When you interact with the Todo items through the Filament interface:
- Actions like creating or updating trigger events
- These events are stored in the
verb_events
table - The events are then applied to update the current state in the
todos
table - Periodically, snapshots are created for performance optimization
I welcome your questions, feedback, and contributions to this project! Feel free to open issues or pull requests to improve this demonstration.
Thank you for exploring this integration of Filament PHP with Verbs event sourcing.