PHPackages                             ignaciocastro0713/cqbus-mediator - 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. ignaciocastro0713/cqbus-mediator

ActiveLibrary[Framework](/categories/framework)

ignaciocastro0713/cqbus-mediator
================================

A modern CQRS Mediator for Laravel using PHP 8 Attributes, auto-discovery, and routing pipelines.

v7.0.1(2mo ago)491MITPHPPHP ^8.2CI passing

Since Jul 21Pushed 2mo agoCompare

[ Source](https://github.com/IgnacioCastro0713/cqbus-mediator)[ Packagist](https://packagist.org/packages/ignaciocastro0713/cqbus-mediator)[ Docs](https://github.com/IgnacioCastro0713/cqbus-mediator)[ RSS](/packages/ignaciocastro0713-cqbus-mediator/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (39)Versions (54)Used By (0)

[![](https://camo.githubusercontent.com/3a39b8d0fbca7437152a8fca9e26e11f60076732180e3708fa837e02f9ce897d/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f43514275732532304d65646961746f72253230666f722532304c61726176656c2e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d69676e6163696f63617374726f3037313325324663716275732d6d65646961746f72267061747465726e3d617263686974656374267374796c653d7374796c655f31266465736372697074696f6e3d435152532b4d65646961746f722b696d706c656d656e746174696f6e2b666f722b4c61726176656c266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)](https://camo.githubusercontent.com/3a39b8d0fbca7437152a8fca9e26e11f60076732180e3708fa837e02f9ce897d/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f43514275732532304d65646961746f72253230666f722532304c61726176656c2e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d69676e6163696f63617374726f3037313325324663716275732d6d65646961746f72267061747465726e3d617263686974656374267374796c653d7374796c655f31266465736372697074696f6e3d435152532b4d65646961746f722b696d706c656d656e746174696f6e2b666f722b4c61726176656c266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)

[![run-tests](https://github.com/ignaciocastro0713/cqbus-mediator/actions/workflows/run-tests.yml/badge.svg)](https://github.com/ignaciocastro0713/cqbus-mediator/actions/workflows/run-tests.yml)[![PHPStan](https://github.com/ignaciocastro0713/cqbus-mediator/actions/workflows/phpstan.yml/badge.svg)](https://github.com/ignaciocastro0713/cqbus-mediator/actions/workflows/phpstan.yml)[![codecov](https://camo.githubusercontent.com/4766d71dcd0b066611f72e63ca90fcda1092c199f18f1d8b8f0f47759ba5dbf9/68747470733a2f2f636f6465636f762e696f2f67682f69676e6163696f63617374726f303731332f63716275732d6d65646961746f722f67726170682f62616467652e737667)](https://codecov.io/gh/ignaciocastro0713/cqbus-mediator)[![Documentation](https://camo.githubusercontent.com/3355a7f5e7f2ebde9f8a5fc59aa83fff56866486876bfd5b96f07c57ffe24e5c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f63732d76372e302e782d7265642e7376673f7374796c653d666c61742d737175617265)](https://ignaciocastro0713.github.io/cqbus-mediator/7.0/installation.html)[![](https://camo.githubusercontent.com/a9d5a42445b3aa0454b26f10a9105d524595663d09b87ce43810181834a83e06/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f69676e6163696f63617374726f303731332f63716275732d6d65646961746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ignaciocastro0713/cqbus-mediator)[![](https://camo.githubusercontent.com/5da79bdef276749d74ce210387cb4990223cd7167bd59f59637b9c77a752be20/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f69676e6163696f63617374726f303731332f63716275732d6d65646961746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ignaciocastro0713/cqbus-mediator)[![](https://camo.githubusercontent.com/b501c420cfdeea54cc2375176ec3b5acb8a171964c59fb65175ce57f4df4c4f3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f69676e6163696f63617374726f303731332f63716275732d6d65646961746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ignaciocastro0713/cqbus-mediator)

### A zero-configuration Command/Query Bus for Laravel

[](#a-zero-configuration-commandquery-bus-for-laravel)

Decouple your controllers from business logic using the **Mediator pattern (CQRS)** and **PHP 8 Attributes** — with zero boilerplate.

**[📖 Read the Documentation](https://ignaciocastro0713.github.io/cqbus-mediator/)**

---

The Problem
-----------

[](#the-problem)

Controllers that mix HTTP, business logic, and side effects are hard to test and maintain.

❌ Before — everything tangled in one place✅ After — each concern in its own place```
class UserController extends Controller
{
    public function register(Request $request)
    {
        $request->validate([
            'email' => 'required|email',
            'password' => 'required',
        ]);

        DB::beginTransaction();
        try {
            $user = User::create($request->all());
            Mail::to($user)->send(new WelcomeEmail());
            Log::info("User registered");
            DB::commit();
            return response()->json($user, 201);
        } catch (\Exception $e) {
            DB::rollBack();
            throw $e;
        }
    }
}
```

```
#[Api]
class RegisterUserAction
{
    use AsAction;

    public function __construct(
        private readonly Mediator $mediator
    ) {}

    public static function route(Router $router): void
    {
        $router->post('/register');
    }

    public function handle(RegisterUserRequest $request): JsonResponse
    {
        // Handler runs the logic
        $user = $this->mediator->send($request);

        // Notifications handle side effects
        $this->mediator->publish(new UserRegisteredEvent($user));

        return response()->json($user, 201);
    }
}
```

---

Features
--------

[](#features)

**⚡ Zero Config**Handlers are auto-discovered via `#[RequestHandler]` and `#[Notification]` attributes. No registration needed.

**📢 Event Bus**Publish events to multiple notification handlers, with priority control over execution order.

**🎮 Attribute Routing**Define routes directly on Action classes with `#[Api]`, `#[Prefix]`, `#[Middleware]`, and more.

**🔗 Pipelines**Apply middleware-like logic (transactions, logging) globally or per-handler via `#[Pipeline]`.

**🧪 Testing Fakes**Assert dispatched requests without executing business logic — built-in, no setup required.

**🚀 Production Cache**Eliminate discovery overhead (~2,500x faster boot) with `php artisan mediator:cache`.

---

Installation
------------

[](#installation)

```
composer require ignaciocastro0713/cqbus-mediator
```

The package is auto-discovered. Optionally publish the config file:

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

---

Quick Start
-----------

[](#quick-start)

The package supports two patterns:

PatternMethodDirectionUse for**Command / Query**`send()`1-to-1Business logic that reads or writes**Event Bus**`publish()`1-to-NSide effects (emails, logs, etc.)**1. Scaffold your classes**

```
php artisan make:mediator-handler RegisterUserHandler --action
```

Generates `RegisterUserRequest`, `RegisterUserHandler`, and `RegisterUserAction` in one go.

**2. Write your Handler**

```
#[RequestHandler(RegisterUserRequest::class)]
class RegisterUserHandler
{
    public function handle(RegisterUserRequest $request): User
    {
        return User::create($request->validated());
    }
}
```

**3. Dispatch from your Action**

```
$user = $this->mediator->send($request);
```

The Mediator discovers and routes to the correct handler automatically.

---

Documentation
-------------

[](#documentation)

[📦 Installation](https://ignaciocastro0713.github.io/cqbus-mediator/7.0/installation.html)[🧠 Core Concepts](https://ignaciocastro0713.github.io/cqbus-mediator/7.0/concepts.html)[⚡ Commands &amp; Queries](https://ignaciocastro0713.github.io/cqbus-mediator/7.0/commands.html)[📢 Event Bus](https://ignaciocastro0713.github.io/cqbus-mediator/7.0/events.html)[🎮 Routing &amp; Actions](https://ignaciocastro0713.github.io/cqbus-mediator/7.0/actions.html)[🔗 Pipelines](https://ignaciocastro0713.github.io/cqbus-mediator/7.0/pipelines.html)[🧪 Testing](https://ignaciocastro0713.github.io/cqbus-mediator/7.0/testing.html)[📋 Console Commands](https://ignaciocastro0713.github.io/cqbus-mediator/7.0/console.html)[🚀 Production &amp; Performance](https://ignaciocastro0713.github.io/cqbus-mediator/7.0/performance.html)---

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 11.0+

---

Contributing
------------

[](#contributing)

Feel free to open issues or submit pull requests on the [GitHub repository](https://github.com/IgnacioCastro0713/cqbus-mediator).

License
-------

[](#license)

This package is open-sourced software licensed under the MIT license.

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance86

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 61.8% of commits — single point of failure

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

Every ~6 days

Recently: every ~13 days

Total

47

Last Release

73d ago

Major Versions

v2.4.1 → v3.0.02026-02-22

v3.1.0 → v4.0.02026-02-22

v4.1.0 → v5.0.02026-02-24

v5.4.1 → v6.0.02026-02-28

v6.2.0 → v7.0.02026-04-20

PHP version history (2 changes)v1.0.0PHP ^8.1

v4.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/f52b8af2238b71a28e08ef016307e3ae955d3ff7f44b40285a7e207b4fe7ac6b?d=identicon)[IgnacioCastro0713](/maintainers/IgnacioCastro0713)

---

Top Contributors

[![IgnacioCastro0713](https://avatars.githubusercontent.com/u/31707457?v=4)](https://github.com/IgnacioCastro0713 "IgnacioCastro0713 (128 commits)")[![IgnacioMenchaca666](https://avatars.githubusercontent.com/u/26027767?v=4)](https://github.com/IgnacioMenchaca666 "IgnacioMenchaca666 (74 commits)")[![claude](https://avatars.githubusercontent.com/u/81847?v=4)](https://github.com/claude "claude (5 commits)")

---

Tags

commandcqrslaravelmediatormediatrphpquerylaravelroutingattributescommand busevent buscqrsactionmediator

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ignaciocastro0713-cqbus-mediator/health.svg)

```
[![Health](https://phpackages.com/badges/ignaciocastro0713-cqbus-mediator/health.svg)](https://phpackages.com/packages/ignaciocastro0713-cqbus-mediator)
```

###  Alternatives

[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M201](/packages/laravel-ai)[laravel/folio

Page based routing for Laravel.

603583.7k33](/packages/laravel-folio)[illuminate/queue

The Illuminate Queue package.

21332.6M1.6k](/packages/illuminate-queue)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[illuminate/routing

The Illuminate Routing package.

1419.2M3.0k](/packages/illuminate-routing)[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.5k55.4M8.5k](/packages/larastan-larastan)

PHPackages © 2026

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