hassanelzarkawy / nactu
A Command Bus implementation with middleware pipeline, query caching, and retry support for Laravel
0.0.1
2026-05-26 14:23 UTC
Requires
- php: ^8.4
- illuminate/contracts: ^13.11
- illuminate/support: ^13.11
- laravel/framework: ^13.11
Requires (Dev)
- driftingly/rector-laravel: ^2.4
- laravel/pint: ^1.29
- orchestra/testbench: ^11.1
- phpunit/phpunit: ^13.1
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\CreateUserCommandApp\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\ListUsersQueryApp\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
- Commands — Command bus, handlers, and write operations
- Queries — Query bus, cacheable queries, and read operations
- Middleware — Built-in and custom middleware
- Caching — Query caching, cache keys, and invalidation
- Auto-Discovery — Convention-based handler resolution
- Console Commands — Code generation commands
- Configuration — Full config reference
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