graph

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package graph provides core types for the GraphFS graph database.

Package graph provides core types for the GraphFS graph database.

Package graph provides core types for the GraphFS graph database.

Index

Constants

View Source
const (
	EdgeTypeCalls      = "calls"
	EdgeTypeImports    = "imports"
	EdgeTypeImplements = "implements"
	EdgeTypeExtends    = "extends"
	EdgeTypeUses       = "uses"
	EdgeTypeContains   = "contains"
	EdgeTypeDependsOn  = "depends_on"
	EdgeTypeReferences = "references"

	// EdgeTypeInjects represents dependency injection (Spring @Autowired, etc.)
	EdgeTypeInjects = "injects"

	// EdgeTypeHandlesRoute represents a controller method handling an HTTP route.
	EdgeTypeHandlesRoute = "handles_route"

	// EdgeTypeHasMany represents a one-to-many relationship (JPA @OneToMany).
	EdgeTypeHasMany = "has_many"

	// EdgeTypeBelongsTo represents a many-to-one relationship (JPA @ManyToOne).
	EdgeTypeBelongsTo = "belongs_to"

	// EdgeTypeAnnotatedWith represents a class/method annotated with a specific annotation.
	EdgeTypeAnnotatedWith = "annotated_with"

	// EdgeTypeMethodOf represents a method belonging to a class/struct (non-containment).
	EdgeTypeMethodOf = "method_of"
)

EdgeType constants for common relationship types.

View Source
const (
	NodeTypeFunction  = "function"
	NodeTypeMethod    = "method"
	NodeTypeClass     = "class"
	NodeTypeStruct    = "struct"
	NodeTypeFile      = "file"
	NodeTypePackage   = "package"
	NodeTypeModule    = "module"
	NodeTypeVariable  = "variable"
	NodeTypeConstant  = "constant"
	NodeTypeInterface = "interface"
)

NodeType constants for common node types.

Variables

This section is empty.

Functions

This section is empty.

Types

type Confidence

type Confidence string

Confidence indicates how an edge relationship was determined.

const (
	// ConfidenceExtracted means the edge was directly extracted from source
	// (e.g., import statement, function call in AST).
	ConfidenceExtracted Confidence = "EXTRACTED"

	// ConfidenceInferred means the edge was inferred by an LLM or heuristic,
	// with an associated confidence score.
	ConfidenceInferred Confidence = "INFERRED"

	// ConfidenceAmbiguous means the relationship is uncertain and should be
	// reviewed by a human.
	ConfidenceAmbiguous Confidence = "AMBIGUOUS"
)

type Edge

type Edge struct {
	// From is the source node ID.
	From string `json:"from"`

	// To is the target node ID.
	To string `json:"to"`

	// Type categorizes the relationship (e.g., "calls", "imports", "implements").
	Type string `json:"type"`

	// Confidence indicates how the edge was determined.
	Confidence Confidence `json:"confidence"`

	// ConfidenceScore is a 0.0-1.0 score for INFERRED edges.
	// Only meaningful when Confidence is ConfidenceInferred.
	ConfidenceScore float64 `json:"confidence_score,omitempty"`

	// Attrs holds additional attributes as key-value pairs.
	Attrs map[string]string `json:"attrs,omitempty"`
}

Edge represents a relationship between two nodes.

type Graph

type Graph struct {
	// Nodes maps node ID to Node.
	Nodes map[string]*Node `json:"nodes"`

	// Edges holds all edges in the graph.
	Edges []*Edge `json:"edges"`
}

Graph represents a complete graph with nodes and edges.

func NewGraph

func NewGraph() *Graph

NewGraph creates an empty graph.

func (*Graph) AddEdge

func (g *Graph) AddEdge(e *Edge)

AddEdge adds an edge to the graph.

func (*Graph) AddNode

func (g *Graph) AddNode(n *Node)

AddNode adds a node to the graph. If a node with the same ID exists, it will be overwritten.

func (*Graph) EdgeCount

func (g *Graph) EdgeCount() int

EdgeCount returns the number of edges in the graph.

func (*Graph) GetNode

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

GetNode returns a node by ID, or nil if not found.

func (*Graph) NodeCount

func (g *Graph) NodeCount() int

NodeCount returns the number of nodes in the graph.

type Node

type Node struct {
	// ID is the unique, stable identifier for this node.
	// Should be deterministic (e.g., based on content hash or path+symbol).
	ID string `json:"id"`

	// Type categorizes the node (e.g., "function", "file", "class", "module").
	Type string `json:"type"`

	// Label is a human-readable name for display.
	Label string `json:"label,omitempty"`

	// Attrs holds additional attributes as key-value pairs.
	Attrs map[string]string `json:"attrs,omitempty"`
}

Node represents an entity in the graph.

Jump to

Keyboard shortcuts

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