Skip to content

Contracts

All interfaces of the Jardis platform, one package, zero implementations.

Introduction

In a hexagonal architecture, everything depends on interfaces: domain code imports only contracts, adapters implement them, and wiring happens at boot time. When these interfaces are scattered across dozens of packages, circular dependencies and release chaos arise.

jardissupport/contracts solves this radically: a single package contains all interfaces, enums, Value Objects and exceptions of the entire Jardis platform. Not a single implementation. Every Jardis package (whether Core, Adapter, Support or Tools) imports jardissupport/contracts and finds its contracts there.

  • Zero implementations — interfaces, enums and base exceptions only
  • Single source of truth — one dependency instead of dozens
  • PSR-first — PSR-3 (Log), PSR-11 (Container), PSR-14 (Events), PSR-16 (Cache), PSR-18 (HTTP) where standards exist
  • Interface Segregation — Reader/Writer separation, granular query builder interfaces

Installation

bash
composer require jardissupport/contracts

GitHub: jardisSupport/contracts

This package is automatically installed as a dependency of all Jardis packages.

Namespace Structure

All interfaces live under JardisSupport\Contract\:

JardisSupport\Contract\
├── Auth\              ← Authentication, RBAC, sessions, tokens
├── ClassVersion\      ← Versioned class resolution
├── Connection\        ← Base lifecycle (connect/disconnect)
├── Data\              ← Hydration, identity, FieldMapper
├── DbConnection\      ← PDO connections, connection pool
├── DbQuery\           ← SQL query builder
├── DbSchema\          ← Schema analysis
├── DotEnv\            ← Environment variables
├── EventListener\     ← Event listener registration
├── Filesystem\        ← Filesystem abstraction
├── Kernel\            ← DDD kernel, BoundedContext, responses
├── Mailer\            ← Email sending
├── Messaging\         ← Multi-transport messaging
├── Repository\        ← Generic CRUD
├── Scheduling\        ← Cron and task scheduling
├── Secret\            ← Encryption
├── Validation\        ← Object validation
└── Workflow\          ← Multi-step processes

Interface Overview by Domain

Kernel

The heart of the DDD architecture:

InterfaceDescription
DomainKernelInterfaceService locator for BoundedContexts — nullable PSR services + Jardis services
BoundedContextInterfacehandle(className, ...params): mixed — pass-through resolver, inherits payload+version. context(className, payload, version): mixed — fresh BC entry point, accepts only BC subclasses
ContextResponseInterfaceMutable carrier for data, events, errors and sub-results
DomainResponseInterfaceImmutable final response with HTTP-like status

Auth

Interface / EnumDescription
AuthenticatorInterfaceauthenticate(Credential): AuthResult
GuardInterfacecheck(session, permission): bool, authorize(session, permission): void
SessionInterfaceAuthenticated session with identity and metadata
PasswordHasherInterfacehash(), verify()
TokenStoreInterfaceToken persistence: store(), find(), revoke(), revokeAllForSubject()
HashedTokenInterfaceStored token hash
CredentialInterfaceLogin credential (password, API key, token)
CredentialTypeEnum: Password, ApiKey, Token
TokenTypeEnum: Access, Refresh, ApiKey, Verification, PasswordReset

Data

InterfaceDescription
HydrationInterfaceEntity hydration, change tracking, clone, diff, toArray
IdentityInterfaceUUID v4/v5/v7, NanoID
FieldMapperInterfaceBidirectional key translation

Repository

Interface / ClassDescription
RepositoryInterfaceinsert(), update(), delete(), findById(), findByQuery(), exists()
PkStrategyEnum: AUTOINCREMENT, INTEGER, NONE
PersistExceptionException on write errors
RecordNotFoundExceptionException when record is not found

DbConnection

InterfaceDescription
DbConnectionInterfacePDO wrapper with transactions and reconnect
ConnectionPoolInterfaceRead/write splitting with health checks
DatabaseConfigInterfaceDSN, credentials, options

