Help us shape the future of Go! Take the 2026 Go Developer Survey

analysis

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeBetweenness

func ComputeBetweenness(nodes []graph.Node, edges []graph.Edge) map[graph.NodeID]float64

ComputeBetweenness computes approximate betweenness centrality using Brandes' Algorithm.

func ComputePageRank

func ComputePageRank(nodes []graph.Node, edges []graph.Edge, damping float64, iterations int) map[graph.NodeID]float64

ComputePageRank computes PageRank scores over directed calls/implements/consumes/imports edges.

func DetectCyclesReport

func DetectCyclesReport(nodes []graph.Node, edges []graph.Edge, limit int) ([]Cycle, Coverage)

DetectCyclesReport is like DetectCycles but also returns resolution coverage.

func ShortestPath

func ShortestPath(nodes []graph.Node, edges []graph.Edge, startID, targetID graph.NodeID) []graph.NodeID

ShortestPath computes the shortest path between startID and targetID using BFS.

Types

type Community

type Community struct {
	ID       string         `json:"id"`
	Name     string         `json:"name"`     // Label derived from dominant node hub
	Cohesion float64        `json:"cohesion"` // Edge density: 2 * E_in / (V * (V - 1))
	NodeIDs  []graph.NodeID `json:"node_ids"`
}

Community represents a detected structural cluster in the graph.

func DetectCommunities

func DetectCommunities(nodes []graph.Node, edges []graph.Edge) []Community

DetectCommunities partitions resolved dependency-view nodes into communities using Label Propagation. KindSymbol and KindImport are excluded; only file/module/function/type/method nodes that appear in resolved edges participate.

type Coverage

type Coverage struct {
	ImportEdgesTotal    int      `json:"import_edges_total"`
	ImportEdgesResolved int      `json:"import_edges_resolved"`
	CallEdgesTotal      int      `json:"call_edges_total"`
	CallEdgesResolved   int      `json:"call_edges_resolved"`
	Notes               []string `json:"notes,omitempty"`
}

Coverage describes what dependency resolution could and could not establish.

func (Coverage) Incomplete

func (c Coverage) Incomplete() bool

Incomplete reports whether any import or call edges remain unresolved.

type Cycle

type Cycle struct {
	Type   string         `json:"type"` // e.g. "import_cycle", "call_cycle"
	Length int            `json:"length"`
	Path   []graph.NodeID `json:"path"`
}

Cycle represents a circular dependency loop.

func DetectCycles

func DetectCycles(nodes []graph.Node, edges []graph.Edge, limit int) []Cycle

DetectCycles finds circular dependency cycles using Tarjan's Strongly Connected Components (SCC) over the resolved dependency view.

type DependencyView

type DependencyView struct {
	Nodes    []graph.Node
	Edges    []graph.Edge // only resolved deps between files/modules (and resolved calls between defs)
	Coverage Coverage
}

DependencyView is a filtered graph of resolved file/module relationships.

func BuildDependencyView

func BuildDependencyView(nodes []graph.Node, edges []graph.Edge) DependencyView

BuildDependencyView constructs a single-repo analysis view of resolvable local imports and resolved call targets. Raw graph exports are left unchanged.

type IndirectTrace

type IndirectTrace struct {
	From string         `json:"from"`
	To   string         `json:"to"`
	Hops int            `json:"hops"`
	Path []graph.NodeID `json:"path"`
}

IndirectTrace represents a multi-hop call/dependency chain across namespaces or modules.

func FindIndirectTraces

func FindIndirectTraces(nodes []graph.Node, edges []graph.Edge, limit int) []IndirectTrace

FindIndirectTraces discovers indirect call chains (length >= 2 hops) between distinct modules/files, traversing only resolved call edges from the dependency view.

type KnowledgeGaps

type KnowledgeGaps struct {
	IsolatedNodes   []graph.NodeID `json:"isolated_nodes"`
	ThinCommunities []string       `json:"thin_communities"`
}

KnowledgeGaps holds summary of orphan nodes and thin communities.

func AnalyzeKnowledgeGaps

func AnalyzeKnowledgeGaps(nodes []graph.Node, edges []graph.Edge, communities []Community) KnowledgeGaps

AnalyzeKnowledgeGaps finds isolated nodes (<=1 edge) and thin clusters.

type NodeCentrality

type NodeCentrality struct {
	ID          graph.NodeID `json:"id"`
	Kind        string       `json:"kind"`
	Name        string       `json:"name"`
	Path        string       `json:"path"`
	PageRank    float64      `json:"pagerank"`
	Betweenness float64      `json:"betweenness"`
}

NodeCentrality holds centrality scores for a single node.

func RankCentrality

func RankCentrality(nodes []graph.Node, edges []graph.Edge, limit int) []NodeCentrality

RankCentrality returns top N nodes sorted by PageRank score, scored only over the resolved dependency view. KindSymbol and KindImport never appear as God Nodes.

type Question

type Question struct {
	Text      string `json:"text"`
	Rationale string `json:"rationale"`
}

Question represents an auto-generated architectural navigation or refactoring question.

func GenerateQuestions

func GenerateQuestions(nodes []graph.Node, communities []Community, centralities []NodeCentrality, cycles []Cycle, coverage Coverage) []Question

GenerateQuestions programmatically creates navigation questions based on topological metrics. coverage qualifies advice when import/call resolution is incomplete.

Jump to

Keyboard shortcuts

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