GraphAnalyzer

Stateless graph analysis algorithms that operate on a ModuleDependencyGraph.

All functions are pure - no side effects, no I/O, no mutation. This is the computational heart of Aalekh: every metric, every insight, every rule evaluation starts here.

Properties

Link copied to clipboard

Default minimum fan-in for a godModules classification - a module depended on by at least this many others. Shared with HealthScoreCalculator so the two never drift apart.

Link copied to clipboard

Default minimum fan-out for a godModules classification - a module depending on at least this many others. Shared with HealthScoreCalculator so the two never drift apart.

Functions

Link copied to clipboard

Returns the longest dependency chain (critical path) in the project. Useful for understanding which modules most constrain build parallelism.

Link copied to clipboard

Finds cycles using only main (non-test) edges.

Link copied to clipboard
fun godModules(graph: ModuleDependencyGraph, fanInThreshold: Int = DEFAULT_GOD_FAN_IN_THRESHOLD, fanOutThreshold: Int = DEFAULT_GOD_FAN_OUT_THRESHOLD): List<ModuleNode>

Identifies "god modules" - modules with both high fan-in AND high fan-out. These are architectural hotspots that are hard to change and test.

Link copied to clipboard

Computes the longest chain of production dependencies as a count of modules. This is the graph height used by the max-graph-height rule and is the primary constraint on build parallelism. Returns 0 when a cycle prevents a topological ordering. Only main edges are considered.

Link copied to clipboard

Identifies "isolated modules" - modules with neither dependents nor dependencies. These are candidates for removal.

Link copied to clipboard

Identifies "leaf modules" - modules with no outgoing production dependencies. These should ideally be domain/model modules.

Link copied to clipboard
fun potentiallyCoupledModules(graph: ModuleDependencyGraph, sharedDependentThreshold: Int = 3): List<Pair<ModuleNode, ModuleNode>>

Returns all pairs of modules that share a significant number of common dependents, suggesting they might be tightly coupled and should be merged or extracted.

Link copied to clipboard

Identifies "root modules" - modules that nobody depends on. There should typically be exactly one (the app module).

Link copied to clipboard

Computes a summary of the graph suitable for the report header and metadata. Cycle detection uses main-only edges (test deps excluded).

Link copied to clipboard

Returns modules in topological order (dependencies before dependents). Throws IllegalStateException if the graph contains cycles. Uses Kahn's algorithm (BFS-based) for deterministic ordering.