graph

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnalysisSummary

type AnalysisSummary struct {
	ProjectID  core.ID        `json:"project_id"`
	NodeCounts map[string]int `json:"node_counts"`
	TotalNodes int            `json:"total_nodes"`
	Timestamp  time.Time      `json:"timestamp"`
}

AnalysisSummary represents a summary of analysis results

type Builder

type Builder interface {
	// BuildFromAnalysis creates graph nodes and relationships from analysis results
	BuildFromAnalysis(
		ctx context.Context,
		projectID core.ID,
		parseResult *parser.ParseResult,
		analysis *analyzer.AnalysisReport,
	) (*core.AnalysisResult, error)

	// BuildFromParseResult creates basic graph structure from parser results only
	BuildFromParseResult(
		ctx context.Context,
		projectID core.ID,
		parseResult *parser.ParseResult,
	) (*core.AnalysisResult, error)
}

Builder defines the interface for building graph structures from analysis results

func NewBuilder

func NewBuilder(config *BuilderConfig) Builder

NewBuilder creates a new graph builder instance

type BuilderConfig

type BuilderConfig struct {
	IncludeLineNumbers bool // Include line numbers in properties
	IncludeComments    bool // Include comment text in properties
	CreateFileNodes    bool // Create nodes for files
	BatchSize          int  // Batch size for node/relationship creation
	ChunkSize          int  // Number of files to process in one chunk
	MaxConcurrency     int  // Maximum concurrent goroutines for processing
}

BuilderConfig holds builder configuration

func DefaultBuilderConfig

func DefaultBuilderConfig() *BuilderConfig

DefaultBuilderConfig returns default builder configuration

type CallChain

type CallChain struct {
	StartFunction string      `json:"start_function"`
	Chain         []ChainNode `json:"chain"`
	MaxDepth      int         `json:"max_depth"`
}

CallChain represents a chain of function calls

type CallGraph

type CallGraph struct {
	RootFunction string     `json:"root_function"`
	Calls        []CallNode `json:"calls"`
}

CallGraph represents a function call graph

type CallNode

type CallNode struct {
	Function string   `json:"function"`
	Calls    []string `json:"calls"`
	CalledBy []string `json:"called_by"`
	Level    int      `json:"level"`
}

CallNode represents a node in the call graph

type ChainNode

type ChainNode struct {
	Function string `json:"function"`
	Depth    int    `json:"depth"`
	Calls    int    `json:"calls"`
}

ChainNode represents a node in a call chain

type CircularDependency

type CircularDependency struct {
	Type     string   `json:"type"` // "package" or "function"
	Elements []string `json:"elements"`
}

CircularDependency represents a circular dependency in the code

type DependencyGraph

type DependencyGraph struct {
	RootPackage  string           `json:"root_package"`
	Dependencies []DependencyNode `json:"dependencies"`
}

DependencyGraph represents a dependency graph

type DependencyNode

type DependencyNode struct {
	Package      string   `json:"package"`
	Dependencies []string `json:"dependencies"`
	Level        int      `json:"level"`
}

DependencyNode represents a node in the dependency graph

type FunctionStats

type FunctionStats struct {
	Name      string `json:"name"`
	CallCount int    `json:"call_count"`
	CalledBy  int    `json:"called_by"`
}

FunctionStats represents statistics for a function

type NodeWithRelations

type NodeWithRelations struct {
	Node              core.Node           `json:"node"`
	IncomingRelations []core.Relationship `json:"incoming_relations"`
	OutgoingRelations []core.Relationship `json:"outgoing_relations"`
}

NodeWithRelations represents a node with its relationships

type PackageStats

type PackageStats struct {
	Name          string `json:"name"`
	FileCount     int    `json:"file_count"`
	FunctionCount int    `json:"function_count"`
	Dependencies  int    `json:"dependencies"`
}

PackageStats represents statistics for a package

type PathSegment

type PathSegment struct {
	FromNode     core.Node         `json:"from_node"`
	Relationship core.Relationship `json:"relationship"`
	ToNode       core.Node         `json:"to_node"`
}

PathSegment represents a segment in a path between nodes

type ProjectGraph

type ProjectGraph struct {
	Nodes         []core.Node         `json:"nodes"`
	Relationships []core.Relationship `json:"relationships"`
}

ProjectGraph represents the entire project graph

type ProjectStatistics

