mj-zana / ddd
Domain-Driven Design and CQRS building blocks for Zana applications
v2.37.0
2026-11-20 20:29 UTC
Requires
- php: ^8.5
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-main
- v2.37.0
- v2.36.0
- v2.35.0
- v2.34.0
- v2.33.0
- v2.32.0
- v2.31.0
- v2.30.0
- v2.29.0
- v2.28.0
- v2.27.0
- v2.26.0
- v2.25.0
- v2.24.0
- v2.23.0
- v2.22.0
- v2.21.0
- v2.20.0
- v2.19.0
- v2.18.0
- v2.17.0
- v2.16.0
- v2.15.0
- v2.14.0
- v2.13.0
- v2.12.0
- v2.11.0
- v2.10.0
- v2.9.0
- v2.8.0
- v2.7.0
- v2.6.0
- v2.5.0
- v2.4.0
- v2.3.0
- v2.2.0
- v2.1.0
- v2.0.0
- v2.0.0-rc.1
- v2.0.0-beta.3
- v2.0.0-beta.2
- v2.0.0-beta.1
- v2.0.0-alpha.3
- v1.0.1
- v1.0.0
This package is auto-updated.
Last update: 2026-11-24 16:53:52 UTC
README
Domain-Driven Design and CQRS building blocks for Domain and Application code. No framework dependencies. Requires PHP 8.5 or later.
composer require mj-zana/ddd
Building blocks
| Type | Use |
|---|---|
Entity, AggregateRoot |
identity-based equality, recorded domain events (recordEvent(), releaseEvents()), version for optimistic concurrency |
ValueObject |
immutable (readonly), compared by value; nested value objects and identities compare by value too |
Identity |
typed ids: PatientId::generate(), PatientId::fromString($s) |
Uuid |
Uuid::v7() (time-ordered, strictly increasing within a process), Uuid::isValid() |
DomainEvent |
event id (UUID v7), occurrence time |
Result, DomainError |
Result::ok($v) / Result::fail($error), with map() and then() |
Specification |
isSatisfiedBy(), composed with and(), or(), not() |
RepositoryInterface, UnitOfWorkInterface |
persistence contracts implemented by infrastructure (e.g. mj-zana/database) |
Command, Query |
CQRS messages with an id and a creation time |
final readonly class PatientId extends Identity {} final readonly class Height extends ValueObject { public function __construct(public float $centimetres) {} } final class Patient extends AggregateRoot { public static function register(PatientId $id, string $name): self { $patient = new self($id); $patient->recordEvent(new PatientRegistered($name)); return $patient; } }
Upgrading from 1.x
ValueObjectisreadonly, so subclasses must be declaredreadonlytoo.with()is removed.- Event, command and query ids are UUID v7 strings instead of
uniqid()values. DomainEventtakes an optionaloccurredAtas its second constructor argument.
Development
composer install
composer test
composer analyse
License
MIT — see LICENSE.