Skip to content

Larch

Architecture rules for Laravel apps, as a Pest plugin. Larch checks which module uses which, and points at the file and line of every link that breaks a rule.

Four modules drawn as larch needle clusters. The link from Billing to Inventory breaks a rule. Billing Inventory Catalog Shared
Billing reaches Inventory through a facade. Larch draws that link, and fails it.
arch('billing uses only shared, and the public API of catalog')
->expect(module('Billing'))
->toOnlyDependOn(module('Shared'), module('Catalog')->publicApi())
->via(Edge::all());
Module Billing may only depend on Shared, Catalog (public API). 1 link breaks it:
Modules/Billing/app/Actions/ChargeOrder.php:18
Modules\Billing\Actions\ChargeOrder uses Modules\Inventory\Internal\StockLedger
through the facade Modules\Shared\Facades\Stock, bound in Modules/Inventory/app/Providers/InventoryServiceProvider.php:13
Billing may not depend on Inventory.

Sees what imports hide

Facades, container keys, event listeners and dispatched jobs link modules without an import. Larch reads them from the booted app.

Rules on the app, too

Routes need their middleware, models need a policy, queued jobs set retry limits.

Adopt it today

A baseline accepts the violations an app already has, so CI fails only on new ones.

A map of your modules

php artisan larch:graph exports every link between modules, as JSON or as an HTML report.