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

Ddd Laravel Package

pccomponentes/ddd

Mini framework PHP para construir aplicaciones con DDD + CQRS + Event Sourcing, orientado a la escritura. Propone arquitectura hexagonal (Application/Domain/Infrastructure/EntryPoint/Util) y guía de capas, dependencias y persistencia basada en eventos.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

The pccomponentes/ddd package enforces a strict hexagonal architecture with DDD/CQRS/ES, which aligns well with Laravel applications requiring domain isolation, event-driven workflows, or scalable read/write separation. Key strengths for Laravel integration:

  • Domain Layer Independence: The Domain layer’s agnosticism to Laravel’s Eloquent/Query Builder enables clean separation of business logic, reducing coupling to framework-specific implementations.
  • Event Sourcing (ES) Support: Laravel’s existing event system (e.g., Illuminate\Events\Dispatcher) can integrate with the package’s event-driven domain models, though additional infrastructure (e.g., message queues) is needed for async CQRS.
  • Value Objects (VOs): The package’s VOs (e.g., Uuid, DateTimeValueObject) complement Laravel’s native types (e.g., Carbon, Str::uuid()) while adding DDD-specific constraints (e.g., UTC enforcement, v7 UUIDs).
  • Hexagonal Ports/Adapters: Laravel’s service containers and bindings can map to the package’s EntryPoint layer, though manual wiring may be required for non-standard dependencies (e.g., MongoDB repositories).

Misalignment Risks:

  • Laravel’s Convention Over Configuration: The package’s explicit layering (e.g., Application, Infrastructure) may conflict with Laravel’s monolithic app/ structure. Requires disciplined project organization.
  • CQRS Complexity: Laravel lacks native CQRS support; integrating async read models (e.g., Elasticsearch projections) demands additional tooling (e.g., Laravel Horizon, RabbitMQ).
  • Event Sourcing Overhead: Laravel’s ORM (Eloquent) is optimized for CRUD, not ES. Migrating to ES requires rewriting persistence logic (e.g., replacing Model::create() with event appenders).

Integration Feasibility

  • Stack Fit:
    • PHP/Laravel: Native compatibility; the package is PHP 8+ and uses Laravel-compatible PSR standards (e.g., containers, events).
    • Databases: Supports MySQL/PostgreSQL/MongoDB via custom repositories, but Laravel’s Eloquent may need replacement for ES tables.
    • Messaging: Requires external queues (e.g., RabbitMQ, Laravel Queues) for async CQRS; no built-in Laravel integration.
  • Migration Path:
    1. Incremental Adoption: Start with the Domain layer (e.g., replace Eloquent models with DDD entities), then extend to Application/Infrastructure.
    2. Hybrid Architecture: Use the package for new features while keeping legacy Laravel code for existing modules.
    3. Event Infrastructure: Add a message broker (e.g., Laravel Horizon + Redis) to handle async event publishing/consumption.
  • Compatibility:
    • Laravel Services: The package’s EntryPoint can wrap Laravel’s HTTP controllers (e.g., Route::post('/orders', OrderController::class)) via dependency injection.
    • Testing: Laravel’s testing tools (e.g., HTTP tests, mocks) work with the Application layer but may need adjustments for domain-specific assertions.
    • UUID v7: Laravel’s Str::uuid() can be replaced with Uuid::create() (v7) or Uuid::v4() for backward compatibility.
  • Sequencing:
    • Phase 1: Refactor a single domain (e.g., Order) to use DDD entities/VOs, keeping Laravel’s Eloquent for persistence.
    • Phase 2: Implement ES by replacing Eloquent with custom repositories that append events to a events table.
    • Phase 3: Add CQRS by introducing read models (e.g., MongoDB) and async event consumers (e.g., Laravel Queues).

