nwidart / larch
Architecture rules for Laravel apps that see facades, the container, events and routes. A Pest plugin.
Requires
- php: ^8.3
- nikic/php-parser: ^5.7
- pestphp/pest: ^4.3|^5.0
Requires (Dev)
- laravel/framework: ^12.0|^13.0
- laravel/pint: ^1.20
- phpstan/phpstan: ^2.1
Suggests
- laravel/framework: Needed by via() and toIgnoreEventsOf(), which read the booted app.
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-25 18:22:53 UTC
README
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:
- Getting started
- Guides: module boundaries, runtime links, app rules, baseline, graph export, Mortise
- Reference: every rule, subject, link kind and option
License
MIT. See LICENSE.md.
