graph

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package graph provides Neo4j-based code graph operations. Implemented in Phase 05.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIHandlerResult

type APIHandlerResult struct {
	Method      string
	Path        string
	HandlerName string
	File        string
	Line        int
}

APIHandlerResult holds resolved handler info for an endpoint pattern.

type AffectedEndpoint

type AffectedEndpoint struct {
	Method string
	Path   string
}

AffectedEndpoint represents an API endpoint affected by a code change.

type BuildResult

type BuildResult struct {
	PackageNodes    int
	FileNodes       int
	FunctionNodes   int
	TypeNodes       int
	ImportEdges     int
	ServiceNodes    int
	ConnectionEdges int
	ComponentEdges  int
	CallEdges       int
	TypeFlowEdges   int
	ImplementsEdges int
}

BuildResult holds counts of nodes and edges created.

type Builder

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

Builder reads the PostgreSQL index and populates the Neo4j knowledge graph.

func NewBuilder

func NewBuilder(pool *pgxpool.Pool, client *Client) *Builder

NewBuilder constructs a Builder.

func (*Builder) Build

func (b *Builder) Build(ctx context.Context) (*BuildResult, error)

Build populates the Neo4j graph from the PostgreSQL index.

type CallerResult

type CallerResult struct {
	Name          string
	QualifiedName string
	File          string
	Line          int
	Depth         int
	Confidence    float64
	IsNameMatch   bool // true when result is a name-match fallback (no CALLS edge in graph)
}

CallerResult holds a function that calls (or references) a target function.

type Client

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

Client wraps a Neo4j driver and provides typed helpers for Cypher execution.

func NewClient

func NewClient(ctx context.Context, uri, user, password string) (*Client, error)

NewClient creates and verifies a Neo4j client connection.

func (*Client) Close

func (c *Client) Close(ctx context.Context) error

Close releases the underlying driver resources.

func (*Client) QueryNodes

func (c *Client) QueryNodes(ctx context.Context, query string, params map[string]any) ([]map[string]any, error)

QueryNodes runs a read Cypher query and returns all records as key→value maps.

func (*Client) RunCypher

func (c *Client) RunCypher(ctx context.Context, query string, params map[string]any) error

RunCypher executes a write Cypher statement inside an explicit transaction.

type CommunityDetector

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

CommunityDetector implements Louvain community detection on the call graph.

func NewCommunityDetector

func NewCommunityDetector(pool *pgxpool.Pool, communityRepo domain.CommunityRepository) *CommunityDetector

NewCommunityDetector constructs a CommunityDetector.

func (*CommunityDetector) BuildGraph

func (d *CommunityDetector) BuildGraph(ctx context.Context, repoID int64) ([]string, map[string]string, []Edge, error)

BuildGraph constructs the adjacency list from function_calls table.

func (*CommunityDetector) DetectAll

func (d *CommunityDetector) DetectAll(ctx context.Context, repoID int64) (int, error)

DetectAll runs Louvain community detection for a repository and persists results.

func (*CommunityDetector) RunLouvain

func (d *CommunityDetector) RunLouvain(nodes []string, edges []Edge) map[string]int

RunLouvain implements the Louvain modularity optimization algorithm.

type Edge

type Edge struct {
	From   int
	To     int
	Weight float64
}

Edge represents a directed edge in the call graph.

type EntryPoint

type EntryPoint struct {
	QualifiedName string
	Name          string
	FilePath      string
	Line          int
	Kind          string // "http_handler", "kafka_consumer", "main", "cli"
}

EntryPoint represents a detected entry point in the codebase.

type FileNode

type FileNode struct {
	Path    string
	Package string
}

FileNode represents a Go source file in the knowledge graph.

type FunctionNode

type FunctionNode struct {
	Name          string
	QualifiedName string
	Signature     string
	File          string
}

FunctionNode represents a function or method in the knowledge graph.

type ImpactReport

type ImpactReport struct {
	Callers            []CallerResult
	AffectedEndpoints  []AffectedEndpoint
	AffectedComponents []string
}

ImpactReport is the result of a change impact analysis.

type PackageNode

type PackageNode struct {
	Name   string
	Module string
}

PackageNode represents a Go package/module in the knowledge graph.

type ProcessDetector

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

ProcessDetector detects entry points and traces execution flows forward.

func NewProcessDetector

func NewProcessDetector(pool *pgxpool.Pool, client *Client, processRepo domain.ProcessRepository) *ProcessDetector

NewProcessDetector constructs a ProcessDetector.

func (*ProcessDetector) DetectAll

func (d *ProcessDetector) DetectAll(ctx context.Context, repoID int64) (int, error)

DetectAll detects all processes for a repository and persists them.

func (*ProcessDetector) DetectEntryPoints

func (d *ProcessDetector) DetectEntryPoints(ctx context.Context, repoID int64) ([]EntryPoint, error)

DetectEntryPoints finds all entry points in the repository.

func (*ProcessDetector) TraceForward

func (d *ProcessDetector) TraceForward(ctx context.Context, entryQName string, maxDepth int) ([]ProcessStepResult, error)

TraceForward performs a BFS from the entry point through CALLS edges.

type ProcessStepResult

type ProcessStepResult struct {
	QualifiedName string
	Name          string
	FilePath      string
	Line          int
	Depth         int
}

ProcessStepResult holds one step from a forward trace.

type Querier

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

Querier provides higher-level graph query operations over the Neo4j client.

func NewQuerier

func NewQuerier(client *Client) *Querier

NewQuerier constructs a Querier.

func (*Querier) AnalyzeImpact

func (q *Querier) AnalyzeImpact(ctx context.Context, symbol string, maxDepth int, repo string) (*ImpactReport, error)

AnalyzeImpact performs a transitive impact analysis — finds all callers, affected endpoints, and affected UI components for a given symbol. repo optionally restricts analysis to a single repository (empty = all repos).

func (*Querier) FindCallers

func (q *Querier) FindCallers(ctx context.Context, functionName string, depth int, minConfidence float64, repo string) ([]CallerResult, error)

FindCallers returns functions that call the target function, using recursive CALLS edges in the Neo4j graph (variable-length paths up to depth). minConfidence filters edges below the threshold (0.0 = no filter). repo optionally restricts results to a single repository (empty = all repos).

func (*Querier) FormatCallers

func (q *Querier) FormatCallers(functionName string, callers []CallerResult) string

FormatCallers renders caller results as human-readable text. Graph callers (CALLS edges) and name-match fallbacks are shown in separate sections.

func (*Querier) FormatServiceDependencies

func (q *Querier) FormatServiceDependencies(service string, deps []string) string

FormatServiceDependencies renders dependency list as human-readable text.

func (*Querier) GetAPIHandlers

func (q *Querier) GetAPIHandlers(ctx context.Context, endpointPattern string) ([]APIHandlerResult, error)

GetAPIHandlers finds functions whose name or qualified name contains the pattern.

func (*Querier) GetServiceDependencies

func (q *Querier) GetServiceDependencies(ctx context.Context, service string) ([]string, error)

GetServiceDependencies returns the packages imported by files belonging to service.

type ServiceDependency

type ServiceDependency struct {
	Service    string
	Dependency string
}

ServiceDependency captures a package dependency edge.

type TypeNode

type TypeNode struct {
	Name          string
	QualifiedName string
	Kind          string // struct|interface|type
	File          string
}

TypeNode represents a named type (struct, interface, alias) in the knowledge graph.

Jump to

Keyboard shortcuts

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