A Command Bus implementation with middleware pipeline, query caching, and retry support for Laravel

Maintainers

Package info

github.com/HassanElZarkawy/nactu

pkg:composer/hassanelzarkawy/nactu

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.0.1 2026-05-26 14:23 UTC

This package is auto-updated.

Last update: 2026-05-31 18:26:21 UTC


README

A lightweight CQRS package for Laravel with command/query bus, middleware pipeline, query caching, and retry support.

Requirements

  • PHP 8.4+
  • Laravel 11+

Installation

composer require hassanelzarkawy/nactu

Publish the config file:

php artisan vendor:publish --tag=nactu-config

Quick Start

Commands (Write)

Create a command and its handler:

php artisan make:command CreateUser

This generates:

  • App\Commands\CreateUserCommand
  • App\Handlers\CreateUserHandler

Dispatch it:

use Nactu\CommandBusInterface;

public function store(CommandBusInterface $bus): void
{
    $bus->dispatch(new CreateUserCommand(
        name: 'Hassan',
        email: 'hassan@example.com',
    ));
}

Queries (Read)

Create a query and its handler:

php artisan make:query ListUsers

This generates:

  • App\Queries\ListUsersQuery
  • App\QueryHandlers\ListUsersHandler

Dispatch it:

use Nactu\QueryBusInterface;

public function index(QueryBusInterface $bus): JsonResponse
{
    $users = $bus->dispatch(new ListUsersQuery(
        status: 'active',
    ));

    return response()->json($users);
}

Documentation

How It Works

CommandBus (writes)          QueryBus (reads)
     │                            │
     ├─ Retry Middleware          ├─ Cache Middleware
     ├─ Performance Monitor       ├─ Performance Monitor
     │                            │
     └─► Handler                  └─► Handler

Commands and queries have separate middleware stacks. Commands get retry support, queries get caching — no overlap.

License

MIT