New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

complex-heart/domain-model

Domain model toolset to properly build Value Objects, Entities and Aggregates.
4,478 3
Install
composer require complex-heart/domain-model
Latest Version:v6.0.0
PHP:^8.2
Laravel:12 · 13
Older releases:8 – 11
License:MIT
Last Updated:Aug 11, 2026
Links: GitHub  ·  Packagist
Maintainer: usantisteban

Domain Model

Tests Quality Gate Status Coverage

Modeling Aggregates, Entities and Value Objects

Complex Heart allows you to model your domain Aggregates, Entities, and Value Objects using a set of traits. Great, but why traits and not classes? Well, sometimes you have some kind of inheritance in your classes. Being forced to use a certain base class is too invasive and personally, I don't like it. By using a set of traits and interfaces you have all the functionality you need without compromising the essence of your own domain.

The available traits are:

  • HasAttributes Provide some functionality to manage attributes.
  • HasEquality Provide functionality to handle equality between objects.
  • HasInvariants Allow invariant checking on instantiation (Guard Clause).
  • HasIdentity Define the Entity/Aggregate identity.
  • HasDomainEvents Provide domain event management.

On top of those base traits Complex Heart provide ready to use compositions:

  • IsModel composed by HasAttributes and HasInvariants.
  • IsValueObject composed by IsModel and HasEquality.
  • IsEntity composed by IsModel, HasIdentity, HasEquality.
  • IsAggregate composed by IsEntity, HasDomainEvents.

Key Features

  • Type-Safe Factory Method: The make() static factory validates constructor parameters at runtime with clear error messages
  • Automatic Invariant Checking: When using make(), Value Objects and Entities automatically validate invariants after construction (no manual $this->check() needed)
  • Named Parameter Support: Full support for PHP 8.0+ named parameters for improved readability and flexibility
  • Union Type Support: Complete support for PHP 8.0+ union types (e.g., int|float, string|null)
  • Readonly Properties Support: Full compatibility with PHP 8.1+ readonly properties
  • PHPStan Level 8: Complete static analysis support

Note: Automatic invariant checking only works when using the make() factory method. Direct constructor calls require manual $this->check() in the constructor.

For more information and usage examples, please check the wiki.

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

648,266,899 9,701
laravel/framework

The Laravel Framework.

604,216,237 34,982
laravel/tinker

Powerful REPL for the Laravel framework.

512,508,631 7,443
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

429,221,767 607
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

407,699,310 4,663

Version History

Version Released PHP Laravel License
v6.0.0 ^8.2 ^12.0.0 || ^13.0.0 MIT
v5.1.0 ^8.2 ^11.0.0 || ^12.0.0 MIT
v5.0.0 ^8.2 ^11.0.0 Apache-2.0
v4.2.0 ^8.1.0 ^11.0.0 Apache-2.0
v4.1.0 ^8.1.0 ^11.0.0 Apache-2.0