Technical Risk

  • Domain Complexity:
    • Risk: Over-engineering for simple CRUD apps. DDD/ES adds layers of abstraction that may not justify the effort for low-complexity domains.
    • Mitigation: Reserve the package for core domains (e.g., payments, inventory) and use Laravel’s native features for peripheral modules.
  • Performance:
    • Risk: Event sourcing can increase read latency due to projection lag (e.g., CQRS consistency eventuality). Laravel’s synchronous ORM may not scale for high-throughput write systems.
    • Mitigation: Benchmark event append/read performance and use Laravel’s queue workers to offload projections.
  • Tooling Gaps:
    • Risk: Lack of Laravel-specific utilities (e.g., Eloquent event sourcing adapters, CQRS scaffolding).
    • Mitigation: Build custom Laravel service providers to bridge gaps (e.g., EventSourcingServiceProvider for event storage).
  • Debugging:
    • Risk: Time-ordered UUIDs (v7) may expose clock skew in distributed Laravel deployments (e.g., multi-AZ setups).
    • Mitigation: Use NTP-synchronized servers and validate UUID generation in CI/CD.
  • Team Ramp-Up:
    • Risk: Steep learning curve for DDD/ES patterns, especially for Laravel developers accustomed to Eloquent.
    • Mitigation: Conduct workshops on hexagonal architecture and provide code templates for common Laravel integrations (e.g., DDD controllers, ES repositories).

Key Questions

  1. Domain Suitability:
    • Which Laravel modules are complex enough to benefit from DDD/ES (e.g., >50% of business logic is domain-specific)?
    • Are there existing event-driven workflows (e.g., order processing) that could leverage ES?
  2. Architecture Tradeoffs:
    • Is the team willing to abandon Eloquent for ES repositories, or will a hybrid approach (e.g., ES for writes, Eloquent for reads) suffice?
    • How will database migrations handle the transition from CRUD to ES tables (e.g., backfilling event streams)?
  3. Operational Impact:
    • What monitoring is needed for CQRS consistency (e.g., tracking projection lag, event failures)?
    • How will rollbacks work if a domain event is corrupted (e.g., replaying events from a snapshot)?
  4. Laravel-Specific:
    • Can Laravel’s service container manage the package’s dependencies (e.g., repositories, event buses) without manual wiring?
    • How will Laravel’s caching (e.g., Redis) interact with event-sourced read models?
  5. Long-Term Viability:
    • Is the package’s MIT license acceptable, or are there concerns about vendor lock-in?
    • Are there plans to extend the package (e.g., Laravel-specific adapters, CQRS tools) based on community feedback?

Integration Approach

Stack Fit

  • Laravel Core:
    • Service Container: The package’s EntryPoint layer can integrate with Laravel’s container via bindings (e.g., bind('App\Domain\Repository\OrderRepository', fn() => new MongoOrderRepository())).
    • HTTP Layer: Laravel’s controllers can delegate to Application layer handlers (e.g., public function store(OrderCreateRequest $request, OrderCreateHandler $handler)).
    • Events: Laravel’s event system can publish domain events (e.g., event(new OrderCreated($orderId))), which the package’s infrastructure can consume.
  • Database:
    • Write Side: Replace Eloquent models with ES repositories (e.g., EventStoreRepository) that append to an events table with columns: aggregate_id, event_type, payload, occurred_at.
    • Read Side: Use Laravel’s query builder or a dedicated read model (e.g., MongoDB) for projections, updated via Laravel Queues.
  • Messaging:
    • Async CQRS: Use Laravel Queues (e.g., queue:work) to process events and update read models. For advanced use, integrate RabbitMQ via libraries like php-amqplib.
    • Event Bus: The package’s event bus can be mapped to Laravel’s event dispatcher or a custom queue-based bus.
  • Testing:
    • Unit Tests: Mock the Domain layer and test Application handlers with Laravel’s Mockery.
    • Feature Tests: Use Laravel’s HTTP tests to validate EntryPoint behavior (e.g., API responses).
    • ES Tests: Write tests to verify event replay and projection consistency.

Migration Path

  1. Assessment Phase:
    • Audit Laravel modules to identify core domains suitable for DDD/ES.
    • Benchmark current write/read performance to justify ES overhead.
  2. Pilot Phase:
    • Step 1: Refactor a single domain (e.g., User) to use the package’s VOs (e.g., Uuid, EmailValueObject) and entities.
      • Replace Eloquent models with DDD entities (e.g., UserEntity with UserId, UserEmail VOs).
      • Keep persistence in Eloquent for simplicity.
    • Step 2: Implement ES for the domain by creating an events table and a custom repository.
      • Use Laravel migrations to add the `events
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.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity