What Is Code Centrality?

Code centrality is the application of graph centrality algorithms to a codebase's dependency graph, measuring the relative structural importance of each file based on its position in the network of dependencies. Files with high centrality are the load-bearing members of the architecture — they influence the most other files and represent the greatest concentration of structural risk.

Why It Matters

Not all files in a codebase are equally important. A utility module imported by 80% of the codebase is architecturally critical, while a leaf component imported by nothing else is architecturally isolated. Centrality analysis quantifies this difference, transforming the intuition that "some files matter more than others" into a ranked, scored, and tiered classification.

Centrality data enables risk-proportionate engineering practices. High-centrality files warrant more thorough code review, more comprehensive testing, and more careful change management. Low-centrality files can be modified with less ceremony. Without centrality data, teams apply the same review process to all files — over-investing in low-risk changes and under-investing in high-risk ones.

Centrality also reveals architectural patterns that are invisible at the file level. A cluster of files with similar centrality scores often represents an architectural zone — a logical grouping that may or may not align with the directory structure.

How It Works

Code centrality is calculated using multiple graph algorithms, each measuring a different aspect of structural importance:

PageRank, originally developed for ranking web pages, measures the transitive importance of a node. A file that is depended on by other important files scores higher than one depended on by peripheral files. PageRank captures the "quality" of dependencies, not just the quantity.

Betweenness centrality measures how often a file appears on the shortest path between other files in the dependency graph. High betweenness indicates a file that acts as a bridge or bottleneck — if removed, many dependency paths would be disrupted.

In-degree centrality simply counts the number of files that directly depend on a given file. It is the most intuitive measure of importance.

Composite centrality combines multiple metrics into a single normalized score, enabling files to be ranked on overall structural importance rather than any single metric.

How Axiom Refract Addresses This

  • Axiom Refract calculates PageRank, betweenness, in-degree, out-degree, and composite centrality for every file in the dependency graph
  • The get_graph_nodes tool returns centrality metrics sortable by any metric, with SPOF flags and cluster IDs
  • Centrality tiers (critical, high, medium, low) are assigned based on composite score percentiles and used throughout reports and migration plans