PHPackages                             solidframe/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. solidframe/cqrs

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

solidframe/cqrs
===============

CQRS building blocks: Command, Query, Handlers, and Bus implementations for SolidFrame

v0.1.0(3mo ago)06MITPHPPHP ^8.2

Since Apr 11Pushed 3mo agoCompare

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

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

SolidFrame CQRS
===============

[](#solidframe-cqrs)

Command Query Responsibility Segregation: CommandBus, QueryBus, Handlers, and Middleware.

Commands produce side effects and return nothing. Queries return data and produce no side effects.

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

[](#installation)

```
composer require solidframe/cqrs
```

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

[](#quick-start)

### Define a Command and Handler

[](#define-a-command-and-handler)

```
use SolidFrame\Cqrs\Command;
use SolidFrame\Cqrs\CommandHandler;

final readonly class PlaceOrder implements Command
{
    public function __construct(
        public string $orderId,
        public string $customerId,
    ) {}
}

final readonly class PlaceOrderHandler implements CommandHandler
{
    public function __construct(private OrderRepository $orders) {}

    public function __invoke(PlaceOrder $command): void
    {
        $order = Order::place(
            new OrderId($command->orderId),
            new CustomerId($command->customerId),
        );

        $this->orders->save($order);
    }
}
```

### Define a Query and Handler

[](#define-a-query-and-handler)

```
use SolidFrame\Cqrs\Query;
use SolidFrame\Cqrs\QueryHandler;

final readonly class GetOrderById implements Query
{
    public function __construct(public string $orderId) {}
}

final readonly class GetOrderByIdHandler implements QueryHandler
{
    public function __construct(private OrderRepository $orders) {}

    public function __invoke(GetOrderById $query): ?OrderDto
    {
        $order = $this->orders->find(new OrderId($query->orderId));

        return $order ? OrderDto::fromEntity($order) : null;
    }
}
```

### Dispatch

[](#dispatch)

```
// Command — fire and forget
$commandBus->dispatch(new PlaceOrder(
    orderId: 'order-123',
    customerId: 'customer-456',
));

// Query — get result
$order = $queryBus->ask(new GetOrderById(orderId: 'order-123'));
```

Standalone Usage
----------------

[](#standalone-usage)

Without a framework bridge, wire the bus manually:

```
use SolidFrame\Cqrs\Handler\InMemoryHandlerResolver;
use SolidFrame\Cqrs\Bus\CommandBus;
use SolidFrame\Cqrs\Bus\QueryBus;

$resolver = new InMemoryHandlerResolver();
$resolver->register(PlaceOrder::class, new PlaceOrderHandler($orders));

$commandBus = new CommandBus($resolver);
$commandBus->dispatch(new PlaceOrder('order-123', 'customer-456'));
```

Middleware
----------

[](#middleware)

Add cross-cutting concerns to bus processing.

```
use SolidFrame\Core\Middleware\MiddlewareInterface;

final readonly class TransactionMiddleware implements MiddlewareInterface
{
    public function __construct(private Connection $connection) {}

    public function handle(object $message, callable $next): mixed
    {
        $this->connection->beginTransaction();

        try {
            $result = $next($message);
            $this->connection->commit();

            return $result;
        } catch (\Throwable $e) {
            $this->connection->rollBack();
            throw $e;
        }
    }
}

// With middleware
$commandBus = new CommandBus($resolver, [
    new TransactionMiddleware($connection),
    new LoggingMiddleware($logger),
]);
```

Middleware executes in registration order. Each middleware calls `$next($message)` to pass to the next one.

Handler Resolution
------------------

[](#handler-resolution)

Handlers are resolved by the message type passed to `__invoke()`. The convention:

- `PlaceOrder` command → `PlaceOrderHandler::__invoke(PlaceOrder $command)`
- `GetOrderById` query → `GetOrderByIdHandler::__invoke(GetOrderById $query)`

One handler per command/query. Multiple handlers for the same message type will throw an exception.

API Reference
-------------

[](#api-reference)

Class / InterfacePurpose`Command`Marker interface for commands`Query`Marker interface for queries`CommandHandler`Marker interface for command handlers`QueryHandler`Marker interface for query handlers`CommandBus`Dispatches commands through middleware to handlers`QueryBus`Dispatches queries through middleware to handlers`MessageBus`Abstract base for both buses`HandlerResolverInterface`Contract for resolving handlers`InMemoryHandlerResolver`In-memory handler registry`HandlerNotFoundException`Thrown when no handler matchesRelated Packages
----------------

[](#related-packages)

- [solidframe/core](../core) — Bus interfaces, Middleware contract
- [solidframe/ddd](../ddd) — Entities and aggregates your handlers operate on
- [solidframe/event-driven](../event-driven) — Dispatch domain events after commands
- [solidframe/laravel](../laravel) — Auto-discovery, DI, `make:cqrs-command`, `make:query`
- [solidframe/symfony](../symfony) — Compiler pass, DI, same generators

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

[](#contributing)

This repository is a read-only split of the [solidframe/solidframe](https://github.com/solidframe/solidframe) monorepo, auto-synced on every push to `main`. Issues, pull requests, and discussions belong in the monorepo.

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance81

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

104d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/97de2a466719393a21a8ce5caef247a1afb8aec5a8974248da0583f4197765b2?d=identicon)[abdulkadir-posul](/maintainers/abdulkadir-posul)

---

Top Contributors

[![abdulkadir-posul](https://avatars.githubusercontent.com/u/88670954?v=4)](https://github.com/abdulkadir-posul "abdulkadir-posul (1 commits)")

### Embed Badge

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

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

###  Alternatives

[frosh/product-compare

A Simple Product Compare plugin for Shopware 6

4039.2k](/packages/frosh-product-compare)[georgeboot/laravel-tiptap

Opinionated integration of Tiptap editor using the TALL stack

346.4k](/packages/georgeboot-laravel-tiptap)

PHPackages © 2026

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