PHPackages                             premiervirtual/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. premiervirtual/complex-heart

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

premiervirtual/complex-heart
============================

Domain driven design tools.

v0.5.1(2y ago)01.4kMITPHPPHP ^8.1

Since Dec 1Pushed 2y agoCompare

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

READMEChangelog (3)Dependencies (10)Versions (22)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

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 72% 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 ~57 days

Recently: every ~180 days

Total

20

Last Release

903d ago

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

v0.1.0PHP ^7.4|^8.0

v0.5.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1170038?v=4)[Dmytro Zasyadko](/maintainers/segoddnja)[@segoddnja](https://github.com/segoddnja)

---

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 (14 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[grumpydictator/firefly-iii

Firefly III: a personal finances manager.

22.8k69.3k](/packages/grumpydictator-firefly-iii)[laravel/nightwatch

The official Laravel Nightwatch package.

3526.1M13](/packages/laravel-nightwatch)[firefly-iii/data-importer

Firefly III Data Import Tool.

7545.8k](/packages/firefly-iii-data-importer)[whitecube/laravel-timezones

Store UTC dates in the database and work with custom timezones in the application.

106106.2k](/packages/whitecube-laravel-timezones)[diego-ninja/laravel-devices

This package provides session tracking functionalities, multi-session management and user device management features for laravel applications.

763.1k2](/packages/diego-ninja-laravel-devices)

PHPackages © 2026

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