PHPackages                             bowphp/cqrs - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. bowphp/cqrs

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

bowphp/cqrs
===========

Command Query Responsibility Segregation

1.2.2(1y ago)25.2kMITPHPPHP ^8.1CI passing

Since Mar 16Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/bowphp/cqrs)[ Packagist](https://packagist.org/packages/bowphp/cqrs)[ RSS](/packages/bowphp-cqrs/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (5)Dependencies (3)Versions (7)Used By (0)

Bow CQRS
========

[](#bow-cqrs)

CQRS (Command Query Responsibility Segregation). It's a pattern that I first heard described by Greg Young. At its heart is the notion that you can use a different model to update information than the model you use to read information. For some situations, this separation can be valuable but beware that for most systems CQRS adds risky complexity.

[For more information](https://www.martinfowler.com/bliki/CQRS.html)

Install
-------

[](#install)

The package uses php &gt;= 8.1

```
composer require bowphp/cqrs
```

Help
----

[](#help)

First, create the example command:

```
use Bow\CQRS\Command\CommandInterface;

class CreateUserCommand implements CommandInterface
{
    public function __construct(
        public string $username,
        public string $email
    ) {}
}
```

Create the handler here:

```
use Bow\CQRS\Command\CommandHandlerInterface;

class CreateUserCommandHandler implements CommandHandlerInterface
{
    public function __construct(public UserService $userService) {}

    public function process(CommandInterface $command): mixed
    {
        if ($this->userService->exists($command->email)) {
            throw new UserServiceException(
                "The user already exists"
            );
        }

        return $this->userService->create([
            "username" => $command->username,
            "email" => $command->email
        ]);
    }
}
```

Add command to the register in `App\Configurations\ApplicationConfiguration::class`:

```
use Bow\CQRS\Registration as CQRSRegistration;

public function run()
{
    CQRSRegistration::commands([
        CreateUserCommand::class => CreateUserCommandHandler::class
    ]);
}
```

### Attribute-based registration

[](#attribute-based-registration)

You can also map handlers to their commands/queries with PHP attributes instead of manual arrays:

```
use Bow\CQRS\Attribute\CommandHandler;
use Bow\CQRS\Attribute\QueryHandler;
use Bow\CQRS\Command\CommandHandlerInterface;
use Bow\CQRS\Command\CommandInterface;
use Bow\CQRS\Query\QueryHandlerInterface;
use Bow\CQRS\Query\QueryInterface;

#[CommandHandler(CreateUserCommand::class)]
class CreateUserCommandHandler implements CommandHandlerInterface
{
    public function process(CommandInterface $command): mixed
    {
        // create the user...
    }
}

#[QueryHandler(FetchUserQuery::class)]
class FetchUserQueryHandler implements QueryHandlerInterface
{
    public function process(QueryInterface $query): mixed
    {
        // fetch and return the user...
    }
}

// Register handlers once (attributes map them to the right message)
CQRSRegistration::handlers([
    CreateUserCommandHandler::class,
    FetchUserQueryHandler::class,
]);
```

Execute the command in the controller:

```
namespace App\Controllers;

use App\Controllers\Controller;
use App\Commands\CreateUserCommand;

class UserController extends Controller
{
    public function __construct(private CommandBus $commandBus) {}

    public function __invoke(Request $request)
    {
        $payload = $request->only(['username', 'email']);
        $command = new CreateUserCommand(
            $payload['username'],
            $payload['email']
        );

        $result = $this->commandBus->execute($command);

        return redirect()
            ->back()
            ->withFlash("message", "User created");
    }
}
```

Put a new route:

```
$app->post("/users/create", UserController::class);
```

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

[](#contributing)

Thank you for considering contributing to Bow Framework! The contribution guide is in the framework documentation.

- [Franck DAKIA](https://github.com/papac)
- [Thank's collaborators](https://github.com/bowphp/framework/graphs/contributors)

Contact
-------

[](#contact)

 - [@papacdev](https://twitter.com/papacdev)

**Please, if there is a bug in the project. Contact me by email or leave me a message on [slack](https://bowphp.slack.com). or [join us on slack](https://join.slack.com/t/bowphp/shared_invite/enQtNzMxOTQ0MTM2ODM5LTQ3MWQ3Mzc1NDFiNDYxMTAyNzBkNDJlMTgwNDJjM2QyMzA2YTk4NDYyN2NiMzM0YTZmNjU1YjBhNmJjZThiM2Q)**

###  Health Score

43

—

FairBetter than 90% of packages

Maintenance69

Regular maintenance activity

Popularity25

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~168 days

Total

5

Last Release

520d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/96099e66c63e31445f3f76a12e94104030f504eeb18f007216bb4ebdcdeadf7f?d=identicon)[papac](/maintainers/papac)

---

Top Contributors

[![papac](https://avatars.githubusercontent.com/u/9353811?v=4)](https://github.com/papac "papac (42 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/bowphp-cqrs/health.svg)

```
[![Health](https://phpackages.com/badges/bowphp-cqrs/health.svg)](https://phpackages.com/packages/bowphp-cqrs)
```

###  Alternatives

[gburtini/distributions

PHP implementation of a number of statistical probability distributions: normal, beta, gamma, etc.

58517.0k2](/packages/gburtini-distributions)[v17development/flarum-seo

Adds SEO tags for your Flarum forum

4998.7k2](/packages/v17development-flarum-seo)[bowphp/tintin

The very small php Template

1821.7k4](/packages/bowphp-tintin)[revangelista/laravel-idempotency

Laravel Idempotency Middleware

1110.8k](/packages/revangelista-laravel-idempotency)

PHPackages © 2026

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