DbQuery

Granular interfaces for the SQL builder:

InterfaceDescription
DbQueryBuilderInterfaceSELECT (CTE, window, subquery, union, ...)
DbInsertBuilderInterfaceINSERT
DbUpdateBuilderInterfaceUPDATE + WHERE
DbDeleteBuilderInterfaceDELETE + WHERE
DbWhereConditionInterfaceWHERE, AND, OR, JSON conditions
DbQueryConditionBuilderInterfaceComparison operators
DbJoinInterfaceINNER/LEFT JOIN
DbOrderLimitInterfaceORDER BY, LIMIT, OFFSET
DbWindowBuilderInterfaceWindow functions
DbSqlGeneratorInterfacetoSql(), getBindings()

Filesystem

InterfaceDescription
FilesystemInterfaceCombines reader + writer
FilesystemReaderInterfaceread(), readStream(), exists(), size(), mimeType(), listContents()
FilesystemWriterInterfacewrite(), writeStream(), delete(), copy(), move(), createDirectory()
FilesystemServiceInterfaceFactory for filesystem instances
FileInfoInterfaceDTO for directory listing

Messaging

Interface / ClassDescription
MessagingServiceInterfaceFacade: publish() + consume()
MessagePublisherInterfacePublisher
MessageConsumerInterfaceConsumer
MessageHandlerInterfaceCallback contract
MessageExceptionBase exception
ConnectionExceptionBroker connection error
PublishExceptionPublish error
ConsumerExceptionConsume error

Further Domains

DomainInterfaces
SchedulingScheduleInterface, ScheduledTaskInterface, CronExpressionInterface, ConstraintInterface, ScheduleViolation
ValidationValidatorInterface, ValueValidatorInterface, ValidationResult
WorkflowWorkflowInterface, WorkflowBuilderInterface, WorkflowNodeBuilderInterface, WorkflowConfigInterface, WorkflowContextInterface, WorkflowResultInterface
MailerMailerInterface, MailMessageInterface, MailTransportInterface, MailerExceptionInterface
DotEnvDotEnvInterface
SecretSecretResolverInterface, SecretResolutionException
ClassVersionClassVersionInterface, ClassVersionConfigInterface
ConnectionConnectionInterface (base lifecycle)
EventListenerEventListenerRegistryInterface (gap in PSR-14: listener registration)

Design Principles

PSR-first

DomainKernelInterface injects PSR interfaces directly:

  • PSR-3 LoggerInterface for logging
  • PSR-11 ContainerInterface for service resolution
  • PSR-14 EventDispatcherInterface for events
  • PSR-16 CacheInterface for caching
  • PSR-18 ClientInterface for HTTP

Jardis contracts only exist where no PSR standard applies.

Nullable Services

All infrastructure services in the kernel are nullable:

php
$cache = $kernel->cache();           // ?CacheInterface
$logger = $kernel->logger();          // ?LoggerInterface
$mailer = $kernel->mailer();          // ?MailerInterface

Domain code must check availability. No service is guaranteed.

Reader/Writer Separation

php
// Read-only BoundedContext receives only the reader
public function __construct(
    private readonly FilesystemReaderInterface $storage,
) {}

// Full-access service receives both
public function __construct(
    private readonly FilesystemInterface $storage,
) {}

Enum-based Strategies

php
use JardisSupport\Contract\Repository\PrimaryKey\PkStrategy;

$repository->insert('users', 'id', $values, PkStrategy::NONE);

Instead of string constants, all strategies and types use PHP 8.1+ enums.

Dependency Direction

JardisTools   → JardisAdapter → JardisSupport → JardisCore
                    |                |               |
          JardisSupport\Contract ←←←←←←←←←←←←←←←←←←

All arrows point inward toward the contract package. Domain code never imports adapter code directly.