type ProjectStatistics struct {
	TotalNodes          int                       `json:"total_nodes"`
	TotalRelationships  int                       `json:"total_relationships"`
	NodesByType         map[core.NodeType]int     `json:"nodes_by_type"`
	RelationshipsByType map[core.RelationType]int `json:"relationships_by_type"`
	TopPackages         []PackageStats            `json:"top_packages"`
	TopFunctions        []FunctionStats           `json:"top_functions"`
}

ProjectStatistics represents project statistics

type ProjectStats

type ProjectStats struct {
	ProjectID            core.ID `json:"project_id"`
	PackageCount         int     `json:"package_count"`
	FileCount            int     `json:"file_count"`
	FunctionCount        int     `json:"function_count"`
	InterfaceCount       int     `json:"interface_count"`
	StructCount          int     `json:"struct_count"`
	TotalRelationships   int     `json:"total_relationships"`
	CircularDependencies int     `json:"circular_dependencies"`
	UnusedFunctions      int     `json:"unused_functions"`
}

ProjectStats represents simplified project statistics

type Repository

type Repository interface {
	// Connection management
	Connect(ctx context.Context, uri, username, password string) error
	Close() error

	// Node operations
	CreateNode(ctx context.Context, node *core.Node) error
	CreateNodes(ctx context.Context, nodes []core.Node) error
	GetNode(ctx context.Context, id core.ID) (*core.Node, error)
	UpdateNode(ctx context.Context, node *core.Node) error
	DeleteNode(ctx context.Context, id core.ID) error

	// Relationship operations
	CreateRelationship(ctx context.Context, rel *core.Relationship) error
	CreateRelationships(ctx context.Context, rels []core.Relationship) error
	GetRelationship(ctx context.Context, id core.ID) (*core.Relationship, error)
	DeleteRelationship(ctx context.Context, id core.ID) error

	// Query operations
	ExecuteQuery(ctx context.Context, query string, params map[string]any) ([]map[string]any, error)

	// Bulk operations
	ImportAnalysisResult(ctx context.Context, result *core.AnalysisResult) error
	StoreAnalysis(ctx context.Context, result *core.AnalysisResult) error
	ClearProject(ctx context.Context, projectID core.ID) error

	// Search operations
	FindNodesByType(ctx context.Context, nodeType core.NodeType, projectID core.ID) ([]core.Node, error)
	FindNodesByName(ctx context.Context, name string, projectID core.ID) ([]core.Node, error)
	FindRelationshipsByType(
		ctx context.Context,
		relType core.RelationType,
		projectID core.ID,
	) ([]core.Relationship, error)
}

Repository defines the interface for graph database operations

type Service

type Service interface {
	// Project operations
	InitializeProject(ctx context.Context, project *core.Project) error
	ImportAnalysis(ctx context.Context, projectID core.ID, result *core.AnalysisResult) error
	ClearProject(ctx context.Context, projectID core.ID) error

	// Query operations
	GetProjectGraph(ctx context.Context, projectID core.ID) (*ProjectGraph, error)
	GetNodeWithRelationships(ctx context.Context, nodeID core.ID) (*NodeWithRelations, error)
	FindPath(ctx context.Context, fromID, toID core.ID) ([]PathSegment, error)
	ExecuteQuery(ctx context.Context, query string, params map[string]any) ([]map[string]any, error)

	// Analysis operations
	GetDependencyGraph(ctx context.Context, packageName string) (*DependencyGraph, error)
	GetCallGraph(ctx context.Context, functionName string) (*CallGraph, error)
	GetProjectStatistics(ctx context.Context, projectID core.ID) (*ProjectStatistics, error)
}

Service defines the interface for graph service operations

func NewService

func NewService(
	parser parser.Parser,
	analyzer analyzer.Analyzer,
	builder Builder,
	repository Repository,
	config *ServiceConfig,
) Service

NewService creates a new graph service instance

type ServiceConfig

type ServiceConfig struct {
	ParserConfig     *parser.Config
	AnalyzerConfig   *analyzer.Config
	BatchSize        int    // Number of nodes/relationships to create in batch
	MaxQueryDepth    int    // Maximum depth for path queries
	EnableCaching    bool   // Enable result caching
	ProjectPrefix    string // Prefix for project namespaces
	MaxMemoryUsageMB int    // Maximum memory usage in MB before triggering optimization
	EnableStreaming  bool   // Enable streaming mode for very large codebases
}

ServiceConfig holds configuration for the graph service

func DefaultServiceConfig

func DefaultServiceConfig() *ServiceConfig

DefaultServiceConfig returns default service configuration

Jump to

Keyboard shortcuts

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