PHPackages                             syeedalireza/laravel-eventsource - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. syeedalireza/laravel-eventsource

ActiveLibrary[Framework](/categories/framework)

syeedalireza/laravel-eventsource
================================

Enterprise-grade Event Sourcing and CQRS implementation for Laravel. Build scalable, auditable applications with complete event history and temporal queries.

v1.0.0(3mo ago)00MITPHPPHP ^8.1|^8.2|^8.3CI failing

Since Jan 30Pushed 3mo agoCompare

[ Source](https://github.com/syeedalireza/laravel-eventsource)[ Packagist](https://packagist.org/packages/syeedalireza/laravel-eventsource)[ RSS](/packages/syeedalireza-laravel-eventsource/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (12)Versions (2)Used By (0)

Laravel EventSource
===================

[](#laravel-eventsource)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b4e5ce77526f2c16f3385660ccea287029e2c0252de8db0cfe343c387334e27f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7379656564616c6972657a612f6c61726176656c2d6576656e74736f757263652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/syeedalireza/laravel-eventsource)[![Total Downloads](https://camo.githubusercontent.com/09582062fe94e4f6571ba511c19972a71f03abbe9312ab7072d7eaa4bd617e0b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7379656564616c6972657a612f6c61726176656c2d6576656e74736f757263652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/syeedalireza/laravel-eventsource)[![GitHub Tests Action Status](https://camo.githubusercontent.com/cbf0ce29323206934e4745fc26eda7a4e5d1cf840eff1cb98efaf1371dd6c4c3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7379656564616c6972657a612f6c61726176656c2d6576656e74736f757263652f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/syeedalireza/laravel-eventsource/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/16380324feb438a876559dee082e29f0fe12f99c6c9e62684709251a05b20890/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7379656564616c6972657a612f6c61726176656c2d6576656e74736f757263652f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/syeedalireza/laravel-eventsource/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![License](https://camo.githubusercontent.com/2a070de7b0cc271ae9afc67972b53bf50789387ad16d5f77e1b940ee30f581bd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7379656564616c6972657a612f6c61726176656c2d6576656e74736f757263652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/syeedalireza/laravel-eventsource)

**Enterprise-grade Event Sourcing and CQRS implementation for Laravel.**

Build scalable, auditable applications with complete event history, temporal queries, and event-driven architecture. This package provides a production-ready implementation of Event Sourcing patterns with full CQRS support, projections, and snapshots.

🚀 Features
----------

[](#-features)

- **Complete Event Store**: Persist all domain events with full replay capability
- **CQRS Pattern**: Separate command and query responsibilities
- **Aggregate Root**: Build aggregates that maintain consistency boundaries
- **Projections**: Build read models from event streams
- **Snapshots**: Optimize aggregate reconstruction with automatic snapshots
- **Temporal Queries**: Query your data at any point in time
- **Multiple Storage Drivers**: PostgreSQL, MySQL, MongoDB support
- **Event Versioning**: Handle event schema evolution gracefully
- **Async Projections**: Process events asynchronously with Laravel Queue
- **Event Replay**: Rebuild projections from scratch
- **Testing Helpers**: Comprehensive testing utilities

📋 Requirements
--------------

[](#-requirements)

- PHP 8.1 or higher
- Laravel 10.0 or higher
- PostgreSQL 12+ / MySQL 8.0+ / MongoDB 5.0+

📦 Installation
--------------

[](#-installation)

You can install the package via composer:

```
composer require syeedalireza/laravel-eventsource
```

Publish the configuration file:

```
php artisan vendor:publish --tag=eventsource-config
```

Run the migrations:

```
php artisan migrate
```

🎯 Quick Start
-------------

[](#-quick-start)

### 1. Define Your Events

[](#1-define-your-events)

```
use Syeedalireza\LaravelEventSource\Events\DomainEvent;

class AccountCreated extends DomainEvent
{
    public function __construct(
        public readonly string $accountId,
        public readonly string $ownerName,
        public readonly float $initialBalance
    ) {
        parent::__construct();
    }
}
```

### 2. Create an Aggregate

[](#2-create-an-aggregate)

```
use Syeedalireza\LaravelEventSource\Aggregate\AggregateRoot;

class Account extends AggregateRoot
{
    private string $ownerName;
    private float $balance;

    public static function create(string $accountId, string $ownerName, float $initialBalance): self
    {
        $account = new self($accountId);
        $account->recordThat(new AccountCreated($accountId, $ownerName, $initialBalance));

        return $account;
    }

    protected function applyAccountCreated(AccountCreated $event): void
    {
        $this->ownerName = $event->ownerName;
        $this->balance = $event->initialBalance;
    }

    public function deposit(float $amount): void
    {
        $this->recordThat(new MoneyDeposited($this->aggregateId, $amount));
    }

    protected function applyMoneyDeposited(MoneyDeposited $event): void
    {
        $this->balance += $event->amount;
    }
}
```

### 3. Use the Event Store

[](#3-use-the-event-store)

```
use Syeedalireza\LaravelEventSource\Facades\EventStore;

// Create and save an aggregate
$account = Account::create('acc-123', 'John Doe', 1000.0);
$account->deposit(500.0);

EventStore::save($account);

// Load an aggregate
$account = EventStore::load(Account::class, 'acc-123');

// Get event stream
$events = EventStore::getStream('acc-123');
```

### 4. Create a Projection

[](#4-create-a-projection)

```
use Syeedalireza\LaravelEventSource\Projections\Projector;

class AccountBalanceProjector extends Projector
{
    protected array $handles = [
        AccountCreated::class,
        MoneyDeposited::class,
        MoneyWithdrawn::class,
    ];

    public function onAccountCreated(AccountCreated $event): void
    {
        DB::table('account_balances')->insert([
            'account_id' => $event->accountId,
            'owner_name' => $event->ownerName,
            'balance' => $event->initialBalance,
            'created_at' => $event->occurredAt,
        ]);
    }

    public function onMoneyDeposited(MoneyDeposited $event): void
    {
        DB::table('account_balances')
            ->where('account_id', $event->accountId)
            ->increment('balance', $event->amount);
    }
}
```

📖 Advanced Usage
----------------

[](#-advanced-usage)

### Snapshots

[](#snapshots)

Enable automatic snapshots for faster aggregate reconstruction:

```
use Syeedalireza\LaravelEventSource\Contracts\Snapshotable;

class Account extends AggregateRoot implements Snapshotable
{
    public function createSnapshot(): array
    {
        return [
            'owner_name' => $this->ownerName,
            'balance' => $this->balance,
        ];
    }

    public static function restoreFromSnapshot(string $aggregateId, array $state, int $version): self
    {
        $account = new self($aggregateId);
        $account->ownerName = $state['owner_name'];
        $account->balance = $state['balance'];
        $account->version = $version;

        return $account;
    }
}
```

### Temporal Queries

[](#temporal-queries)

Query your data at any point in time:

```
// Get account state at specific date
$account = EventStore::loadAtDate(Account::class, 'acc-123', '2024-01-15');

// Get account state at specific version
$account = EventStore::loadAtVersion(Account::class, 'acc-123', 10);
```

### Event Versioning

[](#event-versioning)

Handle event schema evolution:

```
class AccountCreatedV2 extends DomainEvent
{
    public int $version = 2;

    // Upcaster for old events
    public static function upcast(array $eventData): array
    {
        if ($eventData['version'] === 1) {
            $eventData['currency'] = 'USD'; // Add new field
            $eventData['version'] = 2;
        }

        return $eventData;
    }
}
```

### Async Projections

[](#async-projections)

Process projections asynchronously:

```
// In config/eventsource.php
'projections' => [
    'mode' => 'async', // or 'sync'
],

// Your projection will automatically be queued
```

🧪 Testing
---------

[](#-testing)

```
composer test
```

Run with coverage:

```
composer test-coverage
```

Static analysis:

```
composer analyse
```

Code formatting:

```
composer format
```

📚 Documentation
---------------

[](#-documentation)

For complete documentation, visit

🔧 Configuration
---------------

[](#-configuration)

The configuration file `config/eventsource.php` allows you to customize:

- Event store driver (PostgreSQL, MySQL, MongoDB)
- Snapshot settings and frequency
- Projection mode (sync/async)
- Event serialization
- And more...

🤝 Contributing
--------------

[](#-contributing)

Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

🔒 Security
----------

[](#-security)

If you discover any security-related issues, please email  instead of using the issue tracker.

📝 License
---------

[](#-license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

🙏 Credits
---------

[](#-credits)

- [Your Name](https://github.com/yourname)
- [All Contributors](../../contributors)

📖 Learn More
------------

[](#-learn-more)

- [Event Sourcing Pattern](https://martinfowler.com/eaaDev/EventSourcing.html)
- [CQRS Pattern](https://martinfowler.com/bliki/CQRS.html)
- [Domain-Driven Design](https://domainlanguage.com/ddd/)

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance81

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

102d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/05de5f56c8b265c6720d5a4593d499a06c5a32b7ed2b7c36e0ac73778f09a381?d=identicon)[syeedalireza](/maintainers/syeedalireza)

---

Tags

laravelDomain Driven Designdddevent sourcingevent storecqrsprojectionsnapshotsaggregatetemporal-query

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/syeedalireza-laravel-eventsource/health.svg)

```
[![Health](https://phpackages.com/badges/syeedalireza-laravel-eventsource/health.svg)](https://phpackages.com/packages/syeedalireza-laravel-eventsource)
```

###  Alternatives

[laravel/horizon

Dashboard and code-driven configuration for Laravel queues.

4.2k84.2M225](/packages/laravel-horizon)[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k85.0M532](/packages/laravel-passport)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k25.9M107](/packages/laravel-cashier)[laravel/scout

Laravel Scout provides a driver based solution to searching your Eloquent models.

1.7k49.4M479](/packages/laravel-scout)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[broadway/broadway

Infrastructure and testing helpers for creating CQRS and event sourced applications.

1.5k2.0M53](/packages/broadway-broadway)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
