CodeGraph/docs
Section 6.4

Fan-Out Health & RMS (18%)

Measuring outgoing relationship concentration using Root Mean Square (RMS) to penalize outlier hotspot files and functions.

Source: server/src/analytics/health/fan-out/calculateFanOutHealth.ts

Why Simple Average is Insufficient

In a repository with 100 files, if 99 files have a fan-out of 1 and 1 file has an extreme fan-out of 100 (a God object), the arithmetic mean is only ≈ 2.0, concealing the architectural risk.

CodeGraph uses Root Mean Square (RMS):

RMS = √( (∑ x²) / N )

Squaring each term before averaging makes large outlier hotspots distinctly visible:

server/src/analytics/health/fan-out/calculateFanOutHealth.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
let totalFanOut = 0; let squaredFanOut = 0; let maximumFanOut = 0; for (const nodeId of nodeIds) { const fanOut = graph.outgoingEdges.get(nodeId)?.size ?? 0; totalFanOut += fanOut; squaredFanOut += fanOut * fanOut; // Squaring amplifies outliers maximumFanOut = Math.max(maximumFanOut, fanOut); } const averageFanOut = totalFanOut / nodeIds.length; const rootMeanSquareFanOut = Math.sqrt(squaredFanOut / nodeIds.length); const normalizedRisk = 0.5 * rootMeanSquareFanOut; const score = 100 / (1 + normalizedRisk);