PHPackages                             complex-heart/domain-model - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. complex-heart/domain-model

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

complex-heart/domain-model
==========================

Domain model toolset to properly build Value Objects, Entities and Aggregates.

v5.1.0(2mo ago)42.4k2MITPHPPHP ^8.2CI passing

Since Jun 15Pushed 2mo agoCompare

[ Source](https://github.com/ComplexHeart/php-domain-model)[ Packagist](https://packagist.org/packages/complex-heart/domain-model)[ RSS](/packages/complex-heart-domain-model/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (26)Versions (14)Used By (2)

Domain Model
============

[](#domain-model)

[![Tests](https://github.com/ComplexHeart/php-domain-model/actions/workflows/test.yml/badge.svg)](https://github.com/ComplexHeart/php-domain-model/actions/workflows/test.yml)[![Quality Gate Status](https://camo.githubusercontent.com/b9131aa3bd71221b78be0c70747468d13f0e389a61a274f43a068c43e93d99f6/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d436f6d706c657848656172745f7068702d646f6d61696e2d6d6f64656c266d65747269633d616c6572745f737461747573)](https://sonarcloud.io/summary/new_code?id=ComplexHeart_php-domain-model)[![Coverage](https://camo.githubusercontent.com/ed6b3d89c49d371da991cd0ab092ba9208a5c73480c209da8bc2b0b68dfa9820/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d436f6d706c657848656172745f7068702d646f6d61696e2d6d6f64656c266d65747269633d636f766572616765)](https://sonarcloud.io/summary/new_code?id=ComplexHeart_php-domain-model)

Modeling Aggregates, Entities and Value Objects
-----------------------------------------------

[](#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
------------

[](#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.

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance87

Actively maintained with recent releases

Popularity25

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~144 days

Recently: every ~177 days

Total

13

Last Release

67d ago

Major Versions

v1.0.0 → v2.0.02022-09-19

v2.1.0 → v3.0.02024-01-02

v3.1.1 → v4.0.02024-04-02

v4.2.0 → v5.0.02025-10-16

PHP version history (5 changes)v1.0.0PHP ^7.4|^8.0

v2.0.0PHP ^8.0

v3.0.0PHP ^8.1

v4.0.0PHP ^8.1.0

v5.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/7958790dcf5cd51ebbadc52fc7bada326fb3edd4481decf1006e6cfed8e46c43?d=identicon)[usantisteban](/maintainers/usantisteban)

---

Top Contributors

[![othercodes](https://avatars.githubusercontent.com/u/4815856?v=4)](https://github.com/othercodes "othercodes (33 commits)")

---

Tags

aggregatesdata-modelsdddentitiesmodelingvalue-objects

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/complex-heart-domain-model/health.svg)

```
[![Health](https://phpackages.com/badges/complex-heart-domain-model/health.svg)](https://phpackages.com/packages/complex-heart-domain-model)
```

###  Alternatives

[illuminate/support

The Illuminate Support package.

582107.1M34.5k](/packages/illuminate-support)[fisharebest/webtrees

webtrees online genealogy

73710.5k13](/packages/fisharebest-webtrees)[illuminate/reflection

The Illuminate Reflection package.

371.6M3](/packages/illuminate-reflection)[oat-sa/lib-lti1p3-core

OAT LTI 1.3 Core Library

36341.9k10](/packages/oat-sa-lib-lti1p3-core)[erlandmuchasaj/laravel-gzip

Gzip your responses.

40129.3k2](/packages/erlandmuchasaj-laravel-gzip)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
