nwidart/larch
Larch

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.
Related Packages
Method-level and class-level maintainability limits (complexity, body lines, par...
Generadores y reglas de arquitectura para Model Domain Architecture (MDA) en Lar...
Architecture ratchets for Pest: rules that find offenders with a real PHP parser...
Version History
| Version | Released | PHP | License |
|---|---|---|---|
| v0.1.0 | ^8.3 | MIT |