PHPackages                             rokke/contracts - 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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. rokke/contracts

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

rokke/contracts
===============

Rokke Contracts – Public platform interfaces and shared vocabulary for the Rokke ecosystem.

0.1.0(today)00MITPHPPHP &gt;=8.4CI passing

Since Jun 30Pushed todayCompare

[ Source](https://github.com/rokke-php/contracts)[ Packagist](https://packagist.org/packages/rokke/contracts)[ Docs](https://rokke.dev)[ RSS](/packages/rokke-contracts/feed)WikiDiscussions main Synced today

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

rokke/contracts
===============

[](#rokkecontracts)

[![CI](https://github.com/rokke-php/contracts/actions/workflows/ci.yml/badge.svg)](https://github.com/rokke-php/contracts/actions/workflows/ci.yml)[![Latest Version](https://camo.githubusercontent.com/63c33b73922798853fa470598c10435cf9263ccaf50f02a33cce7fd8c029829a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f726f6b6b652d7068702f636f6e7472616374733f6c6162656c3d76657273696f6e)](https://github.com/rokke-php/contracts/releases)[![PHP](https://camo.githubusercontent.com/755ca4b86b940e73511525af12859edb239dd9c424cde1036f789bf4f574c389/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344382e342d383839326265)](https://www.php.net)[![License](https://camo.githubusercontent.com/0738d51724359a74ad8525904574fb552dfbef6e6dc637e48091cac9db2c124e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f726f6b6b652d7068702f636f6e747261637473)](LICENSE)

Public platform contracts for the [Rokke Framework](https://rokke.dev) — the interfaces and shared vocabulary that define how the platform and its modules communicate.

What this is
------------

[](#what-this-is)

`rokke/contracts` is the dependency anchor of the Rokke ecosystem. Platform modules (`rokke/http`, `rokke/orm`, `rokke/queue`, …) depend on this package to implement platform extension points, without knowing anything about the runtime engine.

```
rokke/contracts          ← you are here
      ↑
      ├── rokke/runtime
      ├── rokke/http
      ├── rokke/orm
      └── rokke/queue

```

This package contains only interfaces and enums. No implementations, no runtime dependencies — just the language of the platform.

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

[](#installation)

```
composer require rokke/contracts
```

Requires PHP 8.4+.

Contracts
---------

[](#contracts)

### `Rokke\Contracts\Module\ModuleInterface`

[](#rokkecontractsmodulemoduleinterface)

Every platform module implements this. The runtime discovers, boots, and stops modules through this interface.

```
use Rokke\Contracts\Module\ModuleInterface;

final class HttpModule implements ModuleInterface
{
    public function name(): string { return 'http'; }
    public function boot(): void { /* register services */ }
    public function start(): void { /* start server */ }
    public function stop(): void { /* graceful shutdown */ }
    public function health(): bool { return true; }
    public function dependencies(): array { return []; }
}
```

### `Rokke\Contracts\Lifecycle\LifecycleEventsInterface`

[](#rokkecontractslifecyclelifecycleeventsinterface)

Subscribe to application lifecycle events. Modules use this to react to state changes without controlling transitions.

```
use Rokke\Contracts\Lifecycle\LifecycleEventsInterface;

$lifecycle->onRunning(function (): void {
    // application is fully started
});

$lifecycle->onStopping(function (): void {
    // drain in-flight requests
});
```

Available hooks: `onBootstrapping`, `onStarting`, `onRunning`, `onStopping`, `onStopped`.

### `Rokke\Contracts\Lifecycle\ApplicationState`

[](#rokkecontractslifecycleapplicationstate)

Enum representing the application lifecycle state. Used as shared vocabulary when subscribing to lifecycle events.

```
Created → Bootstrapping → Starting → Running → Stopping → Stopped

```

### `Rokke\Contracts\Pipeline\PipelineInterface`

[](#rokkecontractspipelinepipelineinterface)

Fluent pipeline — send a payload through middleware layers to a final handler.

```
$result = $pipeline
    ->send($request)
    ->through([$authMiddleware, $loggingMiddleware])
    ->then(fn ($req) => $handler->handle($req));
```

### `Rokke\Contracts\Container\ServiceContainerInterface`

[](#rokkecontractscontainerservicecontainerinterface)

Dependency injection container extending PSR-11. Supports singleton, scoped, transient, and pooled bindings.

```
$container->singleton(CacheInterface::class, RedisCache::class);
$container->pooled(DatabaseInterface::class, fn () => new Connection(), min: 2, max: 10);
```

### `Rokke\Contracts\Resources\ResourceProviderInterface`

[](#rokkecontractsresourcesresourceproviderinterface)

Consume pooled resources. `acquire` checks out a resource; `release` returns it to the pool.

```
$connection = $resources->acquire('database');
try {
    // use $connection
} finally {
    $resources->release('database', $connection);
}
```

### `Rokke\Contracts\Context\ContextInterface`

[](#rokkecontractscontextcontextinterface)

Per-coroutine isolated state. Set values at the start of a request; they disappear automatically when the coroutine ends.

```
$context->set('user', $authenticatedUser);
$user = $context->get('user');
```

### `Rokke\Contracts\Events\EventBusInterface`

[](#rokkecontractseventseventbusinterface)

Dispatch domain events synchronously, as a coroutine, in the background, or across nodes.

```
$bus->dispatchSync(new UserRegistered($user));
$bus->dispatchBackground(new SendWelcomeEmail($user));
```

### `Rokke\Contracts\Configuration\ConfigurationInterface`

[](#rokkecontractsconfigurationconfigurationinterface)

Read configuration, environment variables, and secrets.

```
$dsn    = $config->env('DATABASE_URL');
$apiKey = $config->secret('STRIPE_KEY');
$debug  = $config->get('app.debug', false);
```

### `Rokke\Contracts\Time\ClockInterface`

[](#rokkecontractstimeclockinterface)

Testable time abstraction.

```
$now = $clock->now(); // DateTimeImmutable
```

Governing criterion
-------------------

[](#governing-criterion)

A contract lives here if and only if **multiple legitimate implementations can exist outside the runtime engine**.

- `ModuleInterface` → any module author implements it → **here**
- `WorkerManagerInterface` → only the runtime implements it → **rokke/runtime**

Stability
---------

[](#stability)

This package is intentionally the most stable in the Rokke ecosystem. Breaking changes require architectural justification. Treat every interface here as a signed API contract.

New interfaces start as internal contracts inside their first module and are promoted here only after two or more independent modules prove the abstraction.

License
-------

[](#license)

MIT

###  Health Score

39

—

LowBetter than 85% of packages

Maintenance100

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 63.6% 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

Unknown

Total

1

Last Release

0d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/55115722?v=4)[Fernando Duarte](/maintainers/ferchd)[@ferchd](https://github.com/ferchd)

---

Top Contributors

[![ferchd](https://avatars.githubusercontent.com/u/55115722?v=4)](https://github.com/ferchd "ferchd (7 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (4 commits)")

---

Tags

contractsinterfacesphpphp84rokkephpinterfacescontractsplatform

###  Code Quality

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/rokke-contracts/health.svg)

```
[![Health](https://phpackages.com/badges/rokke-contracts/health.svg)](https://phpackages.com/packages/rokke-contracts)
```

###  Alternatives

[symfony/contracts

A set of abstractions extracted out of the Symfony components

3.9k65.5M130](/packages/symfony-contracts)[symfony/translation-contracts

Generic abstractions related to translation

2.6k730.8M606](/packages/symfony-translation-contracts)[symfony/cache-contracts

Generic abstractions related to caching

2.4k324.3M290](/packages/symfony-cache-contracts)[symfony/http-client-contracts

Generic abstractions related to HTTP clients

2.0k419.3M390](/packages/symfony-http-client-contracts)

PHPackages © 2026

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