Module instability
Expand description
instability analysis — Robert C. Martin’s package-coupling metrics
per file (Martin 1994, “OO Design Quality Metrics: An Analysis of
Dependencies”; canonised in Clean Architecture 2017).
- Afferent coupling
ca— how many files import this one (the in-degree of the resolved import graph). Highca= widely depended upon. - Efferent coupling
ce— how many files this one imports (the out-degree). Highce= depends on a lot. - Instability
I = ce / (ca + ce)∈[0, 1].I = 0is maximally stable (much depends on it, it depends on nothing — hard and risky to change);I = 1is maximally unstable (it depends on much, nothing depends on it — cheap to change).
The Stable-Dependencies Principle says a file should only depend on
files more stable than itself; a widely-depended-on file (low
I, high ca) that is nonetheless unstable is the dangerous shape.
Abstractness A and Distance-from-the-Main-Sequence D (the “Zone
of Pain”) need symbol-level abstract-type counts the file-level
import graph doesn’t carry, so they are out of scope here.
Computed on the resolved import graph, so accuracy follows the resolver’s language coverage (Rust + Python + JS/TS).
Structs§
- Instability
Row - One file’s Martin coupling metrics.
Functions§
- run_
instability - Run the
instabilityanalysis. Returns one row per file in the import graph, ranked by afferent coupling (most depended-upon first), where instability is most consequential.