PHPackages                             othercode/complex-heart - 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. othercode/complex-heart

ActiveLibrary

othercode/complex-heart
=======================

Domain driven design tools.

v0.4.7(3y ago)511.2k1MITPHPPHP ^7.4|^8.0CI failing

Since Dec 1Pushed 1y ago1 watchersCompare

[ Source](https://github.com/othercodes/ComplexHeart)[ Packagist](https://packagist.org/packages/othercode/complex-heart)[ RSS](/packages/othercode-complex-heart/feed)WikiDiscussions develop Synced 1w ago

READMEChangelog (10)Dependencies (10)Versions (20)Used By (0)

ComplexHeart
============

[](#complexheart)

[![Latest Stable Version](https://camo.githubusercontent.com/353893e6a3b878e461ff087780fdde000fde6554b4ab400e3e0b3b59d45e78f2/68747470733a2f2f706f7365722e707567782e6f72672f6f74686572636f64652f636f6d706c65782d68656172742f76)](//packagist.org/packages/othercode/complex-heart)[![License](https://camo.githubusercontent.com/eaedf419800b0e1955c101f63d3ba01b87adfce438f2ba4705381d0400e1341e/68747470733a2f2f706f7365722e707567782e6f72672f6f74686572636f64652f636f6d706c65782d68656172742f6c6963656e7365)](//packagist.org/packages/othercode/complex-heart)[![Tests](https://github.com/othercodes/ComplexHeart/workflows/Tests/badge.svg)](https://github.com/othercodes/ComplexHeart/workflows/Tests/badge.svg)[![codecov](https://camo.githubusercontent.com/1bb09704a460fadda0f9a56b5dd214cd8ef338893ffe665e308dbe036da2b484/68747470733a2f2f636f6465636f762e696f2f67682f6f74686572636f6465732f436f6d706c657848656172742f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d774c33784c4661543232)](https://codecov.io/gh/othercodes/ComplexHeart)

About
-----

[](#about)

The **Complex Heart** name stands from "*Domain-Driven Design: Tackling Complexity in the Heart of Software*" Eric Evans Book. This project intends to provide a set of useful classes and tools to ease the adoption of Domain Driven Design into your project.

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

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

Let's see a very basic example:

```
use OtherCode\ComplexHeart\Domain\Contracts\ValueObject;
use OtherCode\ComplexHeart\Domain\Traits\IsValueObject;

/**
 * Class Color
 * @method string value()
 */
final class Color implements ValueObject
{
    use IsValueObject;

    private string $value;

    public function __construct(string $value) {
        $this->initialize(['value' => $value]);
    }

    protected function invariantValueMustBeHexadecimal(): bool {
        return preg_match('/^#(?:[0-9a-fA-F]{3}){1,2}$/', $this->value) === 1;
    }

    public function __toString(): string {
        return $this->value();
    }
}

$red = new Color('#ff0000');
$red->equals(new Color('#00ff00')); // false
$red->value(); // #ff0000
$magenta = new Color('ff00ff'); // Exception InvariantViolation: Value must be hexadecimal.
```

To define a Value Object you only need to use the `IsValueObject` trait, this will allow you to use some functions like `equals()` that will automatically compare the value of the objects or `initialize()` that will allow you to run invariant validations against the object values. Optionally, and recommended, you can use the `ValueObject` interface.

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`

Service Bus: Commands, Queries and Events
-----------------------------------------

[](#service-bus-commands-queries-and-events)

The Service Bus integration contains some basic interfaces (`ServiceBus`, `CommandBus`, `QueryBus`, and `EventBus`) and classes to build on top of them.

- `Message` Base DTO to transfer objects between layers.
    - `Request`
        - `Command` Command DTO.
        - `Event` Event DTO.
        - `Query` Query DTO.
    - `Response`

Check this small example of the usage:

```
$response = $queryBus->ask(new GetUserQuery('some-uuid-value'));
```

Check the [wiki](https://github.com/othercodes/ComplexHeart/wiki) for more detailed examples.

References
----------

[](#references)

- [Pro Codely TV](https://pro.codely.tv/library/)
- [martinFowler.com](https://martinfowler.com/tags/domain%20driven%20design.html)
- [Clean Architecture](https://amzn.to/2ImCugP)
- [Clean Code](https://amzn.to/3goF2HK)
- [Domain-Driven Design: Tackling Complexity in the Heart of Software](https://amzn.to/2K0gJ6S)

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80% 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 ~48 days

Recently: every ~127 days

Total

17

Last Release

1224d ago

PHP version history (2 changes)v0.0.1PHP ^7.4

v0.1.0PHP ^7.4|^8.0

### 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 (36 commits)")[![segoddnja](https://avatars.githubusercontent.com/u/1170038?v=4)](https://github.com/segoddnja "segoddnja (9 commits)")

---

Tags

aggregatescommandbuscqrsddddomain-driven-designentitieseventbushexagonal-architecturequerybusvalue-object

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[laravel/framework

The Laravel Framework.

34.6k509.9M17.0k](/packages/laravel-framework)[laravel/horizon

Dashboard and code-driven configuration for Laravel queues.

4.2k84.2M225](/packages/laravel-horizon)[illuminate/support

The Illuminate Support package.

583107.1M34.5k](/packages/illuminate-support)[laravel/nightwatch

The official Laravel Nightwatch package.

3486.1M13](/packages/laravel-nightwatch)[temporal/sdk

Temporal SDK

4002.2M18](/packages/temporal-sdk)[directorytree/imapengine

A fully-featured IMAP library -- without the PHP extension

531175.4k4](/packages/directorytree-imapengine)

PHPackages © 2026

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