Stellarion
Tools

stellarion_analyze_coupling [Pro]

Measure module coupling with afferent, efferent, and instability metrics
This is a Pro tool. Requires a Stellarion Pro license. A 180-day free trial starts automatically.

Computes module coupling metrics using the indexed dependency graph. Measures afferent coupling (incoming dependencies), efferent coupling (outgoing dependencies), and instability ratio. Uses existing graph edges — no re-parsing required.

When to Use

  • Before refactoring to identify tightly coupled modules
  • To find modules that are too dependent on external code (high instability)
  • To locate stable core modules that many others depend on
  • When planning module boundaries or extracting packages

Parameters

ParameterTypeRequiredDefaultDescription
uristringYesFile or directory path to analyze
includeExternalbooleanNofalseInclude external/third-party dependencies in the analysis
depthnumberNo2How many levels of transitive dependencies to follow
summarybooleanNofalseReturn a condensed summary instead of full breakdown

Examples

Analyze a specific module

What's the coupling profile for src/services/auth/?

Returns afferent/efferent counts and instability for the auth service module.

Find the most coupled modules in the project

Show me coupling metrics for the entire src/ directory with a summary.

Uses summary: true to get a ranked overview of all modules by coupling.

Include third-party dependencies

Analyze coupling for src/api/ including external dependencies. I want to see how much we depend on third-party packages.

Sets includeExternal: true to include imports from node_modules, crates.io dependencies, pip packages, etc.

Deep transitive analysis

Show coupling for src/core/engine.rs with depth 3. I want to see the full dependency chain.

Follows dependencies three levels deep to reveal hidden transitive coupling.

Output Format

For each module analyzed:

  • Afferent coupling (Ca) — number of modules that depend on this module
  • Efferent coupling (Ce) — number of modules this module depends on
  • Instability (I) — ratio Ce / (Ca + Ce), ranging from 0.0 (maximally stable) to 1.0 (maximally unstable)
  • Dependency list — which modules are incoming and outgoing

Instability interpretation:

ScoreMeaning
0.0Fully stable — many depend on it, it depends on nothing
0.0–0.3Stable — changing it affects many consumers
0.3–0.7Balanced
0.7–1.0Unstable — depends on many, few depend on it
1.0Fully unstable — depends on others, nobody depends on it

Tips

  • Stable modules (low instability) should contain abstractions and interfaces — they are hard to change
  • Unstable modules should contain concrete implementations — they are easy to change
  • A module with high afferent coupling AND high efferent coupling is a risk: it is both hard to change and has many reasons to change
  • Use depth: 1 for a quick overview, increase to 3 or more when investigating specific dependency chains
  • Pair with stellarion_codebase_health to see coupling in the context of overall project health