Search by

nwidart / larch

nWidart

Architecture rules for Laravel apps that see facades, the container, events and routes. A Pest plugin.

v0.1.0 2026-11-24 20:18 UTC

This package is auto-updated.

Last update: 2026-11-25 18:22:53 UTC


README

CI Latest Version on Packagist Total Downloads PHP Version License

Larch: architecture rules for Laravel apps, as a Pest plugin

Architecture rules for Laravel apps, as a Pest plugin. Larch checks which module uses which, and prints every link that breaks a rule with the file and line it comes from.

Larch reads links from the code, and from the booted app: facades, container keys, event listeners and dispatched jobs. Import-based tools cannot see those.

Larch is in early development.

Install

composer require nwidart/larch --dev

Larch needs PHP 8.3 or later and Pest 4.3 or later.

Example

Name the modules once, in tests/Pest.php:

use function Nwidart\Larch\larch;

larch()
    ->modules('Modules\*')
    ->publicApi('Contracts', 'Events');

Then write rules:

use Nwidart\Larch\Edge;

use function Nwidart\Larch\module;
use function Nwidart\Larch\modules;

arch('billing uses only shared, and the public API of catalog')
    ->expect(module('Billing'))
    ->toOnlyDependOn(module('Shared'), module('Catalog')->publicApi())
    ->via(Edge::all());

arch('no module is in a cycle')
    ->expect(modules())
    ->toHaveNoCycles();

A failure names each link that breaks the rule:

  Modules/Billing/app/Actions/ChargeOrder.php:16
    Modules\Billing\Actions\ChargeOrder uses Modules\Catalog\Pricing\PriceEngine
    It is internal to Catalog. The public API of a module is: Contracts, Events.

Documentation

Read the full documentation at nwidart.github.io/larch:

License

MIT. See LICENSE.md.