Section 6.7Source:
server/src/analytics/health/modules/calculateModuleHealth.tsModule Isolation Health (7%)
Measuring the proportion of unresolved module nodes (Node.js built-ins) relative to total graph entities.
Source:
server/src/analytics/health/modules/calculateModuleHealth.tsWhat Are Module Nodes?
In CodeGraph, a Module Node represents an entity in an import statement that the extraction pipeline failed to resolve to either a local repository source file (via relative paths or path aliases) or a declared third-party dependency in package.json.
When the Relationship Extractor encounters an import statement, it follows this resolution order:
- Relative / Aliased File: Matches an internal file in the repository → creates a
FileNodetarget. - Declared Dependency: Package name is found in
package.jsondependenciesordevDependencies→ creates aDependencyNodetarget. - Unresolved Fallback: Any import target that fails both lookups above → creates a
ModuleNodetarget.
Why Module Nodes Occur & Why They Have Low Weight (7%)
Module nodes typically appear in two common scenarios:
- Node.js Built-in Modules: Imports like
import fs from "fs",import path from "node:path", orimport crypto from "crypto". These are native platform APIs provided by the runtime environment and are intentionally omitted frompackage.json. - Unlisted or Implicit Dependencies: Imports of packages not explicitly declared in the nearest manifest (e.g., peer dependencies, workspace packages, or missing dependencies).
Why 7% Weightage?
Because Module nodes frequently represent perfectly valid platform imports (like Node.js built-ins) rather than genuine codebase defects, Module Health is assigned the lowest weight (7%) in the overall Health Index ($H$). A high proportion of module nodes indicates incomplete graph resolution rather than severe architectural degradation.
Module Ratio Calculation
The calculator measures the ratio of module nodes to the total node population in the canonical graph and scores it linearly:
server/src/analytics/health/modules/calculateModuleHealth.ts
12345678910111213141516171819202122232425export function calculateModuleHealth(graph: Graph): ModuleHealthResult { const moduleCount = graph.nodesByKind.get("module")?.size ?? 0; const totalNodeCount = graph.nodes.size; if (totalNodeCount === 0) { return { score: 100, moduleCount: 0, totalNodeCount: 0, moduleRatio: 0, }; } const moduleRatio = moduleCount / totalNodeCount; // Linear health score: 100 * (1 - moduleRatio) const score = 100 * (1 - moduleRatio); return { score, moduleCount, totalNodeCount, moduleRatio, }; }