ModuleDependencyGraph

data class ModuleDependencyGraph(val projectName: String, val modules: List<ModuleNode>, val edges: List<DependencyEdge>, val externalDependencies: List<ExternalDependency> = emptyList(), val buildInventory: BuildInventory = BuildInventory.EMPTY, val metadata: Map<String, String> = emptyMap())(source)

The complete module dependency graph for a Gradle project.

This is the central data structure that flows through the entire Aalekh pipeline:

Gradle Project Model
→ aalekh-gradle extraction (AalekhExtractTask)
→ ModuleDependencyGraph (this class)
→ RuleEngine → List<Violation>
→ HtmlReportGenerator / JUnitXmlWriter / JsonReporter / SarifReporter

All fields are serializable to JSON for tooling interoperability and configuration-cache compatibility. All operations are pure - no I/O, no mutation.

Parameters

projectName

Root project name from settings.gradle.kts

modules

All subproject modules discovered in the build

edges

All inter-module dependency relationships

externalDependencies

All declared external (third-party) dependencies, keyed by declaring module via ExternalDependency.module. Empty when external-dependency capture is disabled or when deserializing a graph file produced by an older plugin version.

buildInventory

How the project is built rather than how it is wired: plugins and their versions, version catalogs, toolchains, KMP targets, test layout, CODEOWNERS, and any metadata the team declared in .aalekh/modules.json. BuildInventory.EMPTY when deserializing a graph file produced by an older plugin version.

metadata

Build context: Gradle version, AGP version, extraction timestamp, etc.

Constructors

Link copied to clipboard
constructor(projectName: String, modules: List<ModuleNode>, edges: List<DependencyEdge>, externalDependencies: List<ExternalDependency> = emptyList(), buildInventory: BuildInventory = BuildInventory.EMPTY, metadata: Map<String, String> = emptyMap())

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard

All edges leaving a module (what it directly depends on).

Link copied to clipboard

All edges arriving at a module (what directly depends on it).

Link copied to clipboard

All external (third-party) dependencies declared by a module.

Link copied to clipboard
fun fanIn(path: String): Int

Fan-in: number of modules that directly depend on this one.

Link copied to clipboard
fun fanOut(path: String): Int

Fan-out: number of modules this module directly depends on.

Link copied to clipboard

Finds all cycles in the graph and returns them as lists of module paths. Returns an empty list if the graph is acyclic.

Link copied to clipboard

Returns true if the graph contains at least one cycle.

Link copied to clipboard

Instability index: fanOut / (fanIn + fanOut). Range: 0.0 (maximally stable) to 1.0 (maximally unstable). Core/domain modules should be near 0.0; leaf feature modules near 1.0.

Link copied to clipboard

Finds a module by its Gradle project path, or null if not found.

Link copied to clipboard

Number of transitively reachable modules from path.

Link copied to clipboard

All modules reachable by following edges from path (BFS). Returns paths only - excludes path itself.