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

Hexagonal Maker Bundle Laravel Package

ahmed-bhs/hexagonal-maker-bundle

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Hexagonal Architecture Alignment: The package excels at enforcing Ports & Adapters principles, aligning perfectly with Hexagonal Architecture. It isolates domain logic from frameworks (Symfony, Doctrine) by generating pure PHP domain entities, value objects, and repository interfaces.
  • CQRS Support: Built-in CQRS generators (commands, queries, handlers) enable clear separation of read/write operations, reducing coupling between layers.
  • Domain-Driven Design (DDD): Encourages ubiquitous language via domain entities, value objects, and business exceptions, making the codebase more maintainable for domain experts.
  • Layer Separation: Explicitly enforces Domain (core logic), Application (use cases), and Infrastructure (adapters) layers, preventing "anemic domain model" anti-patterns.

Integration Feasibility

  • Symfony Ecosystem: Seamlessly integrates with Symfony 6.4/7.x, leveraging Symfony Maker components and Doctrine ORM. Minimal configuration required beyond installation.
  • Doctrine ORM: Generates Doctrine-compatible entities and repositories, but does not force ORM coupling—domain entities remain pure PHP.
  • Async/Queue Support: Includes generators for message handlers, enabling event-driven architectures (e.g., Symfony Messenger).
  • Testing Support: Built-in test generators (use-case tests, controller tests) align with Symfony’s testing tools (KernelTestCase, WebTestCase).

Technical Risk

  • Learning Curve: Requires familiarity with Hexagonal Architecture, CQRS, and DDD principles. Teams new to these patterns may struggle with the generated structure’s rigidity.
  • Customization Overhead: While the bundle automates much of the boilerplate, manual adjustments may be needed for complex domains (e.g., nested aggregates, custom validation).
  • Symfony Dependency: Tight coupling to Symfony’s Maker system and Doctrine ORM limits portability to non-Symfony/PHP projects.
  • YAML Configuration: Uses YAML for mapping (e.g., Doctrine), which may be unfamiliar to teams preferring XML or annotations.
  • Limited Documentation: While the README is detailed, the WHY-HEXAGONAL.md guide is external, and some edge cases (e.g., event sourcing) lack examples.

Key Questions for Adoption

  1. Domain Complexity: Is the team’s domain complex enough to justify Hexagonal Architecture’s upfront cost? (Simple CRUD may not need this level of separation.)
  2. Symfony Commitment: Is the project locked into Symfony/Doctrine long-term? If not, the bundle’s framework-specific generators may become a liability.
  3. Team Expertise: Does the team have experience with DDD, CQRS, or Ports & Adapters? If not, training or mentorship will be required.
  4. Async Requirements: Will the project use Symfony Messenger or other async systems? The bundle’s message-handler generators could be critical.
  5. Testing Strategy: Does the team prioritize fast, isolated unit tests? Hexagonal Architecture’s separation enables this but requires discipline.
  6. Migration Path: How will existing codebases (e.g., traditional layered architecture) incrementally adopt this structure?
  7. Customization Needs: Are there domain-specific patterns (e.g., event sourcing, sagas) not covered by the bundle’s generators?

Integration Approach

Stack Fit

  • Primary Stack: Optimized for Symfony 6.4/7.x + Doctrine ORM + PHP 8.1+.
  • Secondary Stack:
    • Async: Symfony Messenger (via make:hexagonal:message-handler).
    • UI: Symfony Controllers, Forms, and CLI commands.
    • Testing: Symfony’s KernelTestCase, WebTestCase, and CommandTester.
  • Anti-Patterns: Avoids:
    • Anemic domain models (entities contain behavior).
    • Direct framework dependencies in the domain layer.

Migration Path

Option 1: Greenfield Project

  1. Install Bundle: composer require ahmedbhs/hexagonal-maker-bundle --dev.
  2. Generate Core Domain:
    bin/console make:hexagonal:entity domain/module EntityName --aggregate-root
    bin/console make:hexagonal:value-object domain/module ValueObjectName
    bin/console make:hexagonal:repository domain/module EntityName
    
  3. Build Application Layer:
    bin/console make:hexagonal:command domain/module create --factory
    bin/console make:hexagonal:query domain/module find-by-id
    
  4. Add Infrastructure Adapters:
    bin/console make:hexagonal:controller domain/module Create /endpoint
    bin/console make:hexagonal:message-handler domain/module CommandHandler
    
  5. Configure Doctrine: Update YAML/XML mappings for entities.

