shipmonk / modulint
Enforce architecture by defining modules with allowed dependencies. Detects forbidden, uncovered, missing and unused module dependencies in PHP projects.
Requires
- php: ^8.1
- composer-runtime-api: ^2.0
- nikic/php-parser: ^4.18 || ^5.0
Requires (Dev)
- editorconfig-checker/editorconfig-checker: ^10.7.0
- ergebnis/composer-normalize: ^2.19.0
- phpstan/phpstan: ^2.2.0
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^10.5.62
- shipmonk/coding-standard: ^0.2.0
- shipmonk/composer-dependency-analyser: ^1.8
- shipmonk/name-collision-detector: ^2.1.1
- shipmonk/phpstan-rules: ^4.3
This package is auto-updated.
Last update: 2026-05-28 09:56:16 UTC
README
- ð§ą Module-aware: define modules over your codebase and declare which other modules each one may depend on
- ðĶ Strict: detects forbidden, uncovered, missing and unused module dependencies
- ðŠķ Lightweight: single static analysis pass over your sources
- âïļ Configurable: pure PHP config, modules identified by your own enum
- âĻ Compatible: PHP 8.1+
Why?
Once a codebase grows, hand-written rules like "the Logging module must not depend on Doctrine" tend to drift. shipmonk/modulint lets you declare those rules as data and enforce them in CI.
A module is a named bag of paths (files and/or directories). For each module you declare which other modules it is allowed to depend on. Modulint walks every PHP file in each module, parses it, resolves used class-like symbols (classes, interfaces, traits, enums) via Composer's autoloader, looks up which module they belong to, and reports:
- Forbidden dependency â module
Xuses a class belonging to moduleY, andYis not inX's allowed dependencies. - Uncovered dependency â module
Xuses a class that is not part of any declared module. - Missing module â a file inside a "fully-modulized" directory is not covered by any module.
- Unused dependency â module
Xdeclares a dependency on moduleYbut never actually uses anything from it.
Installation
composer require --dev shipmonk/modulint
Usage
Create modulint.php in your project root:
<?php declare(strict_types = 1); use ShipMonk\Modulint\Config\Configuration; use ShipMonk\Modulint\Module; use ShipMonk\Modulint\ModuleIdentifier; enum AppModule: string implements ModuleIdentifier { case Api = 'Api'; case Doctrine = 'Doctrine'; case Logging = 'Logging'; case VendorDoctrine = 'VendorDoctrine'; case VendorPsrLog = 'VendorPsrLog'; } return (new Configuration()) ->addModule(new Module( AppModule::Api, paths: ['src/Api'], dependencies: [AppModule::Doctrine, AppModule::Logging], )) ->addModule(new Module( AppModule::Doctrine, paths: ['src/Doctrine'], dependencies: [AppModule::VendorDoctrine], )) ->addModule(new Module( AppModule::Logging, paths: ['src/Logging'], dependencies: [AppModule::VendorPsrLog], )) // vendors with `dependencies: null` may be depended on by anyone and never report unused/forbidden ->addModule(new Module(AppModule::VendorDoctrine, ['vendor/doctrine'], dependencies: null)) ->addModule(new Module(AppModule::VendorPsrLog, ['vendor/psr/log'], dependencies: null)) // every file under src/ must belong to some module ->addFullyModulizedDirectory('src');
Then run:
vendor/bin/modulint
Exit code is 0 when everything is clean and 1 otherwise.
Concepts
Module identifier
ModuleIdentifier is an empty marker interface extending UnitEnum. You implement it by writing your own enum. Using an enum gives you autocompletion and refactoring support, and the IDE will tell you immediately if you reference a module that does not exist.
Allowed dependencies
The dependencies constructor argument controls what a module can use:
[]â module can only use symbols defined inside itself.[OtherModule::X, OtherModule::Y]â module can additionally use symbols from those modules.nullâ module can depend on anything. Use this for vendor-bag modules so that whoever depends on them never produces a forbidden-dependency error, and modulint will not report unused dependencies for them.
A dependency on a parent module implicitly allows dependencies on its nested modules: [...] children.
Fully-modulized directories
addFullyModulizedDirectory('src') makes modulint complain about any .php file under src/ that no module claims. This is how you keep the configuration honest as code is added.
Vendor modules
A common pattern is to declare one module per relevant vendor package, pointing at vendor/<package> as its paths, with dependencies: null. That lets you assert which parts of your code may use which vendor library â typically the most useful kind of architectural rule.
Disable colored output
Set NO_COLOR to disable ANSI colors:
NO_COLOR=1 vendor/bin/modulint
Contributing
- Check your code with
composer check - Autofix coding-style with
composer fix:cs - All functionality must be tested
Supported PHP versions
- Runtime requires PHP 8.1+