PHPackages                             alex-kassel/laravel-domain-core - 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. [Database &amp; ORM](/categories/database)
4. /
5. alex-kassel/laravel-domain-core

ActiveLibrary[Database &amp; ORM](/categories/database)

alex-kassel/laravel-domain-core
===============================

High-cohesion Laravel platform foundation unifying Domain Context Registration, Dynamic Multi-Database Migrations, Context-Aware Eloquent Models, Standardized CLI Execution, Overlap Lock Management, Diagnostic Events, and Child Domain Package Scaffolding.

v2.0.3(today)035↑2728.6%MITPHPPHP ^8.2CI passing

Since Aug 18Pushed todayCompare

[ Source](https://github.com/alex-kassel/laravel-domain-core)[ Packagist](https://packagist.org/packages/alex-kassel/laravel-domain-core)[ Docs](https://github.com/alex-kassel/laravel-domain-core)[ RSS](/packages/alex-kassel-laravel-domain-core/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (8)Versions (6)Used By (0)

🏛️ Laravel Domain Core
======================

[](#️-laravel-domain-core)

 **Polyglot domain storage contexts, dynamic multi-database provisioning, and ambient execution scoping**

 [Installation](#installation) • [Storage Contexts](#1-registering-domain-storage-contexts) • [Ambient Scopes](#2-ambient-execution-scopes) • [Commands](#commands) • [Release Gate](RELEASE-GATE.md) • [Changelog](CHANGELOG.md)

 [![Audit Verified](https://camo.githubusercontent.com/ad42f3e373736ebfc17d1a0f7e929dd1de73284cbeadb5f24488b9dacb7eef9a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f41756469742d56657269666965642d3130623938313f6c6f676f3d736869656c64)](RELEASE-GATE.md) [![Latest Version](https://camo.githubusercontent.com/3509d256994bd40c35e2c02586cb4c8e3fb0ffef701acea72f12b85617da01ce/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616c65782d6b617373656c2f6c61726176656c2d646f6d61696e2d636f72653f636f6c6f723d663539653062266c6f676f3d7061636b6167697374266c6f676f436f6c6f723d7768697465)](https://packagist.org/packages/alex-kassel/laravel-domain-core) [![Laravel Support](https://camo.githubusercontent.com/32bb20867c064c55c8d525a65a804cf541a083615e3e1810d8098774901ac762/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d3131253230253743253230313225323025374325323031332d6666326432303f6c6f676f3d6c61726176656c266c6f676f436f6c6f723d7768697465)](https://laravel.com) [![PHP Support](https://camo.githubusercontent.com/efb9e9ab96e9febd681c962354b111daa4f2cddccc85b9571e7452145877aeb2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e322b2d3737376262343f6c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://php.net) [![PHPStan Level Max](https://camo.githubusercontent.com/12a851c30b0a4a96268ec381d89ec543bf69a5d6f5141ae80ee15422cf410420/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c2532304d61782d3862356366363f6c6f676f3d706870266c6f676f436f6c6f723d7768697465)](RELEASE-GATE.md)

---

**Laravel Domain Core** is a high-cohesion platform foundation for modular Laravel applications. It unifies **Polyglot Domain &amp; Storage Context Registration**, **Dynamic Multi-Database &amp; S3/Filesystem/Redis Provisioning**, **Context-Aware Base Eloquent Models**, **Standardized Operator CLI Execution**, and **Distributed Lock Management**.

It introduces a clean architectural separation between **Logical Business Contexts** (`StorageContext`) and **Physical Storage Mediums** (`StorageInterface`):

```
Domain Profile (e.g., 'automotive-leasing')
└── StorageContext[] (e.g., 'primary', 'raw-html', 'transient-cache')
    ├── DatabaseStorage   (connection: 'sqlite_leasing_primary', prefix: 'leasing_primary_', migrations: [...])
    ├── FileStorage       (disk: 's3', basePath: 'leasing/raw-html/')
    └── RedisStorage      (connection: 'default', keyPrefix: 'leasing:cache:')

```

---

Key Features
------------

[](#key-features)

- **Polyglot Persistence Support:** Register and manage relational databases (MySQL, PostgreSQL, SQLite), object storage/filesystems (Local, S3, MinIO), and in-memory caches (Redis) under a unified domain model.
- **First-Class IDE Autocomplete &amp; Type Safety:** Strongly-typed Enum `StorageDriverType`, dedicated named constructors (`StorageContext::database()`, `::filesystem()`, `::redis()`), and downcasting helpers (`$context->asDatabase()`, `$context->asFilesystem()`).
- **Context-Aware Eloquent Models &amp; Hijacking Protection:** Automatically route database connections and table prefixes at runtime; statically bound models cannot be hijacked by outer ambient scopes.
- **Isolated Multi-Context Migrations:** Filter database-backed contexts automatically and safely drop only domain-prefixed tables on shared connections via `domain:migrate --fresh`.
- **Standardized Operator CLI DX &amp; Distributed Locks:** Uniform Artisan command flags (`--all`, `--domains`, `--context`, `--force`, `--dry-run`, `--lock-ttl`) with robust lock management and POSIX signal handling (`SIGTERM`, `SIGINT`).
- **Actionable Diagnostics:** Structured `[PROBLEM]`, `[CAUSE]`, and `[RESOLUTION]` exceptions paired with diagnostic events (`StorageConnectionMissing`, `CommandExecutionFailed`, `LockAcquisitionFailed`).
- **Domain Package Scaffolding:** CLI generator (`domain:make-domain`) for standardized domain package skeletons.

---

Requirements
------------

[](#requirements)

- **PHP:** 8.2+ (tested on 8.2, 8.3, 8.4)
- **Laravel Framework:** 11.x | 12.x | 13.x

---

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require alex-kassel/laravel-domain-core
```

The Service Provider `AlexKassel\DomainCore\Providers\DomainCoreServiceProvider` is automatically registered via Laravel Package Discovery.

---

Usage
-----

[](#usage)

### 1. Registering Domain Storage Contexts

[](#1-registering-domain-storage-contexts)

Use dedicated named constructors for full IDE autocomplete:

```
use AlexKassel\DomainCore\Contracts\DomainRegistryInterface;
use AlexKassel\DomainCore\DTOs\StorageContext;

$registry = app(DomainRegistryInterface::class);

// Register domain profile
$registry->registerDomain(
    slug: 'automotive-leasing',
    name: 'Automotive Leasing',
    metadata: ['category' => 'vehicles']
);

// Register Relational Database Storage Context
$registry->registerStorageContext(StorageContext::database(
    domainSlug: 'automotive-leasing',
    contextSlug: 'primary',
    connectionName: 'sqlite_leasing_primary',
    tablePrefix: 'leasing_primary_',
    migrationPaths: [__DIR__ . '/../database/migrations'],
    autoCreateSqliteDatabase: true
));

// Register S3 / Filesystem Storage Context
$registry->registerStorageContext(StorageContext::filesystem(
    domainSlug: 'automotive-leasing',
    contextSlug: 'raw-html',
    disk: 's3',
    basePath: 'leasing/raw-html/'
));

// Register Redis Storage Context
$registry->registerStorageContext(StorageContext::redis(
    domainSlug: 'automotive-leasing',
    contextSlug: 'transient-cache',
    connection: 'default',
    keyPrefix: 'leasing:cache:'
));
```

---

### 2. Ambient Execution Scopes

[](#2-ambient-execution-scopes)

Execute business logic within an isolated domain and storage context:

```
use AlexKassel\DomainCore\Facades\DomainContext;
use AlexKassel\DomainCore\DTOs\StorageContext;

// Database Scope:
DomainContext::using('automotive-leasing', 'primary', function (StorageContext $context) {
    // Eloquent models automatically resolve connection and prefix
    $item = new App\Models\LeasingOffer();
    $item->title = 'Audi A4 Lease';
    $item->save();
});

// Filesystem Scope:
DomainContext::using('automotive-leasing', 'raw-html', function (StorageContext $context) {
    $disk = DomainContext::disk(); // Returns Laravel Filesystem disk ('s3')
    $disk->put('payload_123.html', $htmlContent);
});
```

---

### 3. Context-Aware Base Eloquent Models

[](#3-context-aware-base-eloquent-models)

Extend `ContextAwareModel` or use `HasDomainContextTrait`:

```
use AlexKassel\DomainCore\Database\Models\ContextAwareModel;

class LeasingOffer extends ContextAwareModel
{
    protected $table = 'offers';
    protected $fillable = ['title', 'price', 'vin'];
}
```

#### Static Domain Binding &amp; Hijacking Protection

[](#static-domain-binding--hijacking-protection)

For models permanently bound to a specific domain that must ignore outer ambient scopes:

```
class ArchiveOffer extends ContextAwareModel
{
    protected ?string $explicitDomain = 'automotive-leasing';
    protected ?string $explicitContext = 'archive';
    protected $table = 'archives';
}
```

---

### 4. Running Multi-Database Migrations

[](#4-running-multi-database-migrations)

`MigrationManager` automatically filters relational database contexts and skips non-relational storage:

```
use AlexKassel\DomainCore\Contracts\MigrationManagerInterface;

$migrationManager = app(MigrationManagerInterface::class);

$reports = $migrationManager->migrate(
    domainSlug: 'automotive-leasing',
    contextSlug: 'primary',
    force: true
);
```

---

### 5. CLI Execution &amp; Distributed Lock Management

[](#5-cli-execution--distributed-lock-management)

Execute batch jobs across domains safely with distributed locking and signal traps:

```
use AlexKassel\DomainCore\Contracts\CommandRunnerInterface;
use AlexKassel\DomainCore\DTOs\DomainProfile;

$runner = app(CommandRunnerInterface::class);

$options = $runner->parseCliOptions([
    'all' => true,
    'domains' => 'domain-one,domain-two',
    'context' => 'primary',
    'lock-ttl' => 300,
]);

$targetDomains = $runner->resolveTargetDomains($options);

foreach ($targetDomains as $domain) {
    $report = $runner->executeDomain(
        domain: $domain,
        componentKey: 'scraper-job',
        callback: function (DomainProfile $profile) {
            // Execution protected by distributed lock
            return 42; // Items processed count
        },
        options: $options
    );
}
```

---

Commands
--------

[](#commands)

All package commands are grouped under the `domain:` namespace:

CommandDescription`domain:status`Display registration, connection, driver, and prefix/path across domains`domain:migrate`Execute database migrations across registered domain storage contexts`domain:cache`Compile and atomically cache registered domain contexts for production`domain:clear`Clear compiled domain context cache`domain:make-domain`Scaffold a new domain package skeleton---

Testing
-------

[](#testing)

Run unit and integration test suites:

```
php artisan test -c packages/alex-kassel/laravel-domain-core/phpunit.xml
```

---

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance100

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

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

Total

5

Last Release

0d ago

Major Versions

v1.0.0 → v2.0.02026-08-25

### Community

Maintainers

![](https://www.gravatar.com/avatar/f11bb887e4e2c6eb34ec331939e34acf86591a4a2cafce3e9e7bbe9aeb950708?d=identicon)[Alexander Macenko](/maintainers/Alexander%20Macenko)

---

Top Contributors

[![alex-kassel](https://avatars.githubusercontent.com/u/144229516?v=4)](https://github.com/alex-kassel "alex-kassel (41 commits)")

---

Tags

domain-drivenlaravelmulti-databaseconsolelaravelscaffoldingeloquentartisanmigrationsDomain Drivenmulti-databasedomain-registrylock-management

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/alex-kassel-laravel-domain-core/health.svg)

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

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

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.9M113](/packages/mongodb-laravel-mongodb)[aedart/athenaeum

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

265.2k](/packages/aedart-athenaeum)[laravel/ai

The official AI SDK for Laravel.

1.1k4.6M341](/packages/laravel-ai)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k16.3M158](/packages/laravel-pulse)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9922.4M147](/packages/roots-acorn)

PHPackages © 2026

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