PHPackages                             jardiscore/foundation - 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. jardiscore/foundation

ActiveLibrary

jardiscore/foundation
=====================

DDD Foundation - Convention-based domain orchestration with auto-assembled infrastructure services

v1.0.0(1mo ago)012↓100%proprietaryPHPPHP &gt;=8.2CI passing

Since Mar 22Pushed 1mo agoCompare

[ Source](https://github.com/jardisCore/foundation)[ Packagist](https://packagist.org/packages/jardiscore/foundation)[ Docs](https://github.com/jardisCore/foundation)[ RSS](/packages/jardiscore-foundation/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (13)Versions (3)Used By (0)

[![Build Status](https://github.com/jardisCore/foundation/actions/workflows/ci.yml/badge.svg)](https://github.com/jardisCore/foundation/actions/workflows/ci.yml/badge.svg)[![License: PolyForm Shield](https://camo.githubusercontent.com/d8fb46c82be4c5312bf3e372ac734dfdf6a8b328e9c2b2856af671adbb0600a5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d506f6c79466f726d253230536869656c642d626c75652e737667)](LICENSE.md)[![PHP Version](https://camo.githubusercontent.com/a68b290dcc313d698dc138a1111aa83eee2f143605449d7e8b5416ea6f88558f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344382e322d3737374242342e737667)](https://www.php.net/)[![PHPStan Level](https://camo.githubusercontent.com/c51bda247654363d3e30bc352674dd761a9557803a14af0226eb411d6dc0006b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c253230382d627269676874677265656e2e737667)](phpstan.neon)[![PSR-12](https://camo.githubusercontent.com/34b10db0caa29bacd49bda5c437a8de95385f036f3230b31fa605326e18da22c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f64652532305374796c652d5053522d2d31322d626c75652e737667)](phpcs.xml)[![PSR-3](https://camo.githubusercontent.com/76db838885931d8f63a37cc20c6d033675f31ac75a81dc9329d8289c8f1b042a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6f676765722d5053522d2d332d627269676874677265656e2e737667)](https://www.php-fig.org/psr/psr-3/)[![PSR-11](https://camo.githubusercontent.com/6c0874402e8c4ffbef9afa9d041ec10c657e5234692fca736c9ce564e0fc4957/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f6e7461696e65722d5053522d2d31312d627269676874677265656e2e737667)](https://www.php-fig.org/psr/psr-11/)[![PSR-16](https://camo.githubusercontent.com/0bb4bb647f0531ef86892e4c14d03f9c6541df67b97e14817590ed6ec021c549/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f43616368652d5053522d2d31362d627269676874677265656e2e737667)](https://www.php-fig.org/psr/psr-16/)[![Coverage](https://camo.githubusercontent.com/be418324328a6af0f897b5349e6b95c7e24c1ef95aff187aedcc45849fe04d41/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f7665726167652d38302532352d677265656e2e737667)](https://github.com/jardisCore/foundation)

jardiscore/foundation
=====================

[](#jardiscorefoundation)

> Part of the **[Jardis Business Platform](https://jardis.io)** — Enterprise-grade PHP components for Domain-Driven Design

Foundation is the runtime integration platform for Jardis DDD projects. It bootstraps your entire infrastructure — Cache, Database, Logger, and Messaging — from `.env` configuration alone, without a line of manual wiring. One `Domain` class scans its own directory, resolves the application root, loads the ENV cascade, and hands a fully assembled `DomainKernel` to your bounded contexts. Connection pooling, read/write splitting, multi-layer caching, and cross-domain connection sharing are active by default. `ConnectionProvider` gives every infrastructure role an explicit, typed accessor — no magic strings, no service locator patterns. Foundation does not dictate your architecture; it carries it.

---

Features
--------

[](#features)

- **Domain &amp; BoundedContext** — Convention-based base classes that auto-detect paths, bootstrap services, and expose a clean `handle()` API for inter-context communication with version-aware class resolution
- **ContextResult &amp; DomainResponse** — Two-layer result model: `ContextResult` as mutable internal transporter through BC chains (context-keyed), `DomainResponse` as immutable final answer for the outside world with aggregated data, events, errors, and metadata
- **DomainKernel with auto-assembled services** — Single orchestrator for Cache, ConnectionPool, Logger, Messaging, and Factory; each service is lazily initialized from ENV on first access, overridable at any time via setters
- **ConnectionProvider for typed DI** — No magic strings; every infrastructure role (`getWriter()`, `getCacheRedis()`, `getKafkaProducer()`, etc.) has an explicit, nullable typed accessor — the nullable return is the has-check
- **Multi-layer caching cascade** — Memory → APCu → Redis → PDO, configurable per environment; PSR-16 compliant throughout
- **Connection pool with read/write splitting** — Dedicated writer PDO plus an array of reader PDOs; the pool routes queries automatically based on operation type
- **Smart Logging with 20+ handlers** — PSR-3 compliant logger with conditional handler activation (business hours, request type, debug mode, environment); supports File, Redis Streams, Kafka, RabbitMQ, Slack, Teams, Loki, Webhook, Email, and more
- **Flexible Messaging across transports** — Redis Streams, RabbitMQ (AMQP), and Kafka supported simultaneously; priority-ordered transport chain per message, configurable entirely from ENV
- **SharedRuntime for cross-domain config** — Place a `SharedRuntime/` directory alongside your domain directories; Foundation detects it automatically and merges its `.env` into every domain that boots from the same application root
- **Cross-domain connection sharing** — `ConnectionProvider::shareInto()` and `mergeFrom()` allow domains to reuse existing PDO and Redis connections across kernel instances without re-establishing them
- **Dynamic class versioning** — `ClassVersion` support via namespace injection; swap any class implementation at runtime by version string without touching call sites

---

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

[](#installation)

```
composer require jardiscore/foundation
```

Quick Start
-----------

[](#quick-start)

Extend `Domain` in your bounded context entry point. `DomainKernel` is assembled automatically from `.env`; override `createKernel()` only when you need a domain-specific subclass.

```
use JardisCore\Foundation\Domain;
use JardisCore\Foundation\Domain\BoundedContext;
use JardisCore\Foundation\Domain\Response\DomainResponseTransformer;

class EcommerceDomain extends Domain
{
    public function placeOrder(array $orderData): DomainResponseInterface
    {
        $context = new BoundedContext($this->getKernel(), $orderData);
        $result  = $context->handle(PlaceOrder::class);

        return (new DomainResponseTransformer())->transform($result);
    }
}
```

---

Advanced Usage
--------------

[](#advanced-usage)

### Injecting pre-existing connections

[](#injecting-pre-existing-connections)

`ConnectionProvider` accepts externally managed connections on any role. Injected connections take precedence over ENV-configured ones:

```
use JardisCore\Foundation\Connection\ConnectionProvider;
use JardisCore\Foundation\Adapter\DomainKernel;

$connections = new ConnectionProvider();
$connections->setWriter($existingPdo);      // pre-wired PDO writer
$connections->setCacheRedis($sharedRedis);  // shared Redis instance

$kernel = new DomainKernel(
    appRoot: '/var/www',
    domainRoot: '/var/www/src/Ecommerce',
    connections: $connections,
);

// Override any service after construction — everything else comes from .env
$kernel->setLogger($monologLogger);

$cache  = $kernel->getCache();           // ?CacheInterface  (PSR-16)
$pool   = $kernel->getConnectionPool();  // ?ConnectionPoolInterface
$logger = $kernel->getLogger();          // ?LoggerInterface (PSR-3)
$msg    = $kernel->getMessage();         // ?MessagingServiceInterface
```

### ContextResult and DomainResponse

[](#contextresult-and-domainresponse)

Foundation uses a two-layer result model:

**ContextResult** — Mutable internal transporter through BC chains. All getters return context-keyed arrays:

```
class PlaceOrder extends EcommerceContext
{
    public function __invoke(CreateOrder $command): ContextResultInterface
    {
        // Business logic...
        return $this->getResult()
            ->setData(['orderId' => $orderId])
            ->addEvent(new OrderCreated($orderId));
    }
}
```

**DomainResponse** — Immutable final answer, built by the transformer:

```
$transformer = new DomainResponseTransformer(version: '1.0');
$response    = $transformer->transform($contextResult);

$response->getStatus();    // 200 (auto-resolved: no errors = Success)
$response->getData();      // ['PlaceOrder' => ['orderId' => 'ORD-123']]
$response->getEvents();    // ['PlaceOrder' => [OrderCreated{...}]]
$response->getErrors();    // [] (empty = success)
$response->getMetadata();  // ['duration' => 12.5, 'contexts' => ['PlaceOrder'], ...]
```

### SharedRuntime directory layout

[](#sharedruntime-directory-layout)

Place shared infrastructure configuration as a sibling of your domain directories. Foundation detects the `SharedRuntime/` directory automatically — no configuration required:

```
src/
├── Ecommerce/
