Weave 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
Domain Structures

Domain Structures Laravel Package

andydefer/domain-structures

A Laravel/PHP package that provides reusable domain structures and building blocks for domain-driven design. It helps organize business logic, reduce boilerplate, and keep core rules isolated from framework and infrastructure concerns for cleaner, more maintainable applications.

View on GitHub
Deep Wiki
Context7

A complete domain structures package for PHP: Records, Value Objects, Data DTOs, and TypedCollections. Brings type safety and clean architecture to your application.

Frequently asked questions about Domain Structures
Which Laravel and PHP versions does andydefer/domain-structures support?
The package is installed through Composer with PSR-4 autoloading and is described as framework-agnostic domain tooling, so it likely does not ship a Laravel service provider. However, exact PHP and Laravel version constraints are not documented in the available information. Check the require block in the package composer.json and run a small proof of concept on your target Laravel version before committing. Test on a non-critical module first if you are on an older or very new Laravel release.
How do I install andydefer/domain-structures in a Laravel app?
Install it with composer require andydefer/domain-structures, then confirm the PSR-4 namespace maps correctly by instantiating one class. Because it appears framework-agnostic, you probably do not need to register a service provider or publish config. After installing, create a single DTO or Value Object and a short smoke test to verify autoloading and behavior. Pin the version in composer.json once you confirm it works with your stack.
What is the difference between Records, Value Objects, DTOs, and TypedCollections in this package?
Value Objects wrap and validate a single concept such as Money, Email, or Status, while Records represent immutable domain data structures. DTOs carry data across boundaries like HTTP requests, jobs, and service calls, and TypedCollections give you type-safe lists of domain objects instead of loose arrays. Together they replace unstructured arrays and anemic Eloquent usage in your domain layer. Keep Eloquent models and HTTP resources as mapping boundaries rather than replacing them outright.
Can I use andydefer/domain-structures outside of Laravel?
Yes, the package is described as a PHP domain structures library rather than a Laravel-specific bundle, and the assessment notes it is unlikely to require a service provider. That makes it usable in plain PHP services, CLI tools, and other frameworks. Verify the dependency list in composer.json to confirm it does not pull in Illuminate components. If it is truly framework-agnostic, your domain layer stays portable.
How do DTOs and Records serialize to arrays or JSON in this package?
Serialization semantics are not documented in the available information, so treat this as something to verify yourself. Write contract tests that convert your DTOs and Records to arrays, to JSON, and back again before using them in API responses. Also test queue serialization, since jobs that carry DTOs must round-trip cleanly. If the package does not implement Laravel's JsonSerializable or Arrayable conventions, add explicit mapper classes at the boundary.
How do I map Eloquent models to DTOs and Records?
Keep Eloquent models in your infrastructure layer and map them to DTOs or Records inside repositories or service classes. That way your domain code depends on plain PHP objects rather than the query builder or Eloquent serialization behavior. Start with one bounded context, such as an internal API module, and define mapping conventions early. Avoid a broad refactor until mapping, validation, and collection behavior are proven in that module.
Do TypedCollections work with Laravel collections and Eloquent collections?
Interoperability with Illuminate\Support\Collection is not confirmed, so do not assume TypedCollections satisfy Laravel's collection contracts. Use TypedCollections internally where you control the types, and convert to Laravel collections at the edges that expect them, such as JSON resources or Blade views. Write tests covering map, filter, and iteration before adopting them widely. If conversion is awkward, restrict TypedCollections to pure domain code.
Are the Value Objects and Records immutable and validated on construction?
The package positions itself around type safety and explicit domain structures, and immutability plus construction-time validation are the usual goals of this style of library. Confirm it in practice by writing tests that attempt to mutate properties and construct invalid values. Also check equality and comparison semantics, since Value Objects typically need value-based equality rather than identity comparison. If behavior differs from your expectations, wrap the classes or document the gap internally.
Is andydefer/domain-structures safe to use in production?
Treat it as a high maturity risk: it has no visible stars, dependents, or ecosystem validation, and long-term maintenance is unclear. That does not make it unusable, but it means you should pin versions, assign an internal owner, and wrap usage behind your own conventions. Add static analysis and contract tests around the parts you depend on, and confirm the license allows forking or vendoring if maintenance stalls. Start in a low-risk module rather than shared core code.
What are the alternatives to andydefer/domain-structures for DTOs and Value Objects in Laravel?
Many teams use PHP readonly classes and native enums for simple Value Objects and DTOs, plus packages like spatie/laravel-data for rich data objects with validation. Dedicated libraries such as moneyphp/money, brick/money, and ramsey/uuid cover specific value types. Eloquent casts and custom cast classes can also handle value conversion at the persistence boundary. Compare these against this package on serialization, static analysis support, and maintenance before standardizing.
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.
andydefer/laravel-notification
adachsoft/cli-process-tester
jhaskell13/laraflow
sebastienheyd/boilerplate-media-manager
ccast/tagixo-primix
pretendtrue/laravel-builder
sawmainek/laravel-scout-tntsearch-driver
tomshaw/laravel-calendar-table
dibakar/laravel-ownership
steadrun/laravel-monitor
labyrinthe/connect-laravel
elmogy/layan
drewdan/sentinel-client
dskripchenko/laravel-llm
fatryst/nuonuo
stevenay/myanfont
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc