graph

package
v0.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 25, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package graph provides dependency graph construction and analysis.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DependencyGraph

type DependencyGraph struct {
	// contains filtered or unexported fields
}

DependencyGraph represents the dependency relationships between modules.

func BuildFromDependencies

func BuildFromDependencies(modules []*discovery.Module, deps map[string]*parser.ModuleDependencies) *DependencyGraph

BuildFromDependencies builds a graph from extracted dependencies.

func NewDependencyGraph

func NewDependencyGraph() *DependencyGraph

NewDependencyGraph creates a new empty dependency graph.

func (*DependencyGraph) AddEdge

func (g *DependencyGraph) AddEdge(from, to string)

AddEdge adds a dependency edge (from depends on to).

func (*DependencyGraph) AddLibraryUsage

func (g *DependencyGraph) AddLibraryUsage(libraryPath, moduleID string)

AddLibraryUsage records that an executable module uses a library module.

func (*DependencyGraph) AddNode

func (g *DependencyGraph) AddNode(m *discovery.Module)

AddNode adds a module to the graph.

func (*DependencyGraph) DetectCycles

func (g *DependencyGraph) DetectCycles() [][]string

DetectCycles returns all cycles in the graph.

func (*DependencyGraph) ExecutionLevels

func (g *DependencyGraph) ExecutionLevels() ([][]string, error)

ExecutionLevels returns modules grouped by execution level. Modules at the same level can be executed in parallel.

func (*DependencyGraph) GetAffectedByLibraryChanges

func (g *DependencyGraph) GetAffectedByLibraryChanges(changedLibraryPaths []string) []string

GetAffectedByLibraryChanges returns executable modules affected by changes to library modules.

func (*DependencyGraph) GetAffectedModules

func (g *DependencyGraph) GetAffectedModules(changedModules []string) []string

GetAffectedModules returns modules affected by changes to the given modules. Includes the changed modules themselves plus all transitive dependents and dependencies.

func (*DependencyGraph) GetAffectedModulesWithLibraries

func (g *DependencyGraph) GetAffectedModulesWithLibraries(changedModules, changedLibraryPaths []string) []string

GetAffectedModulesWithLibraries combines executable and library module changes.

func (*DependencyGraph) GetAllDependencies

func (g *DependencyGraph) GetAllDependencies(moduleID string) []string

GetAllDependencies returns all transitive dependencies of a module.

func (*DependencyGraph) GetAllDependents

func (g *DependencyGraph) GetAllDependents(moduleID string) []string

GetAllDependents returns all transitive dependents of a module.

func (*DependencyGraph) GetAllLibraryPaths

func (g *DependencyGraph) GetAllLibraryPaths() []string

GetAllLibraryPaths returns all tracked library module paths.

func (*DependencyGraph) GetDependencies

func (g *DependencyGraph) GetDependencies(moduleID string) []string

GetDependencies returns the direct dependencies of a module.

func (*DependencyGraph) GetDependents

func (g *DependencyGraph) GetDependents(moduleID string) []string

GetDependents returns modules that directly depend on the given module.

func (*DependencyGraph) GetModulesUsingLibrary

func (g *DependencyGraph) GetModulesUsingLibrary(libraryPath string) []string

GetModulesUsingLibrary returns all executable modules that use the given library path.

func (*DependencyGraph) GetNode

func (g *DependencyGraph) GetNode(id string) *Node

GetNode returns a specific node by ID.

func (*DependencyGraph) GetStats

func (g *DependencyGraph) GetStats() Stats

GetStats returns statistics about the dependency graph.

func (*DependencyGraph) Nodes

func (g *DependencyGraph) Nodes() map[string]*Node

Nodes returns all nodes in the graph.

func (*DependencyGraph) ScopeToModule

func (g *DependencyGraph) ScopeToModule(moduleID string, showDependents bool) (*DependencyGraph, error)

ScopeToModule returns a subgraph scoped to the given module's dependencies or dependents. If showDependents is true, includes the module and all its dependents; otherwise includes the module and all its dependencies.

func (*DependencyGraph) Subgraph

func (g *DependencyGraph) Subgraph(moduleIDs []string) *DependencyGraph

Subgraph returns a new graph containing only the specified modules and their edges.

func (*DependencyGraph) ToDOT

func (g *DependencyGraph) ToDOT() string

ToDOT exports the graph in DOT format with HTML labels for proper line breaks.

func (*DependencyGraph) ToPlantUML

func (g *DependencyGraph) ToPlantUML() string

ToPlantUML exports the graph in PlantUML format with nested grouping.

func (*DependencyGraph) TopologicalSort

func (g *DependencyGraph) TopologicalSort() ([]string, error)

TopologicalSort returns modules in dependency order (dependencies first). Returns an error if there's a cycle.

type ModuleStat

type ModuleStat struct {
	ID    string
	Count int
}

ModuleStat holds a module ID and a count.

type Node

type Node struct {
	Module    *discovery.Module
	InDegree  int
	OutDegree int
}

Node represents a module in the dependency graph.

type Stats

type Stats struct {
	TotalModules int
	TotalEdges   int
	RootModules  int // Modules with no dependencies
	LeafModules  int // Modules with no dependents
	MaxDepth     int
	AverageDepth float64
	HasCycles    bool
	CycleCount   int

	// Per-level module counts
	LevelCounts []int

	// Top modules by fan-in (most depended upon)
	TopDependedOn []ModuleStat

	// Top modules by fan-out (most dependencies)
	TopDependencies []ModuleStat
}

Stats contains statistics about the dependency graph.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL