Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
f2d57e7
Cache file analyses by content hash
ChrisAbner Nov 11, 2026
527a181
Keep a warm cache untouched when host files are analysed
ChrisAbner Nov 11, 2026
d98af18
Support modules nested inside a module
ChrisAbner Nov 11, 2026
2daaf79
Let nested modules use their parent's internals and keep them under -…
ChrisAbner Nov 11, 2026
7c16bf5
Add named interfaces to depends_on
ChrisAbner Nov 11, 2026
3bf5a53
Optionally read class names from docblocks (#24)
ChrisAbner Nov 11, 2026
158305e
Anchor docblock references to the code they document
ChrisAbner Nov 11, 2026
095fde6
Check and list what changed since a git reference
ChrisAbner Nov 11, 2026
7393079
Expose the module graph and documentation as text
ChrisAbner Nov 11, 2026
5e8cac9
Document the Filament plugin
ChrisAbner Nov 11, 2026
0947b33
Make Architecture::docs() write what cordon:docs writes
ChrisAbner Nov 11, 2026
5cb1104
Check which Composer packages each module uses
ChrisAbner Nov 11, 2026
e764c2b
Keep polyfill stubs and shared classes out of the package index
ChrisAbner Nov 11, 2026
4ab841e
Optionally warn about tables shared across modules
ChrisAbner Nov 11, 2026
4c8082a
Leave out models whose table cannot be known, and stop joins at the b…
ChrisAbner Nov 11, 2026
d7a7abc
Ignore a literal table when the model's table can change elsewhere
ChrisAbner Nov 11, 2026
3cf1716
Include nested modules of affected modules in cordon:affected
ChrisAbner Nov 11, 2026
9f864bd
Fingerprint the analysis cache with the extractor class
ChrisAbner Nov 11, 2026
aa90b00
Treat an unknown kind in a cache entry as a cache miss
ChrisAbner Nov 11, 2026
122a56a
Label graph arrows with the interfaces the rules apply
ChrisAbner Nov 11, 2026
a23752e
Show both views of a nested module's public API in cordon:docs
ChrisAbner Nov 11, 2026
8dfbfda
Document what the PHPStan rules do not cover
ChrisAbner Nov 11, 2026
ea1df27
Add a version to the cordon:affected JSON report and document its shape
ChrisAbner Nov 11, 2026
f832163
Document host.tests in the config stub and the nested-consumer preced…
ChrisAbner Nov 11, 2026
86aaf3a
Test cordon:verify --since with a deleted file in a cycle
ChrisAbner Nov 11, 2026
a43b557
Warn to restore the analysis cache only from trusted branches
ChrisAbner Nov 11, 2026
d038375
Satisfy Pint and PHPStan for the final-review fixes
ChrisAbner Nov 11, 2026
1e0d1a8
Export the module graph as a C4 diagram
ChrisAbner Nov 11, 2026
2fe8181
Draw C4 violations through a relationship tag and escape backslashes
ChrisAbner Nov 11, 2026
d0466a9
Require the module map in GraphExporter::model
ChrisAbner Nov 11, 2026
45e8259
Bring the nested modules of every affected module into cordon:affected
ChrisAbner Nov 11, 2026
2882eb9
Round-trip docblock references and table uses in the cache test
ChrisAbner Nov 11, 2026
8d36f8c
Reconcile 0.5 with the released 0.4.0
ChrisAbner Nov 11, 2026
5ee93dd
Give nested modules the layer of their nearest named ancestor
ChrisAbner Nov 11, 2026
4be4a18
Read the module documentation through the cached extractor
ChrisAbner Nov 11, 2026
2031cc0
Put phpdoc-parser and illuminate/support versions in the cache finger…
ChrisAbner Nov 11, 2026
7eed812
Record the 0.5 decisions in ADRs 0021 to 0028
ChrisAbner Nov 11, 2026
858f6f3
List external_dependency, tables and nested modules in the agent skil…
ChrisAbner Nov 11, 2026
bc0f31e
Mark the Filament plugin as unpublished and the new context data as n…
ChrisAbner Nov 11, 2026
d18b51c
Complete the 0.5 changelog and add the 0.4 to 0.5 upgrade notes
ChrisAbner Nov 11, 2026
34028de
Document the cache fingerprint, the C4 escaping, the --since blind sp…
ChrisAbner Nov 11, 2026
7069572
Take the version of the replacing package for a replaced one in the c…
ChrisAbner Nov 11, 2026
da76712
Accept ADRs 0027 and 0028 and keep Architecture internal until the Fi…
ChrisAbner Nov 25, 2026
3973262
Prepare 0.5.0
ChrisAbner Nov 25, 2026
cda11ef
Count the code that subprocesses of the suite run, and apply mutants …
ChrisAbner Nov 25, 2026
ad3a991
Test the 0.5 paths that were only run in subprocesses or not at all
ChrisAbner Nov 25, 2026
e2d311c
Mutation-test the 0.5 code of the mutated classes
ChrisAbner Nov 25, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ body:
id: versions
attributes:
label: Versions
placeholder: Cordon Modulith 0.4.0, PHP 8.4, Laravel 13, nwidart/laravel-modules 13
placeholder: Cordon Modulith 0.5.0, PHP 8.4, Laravel 13, nwidart/laravel-modules 13
validations:
required: true
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/false_positive.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ body:
id: versions
attributes:
label: Versions
placeholder: Cordon Modulith 0.4.0, PHP 8.4, Laravel 13
placeholder: Cordon Modulith 0.5.0, PHP 8.4, Laravel 13
validations:
required: true
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
run: vendor/bin/pint --test

- name: Static analysis
run: vendor/bin/phpstan analyse
run: vendor/bin/phpstan analyse --memory-limit=512M

benchmark:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This file is for AI agents (and agent swarms) working on the Cordon Modulith cod

## Project in one paragraph

Cordon Modulith is a Laravel dev-dependency that verifies boundaries between modules. It statically parses PHP files (nikic/php-parser, never loading code), maps class references to modules, and runs rules (`internal_access`, `undeclared_dependency`, `cycles`, `unused_dependency`, `host_access`, `layers`, `public_api_leak`, each `error`, `warn` or `off`). Entry points: `php artisan cordon:verify` (and `cordon:docs`), `vendor/bin/cordon` (the same commands without booting Laravel, `StandaloneApplication`), the Pest expectation `toRespectBoundaries()` and the PHPStan rule. Pipeline: `ModuleResolver` → `FileCollector` → `DependencyExtractor` → `Analyzer` (cross-module edges) → `Rule`s → `Baseline` → `Reporter`.
Cordon Modulith is a Laravel dev-dependency that verifies boundaries between modules. It statically parses PHP files (nikic/php-parser, never loading code), maps class references to modules, and runs rules (`internal_access`, `undeclared_dependency`, `cycles`, `unused_dependency`, `host_access`, `layers`, `public_api_leak`, `external_dependency` and `tables`, each `error`, `warn` or `off`; `tables` is `off` by default). A module can be nested in another one, named `Parent.Child` (the dot is the separator). Entry points: `php artisan cordon:verify` (and `cordon:docs`), `vendor/bin/cordon` (the same commands without booting Laravel, `StandaloneApplication`), the Pest expectation `toRespectBoundaries()` and the PHPStan rule. Pipeline: `ModuleResolver` → `FileCollector` → `DependencyExtractor` → `Analyzer` (cross-module edges) → `Rule`s → `Baseline` → `Reporter`.

## Hard rules

Expand All @@ -14,7 +14,7 @@ Cordon Modulith is a Laravel dev-dependency that verifies boundaries between mod
4. **Zero false positives.** When unsure whether something is a dependency, don't report it and document the limitation.
5. **Do not edit `tests/Fixtures` line layout** without updating the tests that assert line numbers.
6. **Stay in your lane.** Agents only touch the files their task names. Integration across tasks is done by the maintainer.
7. **Quality gate:** `composer check` (Pint, PHPStan, Pest) must pass before you open a pull request.
7. **Quality gate:** `composer check` (Pint, PHPStan, Pest) must pass before you open a pull request. Run PHPStan through `composer analyse`: calling it directly needs `--memory-limit=512M`.

## Conventions

Expand Down
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@

All notable changes to Cordon Modulith are documented here. The project follows [Semantic Versioning](https://semver.org) from 1.0.0; before that, minor versions may contain breaking changes.

## [0.5.0] - 2026-11-25

This release adds nested modules, named interfaces, an analysis cache, checks on what changed since a git reference, rules on Composer packages and shared tables, and a C4 export. Nothing is required to upgrade: with an unchanged `config/cordon.php`, 0.5 gives the same report as 0.4, and every addition is off until you configure it. [UPGRADE.md](UPGRADE.md) lists what you may notice. The decisions behind this release are recorded in [ADR 0021](docs/adr/0021-nested-modules.md) (nested modules), [0022](docs/adr/0022-named-interfaces.md) (named interfaces), [0023](docs/adr/0023-docblock-references.md) (docblock references), [0024](docs/adr/0024-analysis-cache.md) (the analysis cache), [0025](docs/adr/0025-since-and-affected.md) (`--since` and `cordon:affected`), [0026](docs/adr/0026-external-packages.md) (external packages), [0027](docs/adr/0027-tables-rule.md) (the `tables` rule) and [0028](docs/adr/0028-text-exports-and-architecture.md) (text exports and `Architecture`).

### Added
- Modules nested inside a module, as in Spring Modulith 1.3: `nested => ['Invoices', 'Payments']` (or `true`) in the settings of a module turns those folders into the modules `Billing.Invoices` and `Billing.Payments`. Outside `Billing` they do not exist (only what `Billing` exposes is public), inside it their public API applies, a child lists its siblings in `depends_on`, and cycles, the baseline, the reports, `cordon:modules` and `cordon:graph` use the full names. A project without `nested` is unchanged. See the [configuration](https://chrisabner.github.io/Cordon-Modulith/guide/configuration#nested-modules) guide.
- Named interfaces, as in Spring Modulith: `interfaces => ['Pricing' => ['Contracts\\PriceList', 'Data\\Price*']]` in the settings of a module names part of its public API, and `depends_on => ['Catalog::Pricing']` limits a module to it. A public class of `Catalog` outside the interfaces is an `undeclared_dependency` (`Module [Billing] uses ..., which is not in the interfaces it declares on [Catalog] (Pricing).`), in `cordon:verify` and in PHPStan. `Catalog` and `Catalog::*` keep meaning the whole public API, and a project without `interfaces` is unchanged. `unused_dependency` checks each interface, `cordon:explain` lists the interfaces of a class, `cordon:why` says when a dependency is limited to some, and `cordon:graph` labels the arrow. An interface that lists a class that is not public fails `cordon:verify` with exit code `2`, and a pattern that matches no class is a warning. See the [configuration](https://chrisabner.github.io/Cordon-Modulith/guide/configuration#named-interfaces) guide.
- `cache` config key (`null` by default): a file where Cordon Modulith keeps the analysis of each PHP file, keyed by a hash of its content, so a later run only parses the files that changed. The report is the same cold, warm or without it. `cordon:verify --no-cache` skips it for one run, and a cache that cannot be read or written is reported as a warning and ignored. See the [configuration](https://chrisabner.github.io/Cordon-Modulith/guide/configuration#cache) and [CI](https://chrisabner.github.io/Cordon-Modulith/guide/ci#keeping-the-analysis-cache-between-runs) guides.
- `docblocks` config key (`false` by default): with `true`, the class names in docblock types count as dependencies, as references of a new kind (`docblock`) that every rule treats like any other. It reads `@param`, `@return`, `@var`, `@property`, `@method`, `@throws`, `@extends`, `@implements`, `@use`, `@mixin` and the bound of `@template`, including generics, unions, `array<K, V>`, `list<T>`, `class-string<T>` and callable signatures, and resolves names with the namespace and imports of the file. Template names, type aliases, PHP and PHPDoc pseudo-types (`array-key`, `positive-int`, `static`, `$this`, `class-string` without an argument...) and anything that does not parse are never references. It applies to `cordon:verify`, `vendor/bin/cordon`, the Pest expectation and the PHPStan rule (which also takes a `cordon.docblocks` parameter), and it is part of the analysis cache fingerprint. A project that leaves it off is unchanged. It adds `phpstan/phpdoc-parser` (`^2.0`) as a dependency. Closes [#24](https://github.com/ChrisAbner/Cordon-Modulith/issues/24). See the [configuration](https://chrisabner.github.io/Cordon-Modulith/guide/configuration#docblocks) guide.
- `cordon:verify --since=<ref>` and `cordon:affected --since=<ref>`: work from what changed in git since a reference (what was committed since the branch forked from it, plus what is staged, modified or untracked, deleted files included). `verify --since` is `verify <changed PHP files>`: the whole project is analysed and only the violations of those files, and the cycles their modules take part in, are reported. `affected` lists the changed modules and the ones that depend on them (the graph of `cordon:impact`, with a nested module's parent and a parent's nested modules included), and `--tests` prints the test folders of those modules, one per line, for Pest: the `tests` setting of each module (also `host.tests`), or else `tests/<Module>` and `<module>/tests`. A reference that does not exist, a folder that is not a git repository or a reference that starts with `-` exits with `2`. Also `affected` in `vendor/bin/cordon`. See the new [affected tests](https://chrisabner.github.io/Cordon-Modulith/recipes/affected-tests) recipe.
- `external_dependency` rule and the `packages` config: `packages => ['shared' => ['laravel/framework', 'illuminate/*']]` and, per module, `packages => ['stripe/stripe-php']` limit the Composer packages a module may use (names, or a prefix ending in `*`). A module that uses another package gets `Module [Billing] uses Stripe\StripeClient from [stripe/stripe-php], which is not in its packages.`, once per file and package. A module without `packages` is unchanged, a nested module without its own list takes its parent's, and the code outside the modules is not checked. It reads `vendor/composer/installed.json` as data (a missing file, when a module lists `packages`, is a configuration error, and a package that is not installed a warning), and a class belongs to a package only when that package provably provides it, so PHP's classes (polyfills included), the project's and those of packages that are not installed are never reported. It is an error like `layers`, and checks nothing until some module lists `packages`. `cordon:why Billing stripe/stripe-php` lists the uses of a package by a module, and `cordon:explain` knows the classes of packages. `AnalysisContext::$externalReferences` lists the references to classes no module owns and `Module::$packages` holds the setting. See the [rules](https://chrisabner.github.io/Cordon-Modulith/guide/rules#external-dependency) and [configuration](https://chrisabner.github.io/Cordon-Modulith/guide/configuration#packages) guides.
- `tables` rule (heuristic, `off` by default, meant to run as `warn`): a module that alters (`Schema::table`, `drop`, `rename`), queries (`DB::table`, its joins, a model whose table is another module's) or points a foreign key at (`foreign()->references()->on()`, `constrained()`, with the table Laravel infers when it is not named) a table that another module creates gets `Module [Billing] alters table [orders], which belongs to [Orders].` (and the two messages for foreign keys and queries), once per file, table and kind of use. The owner of a table is the module that creates it, or the code outside the modules when a migration in `database/migrations` does; a table that two create, or that nobody does, and a model with a dynamic `$table`, are never reported, and `cordon:docs` lists them in the module cards as without owner, with the reason. It reads literal names only, and a nested module may use the tables of its ancestors. The extractor reads the tables only while the rule is on, so a project that leaves it off is unchanged, and turning it on starts a new analysis cache. `AnalysisContext::$tables` and `FileAnalysis::$tables` hold the data. See the [rules](https://chrisabner.github.io/Cordon-Modulith/guide/rules#tables) guide and the [cross-module relations](https://chrisabner.github.io/Cordon-Modulith/recipes/cross-module-relations) recipe.
- `cordon:graph --format=c4` exports the module graph as a C4-PlantUML diagram (`!include <C4/C4_Component>`): a `Container_Boundary` for the application, a `Component` per module with the `description` of its `metadata`, a `Rel` per dependency with its number of references (and the named interface it is limited to), red, through a `violation` relationship tag (`AddRelTag`), when it has violations, and a nested module inside a `Boundary` of its parent. Names and descriptions are escaped for PlantUML. `cordon:docs --diagrams=c4` also writes it as `architecture.puml` (`--diagrams=mermaid` is the default and changes nothing). See the [explore](https://chrisabner.github.io/Cordon-Modulith/guide/explore#the-whole-graph) guide.
- `Cordon\Laravel\Architecture`, a new class for tools that show the architecture (a dashboard, the Filament plugin), `@internal` until the Filament plugin is published, so it may still change in a minor release: `Architecture::graph(?string $module = null)` returns the Mermaid flowchart of `cordon:graph` and `Architecture::docs()` the Markdown files of `cordon:docs` by file name, both as text, with nothing written to disk. `docs()` reads the files through the same analysis cache as `cordon:verify`, so it does not parse the project again when `cache` is set. See [ADR 0028](docs/adr/0028-text-exports-and-architecture.md).
- `cordon:affected --format=json` starts with `"version": 1`, like the other JSON reports: a new optional field keeps the version, removing or renaming one does not.
- Layers and nested modules: a nested module that `layers` does not name takes the layer of its nearest ancestor that it names, as source and as target, so `Billing.Payments` in the layer of `Billing` can no longer depend on a layer above it unnoticed. The use between a parent and its children is still never reported.

### Changed
- `Cordon::assertBoundaries()` and the `toRespectBoundaries()` expectation fail on invalid named interfaces (an interface that lists a class that is not public), as `cordon:verify` does with exit code `2`. They used to pass.
- With `docblocks` on, the reference counts in `cordon:graph`, `cordon:why` and `cordon:impact` go up: a class named in a type and in the code is two references (one of kind `use` and one of kind `docblock`). Nothing changes while `docblocks` is `false`.
- The analysis cache fingerprint also holds the installed versions of `phpstan/phpdoc-parser` and `illuminate/support`, so updating either starts a new cache (`illuminate/support` is replaced by `laravel/framework` in a Laravel project, so it takes that package's version).

## [0.4.0] - 2026-11-11

This release settles the model that 1.0 will freeze: rule severities, listener edges, a strict config, a versioned JSON report and the code outside the modules. Read [UPGRADE.md](UPGRADE.md) first: a broken config now stops `cordon:verify`, and some reports change. The decisions are recorded in [ADR 0015](docs/adr/0015-rule-severities.md) (severities, warnings and the baseline), [0016](docs/adr/0016-listener-edges.md) (listener edges), [0017](docs/adr/0017-host-module.md) (the `host`), [0018](docs/adr/0018-json-report-version.md) (the JSON report), [0019](docs/adr/0019-strict-configuration.md) (the strict config) and [0020](docs/adr/0020-rules-options-and-commands.md) (the other additions).
Expand Down
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ composer check # pint --test, phpstan, pest
composer bench # analyses a synthetic project of 1,000 files; fails above 10 s
```

Run PHPStan through `composer analyse`: it passes `--memory-limit=512M`, and calling `vendor/bin/phpstan analyse` directly stops at the default memory limit.

`php tests/Benchmark/run.php 5000 50` runs a larger benchmark (files, modules, optional time budget in seconds).

Coverage and mutation testing need pcov (or Xdebug):
Expand All @@ -20,6 +22,8 @@ composer coverage # the whole suite, fails below 95% line coverage
composer mutate # mutates the classes whose tests declare mutates(), fails below 88%
```

Many tests run `bin/cordon` or PHPStan in a process of their own, the way a project runs them. With pcov, `tests/Coverage/SubprocessCoverage.php` counts the code those processes run and applies the mutant there too. With Xdebug it does not, so the coverage is lower than CI's.

To mutate a class, add `mutates(TheClass::class);` to its test file. A surviving mutant either gets a test or, when it cannot change behaviour (an equivalent mutant), a line in the pull request saying why.

The oracles in `tests/Oracle/` check the extractor against independent sources:
Expand Down
Loading