Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Cqrs Php Laravel Package

black/cqrs-php

Minimal CQRS command bus for PHP/DDD without event sourcing. Define Command and CommandHandler, register handlers to commands, then dispatch via a single Bus. Includes optional Symfony bundle integration with service tags for handler registration.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • CQRS Alignment: The package provides a lightweight CQRS implementation tailored for Domain-Driven Design (DDD) in PHP, aligning well with architectures requiring separation of read/write models (e.g., microservices, layered applications).
  • Event Sourcing Absence: Explicitly excludes Event Sourcing, which may limit use cases requiring auditability, replayability, or eventual consistency but simplifies adoption for command-only workflows.
  • Symfony Integration: Offers a Symfony Bundle, reducing boilerplate for Symfony-based projects but introducing framework lock-in if migrating away from Symfony later.
  • DDD-First Design: Encourages explicit command/handler separation, improving testability and modularity but requiring discipline to avoid mixing concerns.

Integration Feasibility

  • Low-Coupling: Minimal dependencies (only PHP ≥5.4), making it easy to integrate into existing Laravel/PHP projects without major refactoring.
  • Laravel Compatibility:
    • No native Laravel support (unlike Symfony), requiring manual DI setup (e.g., Laravel’s ServiceProvider or bind()).
    • Middleware/Events: No built-in support for Laravel’s event system, necessitating custom adapters if leveraging Laravel’s ecosystem.
  • Database Agnostic: No ORM/DB assumptions, but read models must be manually implemented (e.g., via Eloquent or raw queries).

Technical Risk

  • Archived Status: No active maintenance (archived repo) introduces long-term risk (e.g., PHP 8+ compatibility, security patches).
  • Limited Features:
    • No query handling (pure CQRS requires separate read models; this package only handles commands).
    • No transaction management or distributed bus support (e.g., RabbitMQ, Kafka).
  • Error Handling: Basic exception handling; custom error strategies (e.g., retries, dead-letter queues) must be implemented manually.
  • Performance: Synchronous bus may bottleneck under high load; asynchronous alternatives (e.g., Laravel Queues) would need integration.

Key Questions

  1. Why CQRS?
    • Is the goal simpler command processing (e.g., workflows, sagas) or full CQRS with queries? If the latter, this package is insufficient.
  2. Symfony Dependency:
    • Is the team using Symfony? If not, the bundle adds unnecessary complexity.
  3. Alternatives:
    • Would Laravel’s built-in command bus (via Artisan::command()) or third-party packages (e.g., spatie/laravel-command-bus) suffice?
  4. Long-Term Viability:
    • Can the team maintain/commit to this package despite its archived state?
  5. Read Models:
    • How will query-side logic (e.g., API responses, reports) be implemented without this package’s support?

Integration Approach

Stack Fit

  • Laravel Compatibility:
    • Pros: Lightweight, no heavy dependencies. Can be integrated via ServiceProvider or manual DI.
    • Cons: No native Laravel hooks (e.g., boot() for event listeners, handle() for middleware).
  • Alternative Patterns:
    • Laravel Commands: Replace with Artisan::command() for simpler use cases.
    • Laravel Events: Use Laravel’s event system for pub/sub if CQRS is overkill.
  • Symfony Bundle:
    • Only relevant if migrating to Symfony or already using it. Otherwise, avoid to prevent lock-in.

Migration Path

  1. Assess Scope:
    • Audit existing commands/workflows to determine if CQRS adds value (e.g., complex business logic, high write throughput).
  2. Pilot Integration:
    • Start with one command/handler in a non-critical module to test:
      • DI setup (e.g., bind Bus in AppServiceProvider).
      • Error handling (e.g., wrap bus->handle() in try-catch).
  3. Gradual Adoption:
    • Replace direct service calls with command handlers.
    • Implement read models separately (e.g., via repositories or queries).
  4. Laravel-Specific Adaptations:
    • Use Laravel Queues for async command processing.
    • Leverage Laravel’s logging for command tracking.

Compatibility

  • PHP Version: Supports ≥5.4; test compatibility with PHP 8.x (e.g., named arguments, union types).
  • Laravel Version:
    • No version constraints; manual testing required for:
      • Dependency conflicts (e.g., Symfony components if using the bundle).
      • Laravel’s DI container (e.g., binding the Bus as a singleton).
  • Database:
    • No assumptions; ensure read models (e.g., Eloquent) are implemented separately.

Sequencing

  1. Phase 1: Command Layer
    • Implement command/handler pairs for critical workflows.
    • Example:
      // app/Providers/AppServiceProvider.php
      public function register() {
          $this->app->singleton(Black\DDD\CQRSinPHP\Infrastructure\CQRS\Bus::class);
          $bus = $this->app->make(Black\DDD\CQRSinPHP\Infrastructure\CQRS\Bus::class);
          $bus->register(MyCommand::class, new MyHandler());
      }
      
  2. Phase 2: Error Handling
    • Add global exception handling for commands (e.g., log failures, notify admins).
  3. Phase 3: Read Models
    • Decouple query logic from commands (e.g., use repositories or separate services).
  4. Phase 4: Async Processing
    • Integrate with Laravel Queues for background command execution.

Operational Impact

Maintenance

  • Archived Risk:
    • No updates for PHP 8+, security fixes, or feature requests. Fork or abandon if critical.
    • Document customizations (e.g., error handling, async setup) for future maintainers.
  • Dependency Management:
    • Monitor for composer conflicts (e.g., Symfony components if using the bundle).
  • Testing:
    • Write unit tests for handlers and integration tests for command flows.
    • Mock the Bus in tests to isolate command logic.

Support

  • Community:
    • No active support; rely on GitHub issues (if any) or community forks.
    • Consider paid support from the original author (if available).
  • Debugging:
    • Limited tooling: No built-in metrics or observability (e.g., command latency, failure rates).
    • Manual instrumentation required (e.g., log command execution, add tags to Laravel logs).
  • Rollback Plan:
    • Simple to revert: Replace command handlers with direct service calls.
    • Data consistency: Ensure read models are updated if commands modify state.

Scaling

  • Synchronous Bus:
    • Bottleneck risk under high load; offload to queues (e.g., Laravel Horizon).
    • No built-in retries; implement exponential backoff manually.
  • Horizontal Scaling:
    • Stateless commands scale well, but shared state (e.g., DB locks) may require distributed transactions (e.g., Laravel’s database transactions).
  • Performance Tuning:
    • Profile command handlers for slow queries or logic.
    • Cache read models (e.g., Laravel Cache) if queries are expensive.

Failure Modes

Failure Scenario Impact Mitigation
Bus crashes during handling Command lost Use Laravel Queues with retries.
Handler throws unhandled error Silent failure Global exception handler + monitoring.
Database transaction fails Inconsistent state Use Laravel transactions or Sagas.
PHP version incompatibility Package breaks Fork and update dependencies.
No read model updates Stale queries Implement event listeners for state changes.

Ramp-Up

  • Learning Curve:
    • Moderate: Requires understanding of CQRS patterns (commands, handlers, separation of concerns).
    • Documentation: README is basic; expect to reverse-engineer usage from examples.
  • Team Onboarding:
    • Workshops: Teach command/handler design and Laravel integration.
    • Code Reviews: Enforce consistent handler patterns (e.g., input validation, logging).
  • Tooling:
    • IDE Support: Basic (PHPStorm recognizes interfaces).
    • **No CLI
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
craftcms/url-validator
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony