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 Foundation

Ddd Foundation Laravel Package

alexandrebulete/ddd-foundation

View on GitHub
Deep Wiki
Context7

To implement DDD easier

Frequently asked questions about Ddd Foundation
How do I integrate this package with Laravel’s Eloquent ORM?
The package provides repository interfaces (e.g., `RepositoryInterface`) that you can implement for Eloquent models. For example, create a `UserRepository` class extending `EloquentRepository` (if available) or wrapping Eloquent queries. The `InMemoryRepository` can also be used for testing. Ensure your repository implements the required methods like `find()`, `save()`, and `delete()`.
Can I use this package with Laravel 10 or newer?
Yes, the package is designed to work with modern Laravel versions, including Laravel 10. It leverages PHP 8.1+ features like enums and attributes (e.g., `#[AsCommandHandler]`). Always check the package’s `composer.json` for the latest Laravel compatibility or test it in your environment to confirm.
What’s the best way to handle domain events in Laravel?
Domain events can be mapped to Laravel’s native `Event` facade or dispatched asynchronously using Symfony Messenger (via the `ddd-symfony-bundle`). For example, create a `DomainEventDispatcher` that listens to domain events and triggers Laravel events or queues them for processing. The package doesn’t enforce a specific event system, so you can choose what fits your architecture.
Will this package work with Livewire or Inertia.js for UI?
Yes, the package includes the `AsSelectableEnum` trait, which is useful for form filters in Livewire or Inertia.js. For example, you can use it to generate dropdown options for enums like `StatusEnum::choices()`. Pair it with Laravel’s validation or Pintura for form handling, and the package’s query/command structure will work seamlessly with your frontend.
How do I test domain logic with this package?
The package provides an `InMemory` infrastructure layer (e.g., `InMemoryRepository`) for unit testing. Replace your database repositories with in-memory implementations during tests. For integration tests, use Laravel’s testing tools like `HttpTests` or `FeatureTests`, mocking external dependencies like repositories or services. The `InMemoryPaginator` is also useful for testing pagination logic.
Is there a performance overhead for using Value Objects and repositories?
The package introduces minimal overhead. Value Objects are immutable and lightweight, while repositories add abstraction but delegate to your ORM (Eloquent/Doctrine). The `CriteriaNormalizer` and other utilities are optimized for clarity, not performance. For high-throughput systems, profile critical paths, but the abstraction is negligible for most Laravel applications.
Can I mix DDD with traditional Laravel models in the same project?
Yes, you can incrementally adopt DDD. For example, use the package for new features or bounded contexts while keeping legacy Eloquent models for existing functionality. Implement hybrid repositories that bridge DDD interfaces and Eloquent methods. This approach is common in large projects transitioning to DDD.
How do I handle validation in the domain layer vs. application layer?
Domain logic should validate business rules (e.g., `EmailVO` enforcing format), while the application layer handles HTTP-specific validation (e.g., Laravel’s Form Requests). Use the package’s `ValueObject` classes for domain validation and integrate Laravel’s validation for input sanitization. For complex rules, combine both layers.
Are there alternatives if I don’t want to use this package?
Alternatives include Symfony’s DDD bundles (e.g., `api-platform/core` or `symfony/ux-live-component`), custom implementations using Laravel’s service container, or packages like `spatie/laravel-query-builder` for repository patterns. If you prefer a lighter touch, consider using traits or interfaces directly without a full DDD package.
How do I extend this package for custom persistence (e.g., MongoDB or Redis)?
Implement the `RepositoryInterface` for your storage backend. For example, create a `MongoDbRepository` that extends `InMemoryRepository` or builds queries using a MongoDB driver. The package’s abstractions (e.g., `IdentifierVO`) remain agnostic, so you only need to adapt the persistence layer. Test thoroughly to ensure consistency with domain expectations.
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