PHPackages                             satheez/laravel-message-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. [Queues &amp; Workers](/categories/queues)
4. /
5. satheez/laravel-message-contracts

ActiveLibrary[Queues &amp; Workers](/categories/queues)

satheez/laravel-message-contracts
=================================

Define, validate, version, and serialize message contracts shared between Laravel services.

v1.0.2(2w ago)02MITPHPPHP ^8.2CI passing

Since May 21Pushed 2w agoCompare

[ Source](https://github.com/satheez/laravel-message-contracts)[ Packagist](https://packagist.org/packages/satheez/laravel-message-contracts)[ Docs](https://github.com/satheez/laravel-message-contracts)[ RSS](/packages/satheez-laravel-message-contracts/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (2)Dependencies (9)Versions (4)Used By (0)

Laravel Message Contracts
=========================

[](#laravel-message-contracts)

A Laravel package for defining, validating, versioning, documenting, and testing the JSON payloads your services exchange.

[![Laravel Message Contracts](docs/assets/banner.png)](docs/assets/banner.png)[![CI](https://github.com/satheez/laravel-message-contracts/actions/workflows/ci.yml/badge.svg)](https://github.com/satheez/laravel-message-contracts/actions)[![Tests](https://github.com/satheez/laravel-message-contracts/actions/workflows/run-tests.yml/badge.svg)](https://github.com/satheez/laravel-message-contracts/actions/workflows/run-tests.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/c778fe736b3908c4ca156ecfec84d226f2733084caffd013baf52d3593f6e32a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7361746865657a2f6c61726176656c2d6d6573736167652d636f6e7472616374732e737667)](https://packagist.org/packages/satheez/laravel-message-contracts)[![Total Downloads](https://camo.githubusercontent.com/73daff7b6daab589111d35bb05e8e9727222b434a77631911355bd3ae1e0031f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7361746865657a2f6c61726176656c2d6d6573736167652d636f6e7472616374732e737667)](https://packagist.org/packages/satheez/laravel-message-contracts)[![PHP](https://camo.githubusercontent.com/187240af044d09d5b14a1d9d9ebdf3f7a993e4c7bc09bdb46b4ba661a891bf5b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e322532422d626c7565)](https://www.php.net)[![Laravel](https://camo.githubusercontent.com/3c947bde5893eab66cfda333d4d46780b85eb09acdb216efe9330b2e77532c5f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31302532302537432532303131253230253743253230313225323025374325323031332d726564)](https://laravel.com)[![License](https://camo.githubusercontent.com/67e683f99cb5a7473bafddaa0c06711a5bc957ba300bc8071c6d6cd03dc2006d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7361746865657a2f6c61726176656c2d6d6573736167652d636f6e7472616374732e737667)](LICENSE.md)

Laravel Message Contracts turns queue, event, webhook, and broker payloads into explicit PHP classes. A contract class gives each message a stable name, an integer version, Laravel validation rules, examples, generated JSON Schema, AsyncAPI documentation, compatibility snapshots, and test assertions.

The package is transport-agnostic. It does not replace RabbitMQ, SQS, Kafka, Redis, Laravel queues, webhooks, an outbox, retries, or delivery guarantees. It protects the JSON message body that moves through those systems.

Use it when multiple producers, consumers, services, or teams need a shared payload boundary that is stricter than plain arrays but lighter than a full schema registry.

Highlights
----------

[](#highlights)

- Define one source of truth for every message payload.
- Validate outgoing producer payloads before serialization.
- Validate incoming consumer payloads before business logic reads them.
- Reject unknown payload keys in strict mode.
- Keep `V1`, `V2`, and later contract versions registered side by side.
- Export JSON Schema for non-Laravel consumers.
- Generate AsyncAPI 2.6.0 documentation from registered contracts.
- Detect breaking payload changes in CI with snapshots.
- Test payloads with Pest or PHPUnit assertion helpers.
- Integrate with Spatie Laravel Data when your payload already has a data class.

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

[](#requirements)

RequirementVersionPHP`^8.2`Laravel`^10.0`, `^11.0`, `^12.0`, or `^13.0`Installation
------------

[](#installation)

```
composer require satheez/laravel-message-contracts
php artisan vendor:publish --tag=message-contracts-config
```

Optionally publish the generator stub:

```
php artisan vendor:publish --tag=message-contracts-stubs
```

See [Installation](docs/installation.md) for the full setup flow.

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

[](#quick-start)

Imagine you publish a `user.registered` event that an email service, analytics pipeline, and billing service all consume. A message contract makes the payload shape explicit, validated, and versioned so every consumer knows exactly what to expect.

Generate a contract class:

```
php artisan make:message-contract UserRegistered \
  --contract-version=1 \
  --contract=user.registered
```

Define the payload rules in the generated class:

```
use Satheez\MessageContracts\Contracts\MessageContract;

final class UserRegisteredV1Message extends MessageContract
{
    public static function contract(): string
    {
        return 'user.registered';
    }

    public static function version(): int
    {
        return 1;
    }

    public static function rules(): array
    {
        return [
            'user_id' => ['required', 'integer'],
            'email' => ['required', 'email'],
            'registered_at' => ['required', 'date'],
        ];
    }
}
```

Register it in `config/message-contracts.php`:

```
'contracts' => [
    App\MessageContracts\UserRegisteredV1Message::class,
],
```

Create and serialize a producer message:

```
$message = UserRegisteredV1Message::message(
    payload: [
        'user_id' => 123,
        'email' => 'john@example.com',
        'registered_at' => now()->toISOString(),
    ],
    meta: [
        'trace_id' => 'req-7f1c4c2a',
    ],
);

$json = $message->toJson();
```

Parse and validate a consumer message:

```
use Satheez\MessageContracts\DTO\Message;

$message = Message::fromJson($json);
$message->validateOrFail();

$userId = $message->payload('user_id');
```

The default envelope contains `contract`, `version`, `payload`, and optional `meta` keys. Metadata such as `message_id` and `created_at` can be configured.

Important Concepts
------------------

[](#important-concepts)

ConceptSummaryContract nameStable dot-notation name such as `user.registered`. Do not include the version.VersionInteger starting at `1`. Add a new version for breaking payload changes.Strict modeRejects payload keys that are not declared in `rules()`. Enabled by default.RegistryResolves incoming messages by `contract` and `version`.SnapshotCaptures current schemas so CI can detect breaking changes later.For breaking changes, create `UserRegisteredV2Message` and keep V1 registered until consumers migrate.

Command Overview
----------------

[](#command-overview)

CommandPurpose`make:message-contract`Scaffold a versioned contract class.`message-contracts:list`Show registered contracts.`message-contracts:validate`Validate a raw payload or full envelope.`message-contracts:validate-examples`Validate every contract `example()`.`message-contracts:export-json-schema`Export payload or envelope JSON Schemas.`message-contracts:export-asyncapi`Export AsyncAPI documentation.`message-contracts:snapshot`Save the current contract schema snapshot.`message-contracts:check-breaking-changes`Compare current contracts to a previous snapshot.See [Checks](docs/checks.md), [Output formats](docs/output.md), and [CI](docs/ci.md) for command options and CI examples.

Documentation
-------------

[](#documentation)

GuideCovers[Installation](docs/installation.md)Composer install, publishing config and stubs, first contract setup[Usage guide](docs/usage.md)Defining, registering, producing, consuming, and validating messages[Configuration](docs/configuration.md)`config/message-contracts.php` options, strict mode, metadata, schema export[Architecture](docs/architecture.md)Core classes, producer flow, consumer flow, and generated docs[Output formats](docs/output.md)Message envelopes, list JSON, JSON Schema, AsyncAPI, and snapshots[Checks](docs/checks.md)Artisan validation, schema, example, and compatibility checks[CI](docs/ci.md)GitHub Actions patterns for package and application contract checks[Comparison](docs/comparison.md)How this package compares with plain arrays, Form Requests, JSON Schema, AsyncAPI, and schema registries[Examples and recipes](docs/examples.md)Versioning, testing helpers, example validation, Laravel Jobs, and producer-side patterns[FAQ](docs/faq.md)Common usage, versioning, strict mode, envelope, schema, and Spatie Data questionsContributing
------------

[](#contributing)

See [CONTRIBUTING.md](CONTRIBUTING.md) for local setup, coding standards, and pull request guidelines.

Changelog
---------

[](#changelog)

All notable changes are documented in [CHANGELOG.md](CHANGELOG.md).

License
-------

[](#license)

Laravel Message Contracts is open-sourced software licensed under the [MIT license](LICENSE.md).

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance96

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

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

2

Last Release

18d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6590c21841f4323f7322cb865bc535b1b58b00b636aba0c3bcc08a1b1f53819c?d=identicon)[Satheez](/maintainers/Satheez)

---

Top Contributors

[![isatheez](https://avatars.githubusercontent.com/u/252316041?v=4)](https://github.com/isatheez "isatheez (8 commits)")[![satheez](https://avatars.githubusercontent.com/u/11453046?v=4)](https://github.com/satheez "satheez (3 commits)")

---

Tags

messagecontractslaravelvalidationpayloadmicroservices

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/satheez-laravel-message-contracts/health.svg)

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

###  Alternatives

[convenia/pigeon

3234.2k](/packages/convenia-pigeon)[mpbarlow/laravel-queue-debouncer

A wrapper job for debouncing other queue jobs.

63792.6k1](/packages/mpbarlow-laravel-queue-debouncer)[ecotone/laravel

Ecotone for Laravel — CQRS, Event Sourcing, Sagas, Durable Workflows, and Outbox on top of Laravel Queue, via PHP attributes.

21313.7k3](/packages/ecotone-laravel)[iamfarhad/laravel-rabbitmq

Native ext-amqp RabbitMQ queue driver for Laravel production workloads with connection pooling, publisher confirms, Horizon support, Octane support, quorum queues, and high-performance workers

3317.9k](/packages/iamfarhad-laravel-rabbitmq)[baklysystems/laravel-chat-messenger

Laravel chat package

121.8k](/packages/baklysystems-laravel-chat-messenger)

PHPackages © 2026

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