PHPackages                             net-code/laravel-domain - 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. [Framework](/categories/framework)
4. /
5. net-code/laravel-domain

ActiveLibrary[Framework](/categories/framework)

net-code/laravel-domain
=======================

DDD tactical building blocks (aggregate root, value objects, domain events, typed UUID identifiers, business-rule specification) with optional Laravel integration.

v0.1.2(1mo ago)073MITPHPPHP ^8.5

Since Jul 10Pushed 1mo agoCompare

[ Source](https://github.com/Net-Tech-Marek-Rode-Sp-z-o-o/laravel-domain)[ Packagist](https://packagist.org/packages/net-code/laravel-domain)[ RSS](/packages/net-code-laravel-domain/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (8)Versions (4)Used By (3)

net-code/laravel-domain
=======================

[](#net-codelaravel-domain)

DDD tactical building blocks — the reusable kernel that concrete bounded contexts build on. The core (`NetCode\Domain\*`) is pure PHP 8.5+ (only `ramsey/uuid`); a thin, **optional**Laravel integration layer (`NetCode\Domain\Laravel\*`) wires the kernel into a Laravel app through an auto-discovered service provider.

Install
-------

[](#install)

```
composer require net-code/laravel-domain
```

What's inside
-------------

[](#whats-inside)

Class / interfacePurpose`NetCode\Domain\AggregateRoot`Base aggregate that records and releases domain events.`NetCode\Domain\ValueObject`Base value object with an `equals()` contract.`NetCode\Domain\DomainEvent`Marker interface for events (`occurredOn()`).`NetCode\Domain\DomainEventPublisher`Publisher seam implemented by the host application.`NetCode\Domain\Identifier\Uuid`Base for typed UUID identifiers (UUIDv7).`NetCode\Domain\Rule\BusinessRule`A single invariant that can be broken.`NetCode\Domain\Rule\BusinessRuleCode`Backed-enum contract for machine-readable rule codes.`NetCode\Domain\Rule\TranslatableRuleParams`Optional translation parameters for a rule.`NetCode\Domain\Rule\Specification`Checks rules and throws `BusinessRuleException` on the first broken one.`NetCode\Domain\Rule\BusinessRuleException`Carries the broken rule's code and translation params.`NetCode\Domain\Exception\DomainException`Base for domain-layer exceptions.`NetCode\Domain\Exception\InvalidArgumentException`Invalid value-object input.### Laravel integration (`NetCode\Domain\Laravel`)

[](#laravel-integration-netcodedomainlaravel)

ClassPurpose`DomainServiceProvider`Auto-discovered; binds `DomainEventPublisher` → `LaravelDomainEventPublisher`.`LaravelDomainEventPublisher`Publishes domain events through Laravel's event dispatcher.`IdentifierCast`Eloquent cast between a string column and a typed `Identifier\Uuid`.Usage
-----

[](#usage)

### Typed identifier

[](#typed-identifier)

```
use NetCode\Domain\Identifier\Uuid;

final class OrderId extends Uuid {}

$id = OrderId::random();          // UUIDv7
$id->equals(OrderId::fromString((string) $id)); // true
```

### Aggregate + domain events

[](#aggregate--domain-events)

```
use NetCode\Domain\AggregateRoot;

final class Order extends AggregateRoot
{
    public function place(): void
    {
        // ... mutate state ...
        $this->recordThat(new OrderPlaced(/* ... */));
    }
}

$events = $order->releaseEvents(); // hand to your DomainEventPublisher
```

### Business rules via a specification

[](#business-rules-via-a-specification)

```
use NetCode\Domain\Rule\Specification;

Specification::check(
    new OrderMustHaveLines($order),
    new OrderMustBeUnpaid($order),
); // throws BusinessRuleException on the first broken rule
```

`Specification::check()` is a static, stateless guard — call it directly from your aggregates. There is no instance to construct, inject, or subclass.

### Laravel integration

[](#laravel-integration)

`DomainServiceProvider` is auto-discovered, so `DomainEventPublisher` resolves to `LaravelDomainEventPublisher` (domain events go through Laravel's dispatcher) with zero wiring. Cast a model's identifier column to its typed value object:

```
use Illuminate\Database\Eloquent\Model;
use NetCode\Domain\Laravel\IdentifierCast;

final class OrderModel extends Model
{
    /** @return array */
    protected function casts(): array
    {
        return ['id' => IdentifierCast::class.':'.OrderId::class];
    }
}
```

Development
-----------

[](#development)

```
composer check   # pint --test + phpstan (level 8) + phpunit
```

License
-------

[](#license)

MIT

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance90

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 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 ~0 days

Total

3

Last Release

48d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e1537b84454509a8f558fa6772528d6ef0942cd74e39c5224ae39e41ea9c841e?d=identicon)[mrode-net-tech](/maintainers/mrode-net-tech)

---

Top Contributors

[![mrode-net-tech](https://avatars.githubusercontent.com/u/158272218?v=4)](https://github.com/mrode-net-tech "mrode-net-tech (4 commits)")

---

Tags

laravelspecificationValue ObjectDomain Driven Designddddomain-eventsaggregate-root

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/net-code-laravel-domain/health.svg)

```
[![Health](https://phpackages.com/badges/net-code-laravel-domain/health.svg)](https://phpackages.com/packages/net-code-laravel-domain)
```

###  Alternatives

[laravel/horizon

Dashboard and code-driven configuration for Laravel queues.

4.2k99.8M362](/packages/laravel-horizon)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/packages/psalm-plugin-laravel)[laravel/ai

The official AI SDK for Laravel.

1.1k4.6M342](/packages/laravel-ai)[illuminate/queue

The Illuminate Queue package.

20433.0M1.9k](/packages/illuminate-queue)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k31.8M163](/packages/laravel-cashier)[laravel/scout

Laravel Scout provides a driver based solution to searching your Eloquent models.

1.7k57.2M690](/packages/laravel-scout)

PHPackages © 2026

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