Guard
mago guard enforces architectural boundaries and structural conventions across a PHP project. It covers the same ground as deptrac and arkitect, in a single binary running off Mago's parser.
The tool has two halves: the perimeter guard validates dependencies between layers, and the structural guard enforces conventions on the symbols themselves.
Perimeter guard
The perimeter guard validates dependency edges. It ensures that different parts of an application only talk to each other in ways you have explicitly allowed, so the domain stays free of infrastructure leaks and the UI cannot reach past the application layer.
Typical rules:
- The
Domainlayer must not depend on any other layer. - The
UIlayer can depend onApplicationbut not the other way around. - A specific module is only allowed to use an approved list of libraries.
Structural guard
The structural guard enforces conventions on the symbols themselves: their names, modifiers, supertypes, attributes, and the shape of their containing namespace.
Typical rules:
- All classes in
App\Http\Controllersmust befinaland end inController. - Interfaces under
Domainmust end withInterface. - A specific namespace may only contain
enumdefinitions.
Where to next
- Usage: the common commands and what their output looks like.
- Command reference: every flag
mago guardaccepts. - Configuration reference: every option Mago accepts under
[guard].