Option 2: Incremental Adoption (Existing Codebase)

  1. Isolate a Module: Start with a single feature (e.g., "User Registration").
  2. Generate Hexagonal Components:
    bin/console make:hexagonal:crud user/account --no-tests
    
  3. Refactor Existing Code:
    • Move business logic from controllers/services to domain entities/use cases.
    • Replace repository implementations with the generated interface.
  4. Phase Out Legacy:
    • Gradually replace controllers/services with hexagonal adapters.
    • Use feature flags to toggle between old/new implementations.

Option 3: Hybrid Architecture

  • Use the bundle for new features while maintaining legacy architecture for existing systems.
  • Example: Generate hexagonal components for a new "Order Processing" module while keeping old "Inventory" code as-is.

Compatibility

Component Compatibility Notes
Symfony 6.4/7.x Full support; leverages Symfony Maker and Flex.
Doctrine ORM Generates Doctrine-compatible entities but keeps domain layer pure.
PHP 8.1+ Requires PHP 8.1+ (attributes, typed properties).
Symfony Messenger Supports async handlers via make:hexagonal:message-handler.
Custom Validation Input DTOs support Symfony Validator constraints.
Event Sourcing Not natively supported; would require custom generators or post-processing.
GraphQL No built-in support; would need to manually create adapters for generated use cases.
API Platform Possible but non-trivial; would require custom controller adapters.

Sequencing

  1. Domain First: Always generate domain entities/value objects before application/use case layers.
  2. Ports Before Adapters: Define repository interfaces (make:hexagonal:repository) before implementing Doctrine adapters.
  3. Use Cases Before UI: Build commands/queries (make:hexagonal:command, make:hexagonal:query) before controllers/forms.
  4. Test Last: Generate tests (make:hexagonal:use-case-test) after implementing use cases.
  5. CRUD as Shortcut: Use make:hexagonal:crud for rapid prototyping, then refactor for complex domains.

Operational Impact

Maintenance

  • Pros:
    • Isolated Domain: Changes to business logic (e.g., validation rules) are localized to domain entities/value objects.
    • Explicit Dependencies: Clear separation of concerns reduces merge conflicts in large teams.
    • Automated Boilerplate: Generators reduce repetitive maintenance (e.g., DTOs, repositories).
  • Cons:
    • Generator Dependencies: Customizing generated code may require overriding templates or post-generation scripts.
    • YAML/Doctrine Overhead: Maintaining YAML mappings for entities adds complexity compared to annotations.
    • Symfony-Specific: Future migration out of Symfony may require rewriting adapters.

Support

  • Debugging:
    • Domain Layer: Pure PHP; easy to debug with unit tests.
    • Application Layer: Use case handlers are isolated; dependencies are injected.
    • Infrastructure Layer: Controllers/services may still have cross-cutting concerns (e.g., auth, logging).
  • Common Pitfalls:
    • Repository Misuse: Overusing repositories for business logic (violates Hexagonal principles).
    • Over-Engineering: Applying CQRS/Hexagonal to simple domains (e.g., "User Profile").
    • Test Duplication: Generating tests for every use case may lead to maintenance overhead.
  • Tooling:
    • IDE Support: Modern IDEs (PHPStorm, VSCode) handle attributes and typed properties well.
    • Static Analysis: Psalm or PHPStan can catch type issues in the domain layer.

Scaling

  • Performance:
    • Domain Layer: Zero framework overhead; pure PHP objects are fast.
    • Application Layer: Use cases are stateless and cache-friendly.
    • Infrastructure Layer: Controllers may become bottlenecks; consider:
      • Async Processing: Offload long-running tasks to message handlers.
      • Caching: Cache query responses (e.g., FindUserQueryHandler).
  • Team Scaling:
    • Ownership: Teams can own entire "hexagons" (
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
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
christhompsontldr/laravel-inky