parser

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: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KindComponent = "component"
	KindHook      = "hook"
	KindInterface = "interface"
	KindTypeAlias = "type_alias"
)

JSX/TS symbol kinds

View Source
const (
	KindClass  = "class"
	KindFunc   = "func"
	KindMethod = "method"
	KindConst  = "const"
	KindVar    = "var"
)

Python symbol kinds

View Source
const (
	FrameworkReactRouter     = "react-router"
	FrameworkReactNavigation = "react-navigation"
	FrameworkExpoRouter      = "expo-router"
)

React framework identifiers stored in api_endpoints.framework

Variables

This section is empty.

Functions

func DetectComponentAPICalls

func DetectComponentAPICalls(filePath string, patterns []TSAPIPattern) ([]domain.ComponentAPICall, error)

DetectComponentAPICalls scans a TS/JSX file and detects which React component makes which API calls. This is component-level detection (not file-level).

func DetectJavaConnections added in v0.2.0

func DetectJavaConnections(filePath string, cfg []JavaCallPattern) ([]domain.ServiceConnection, error)

DetectJavaConnections detects cross-service connections in a Java source file.

func DetectPythonConnections added in v0.2.0

func DetectPythonConnections(filePath string, cfg []PyCallPattern) ([]domain.ServiceConnection, error)

DetectPythonConnections uses tree-sitter AST to detect cross-service connections.

func DetectReactFrameworkFromLine

func DetectReactFrameworkFromLine(line string) string

DetectReactFrameworkFromLine is used for import-line-based detection when parsing incrementally without pre-built import list.

func DetectTSAPIConnections

func DetectTSAPIConnections(filePath string, patterns []TSAPIPattern) ([]domain.ServiceConnection, error)

DetectTSAPIConnections scans a TypeScript file for API service references using regex patterns from the config. Returns detected connections.

func ExtractFunctionCalls

func ExtractFunctionCalls(filePath string) ([]domain.FunctionCall, error)

ExtractFunctionCalls parses a Go file and extracts all function/method calls made within each function body, building a caller→callee call graph.

func ExtractInterfaceImpls

func ExtractInterfaceImpls(filePath string) ([]domain.InterfaceImpl, error)

ExtractInterfaceImpls parses a Go file and detects interface implementation relationships by matching struct methods against interface method sets defined in the same file.

Approach: within a single file, collect all interface definitions and all methods on struct receivers. For each interface method, if a struct has a method with the same name, we record it as an implementation. This is a heuristic (same-file, name-based) that works well for typical Go service code where interfaces and implementations coexist.

func ExtractReactRoutes

func ExtractReactRoutes(filePath string, imports []domain.Import) ([]domain.APIEndpoint, error)

ExtractReactRoutes detects React Router and React Navigation route definitions. It uses imports to identify the framework, then scans for route declarations.

func ExtractRoutes

func ExtractRoutes(filePath string, imports []domain.Import) ([]domain.APIEndpoint, error)

ExtractRoutes detects HTTP routes based on framework imports present in the file.

func ExtractTypeUsages

func ExtractTypeUsages(filePath string) ([]domain.TypeUsage, error)

ExtractTypeUsages parses a Go file and extracts type usage information from function/method signatures — which types are accepted as parameters and which types are returned.

func ModuleFromGoMod

func ModuleFromGoMod(repoPath string) string

ModuleFromGoMod extracts the Go module path from go.mod in the repo root.

func NormalizePath added in v0.3.0

func NormalizePath(path string) string

NormalizePath converts dynamic path segments to {id} placeholders for matching. Examples:

/users/123          → /users/{id}
/transfer-orders/45 → /transfer-orders/{id}
/api/v1/users       → /api/v1/users  (unchanged)
/items/:id          → /items/{id}
/items/$id          → /items/{id}

Types

type CatalogPatterns added in v0.2.0

type CatalogPatterns struct {
	GoPatterns   []GoCallPattern
	TSPatterns   []TSAPIPattern
	PyPatterns   []PyCallPattern
	JavaPatterns []JavaCallPattern
}

CatalogPatterns holds patterns that a catalog entry contributes per language.

type ConnectionResult

type ConnectionResult struct {
	Connections []domain.ServiceConnection
}

ConnectionResult holds cross-service connections detected in a Go source file.

func DetectConnections

func DetectConnections(filePath string, cfg *PatternConfig) (*ConnectionResult, error)

DetectConnections parses a Go file and detects cross-service connections using patterns from the config. If cfg is nil, returns empty result.

type CrossFileInterfaceMatcher

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

CrossFileInterfaceMatcher performs cross-file interface implementation detection by loading all interfaces and method sets from PostgreSQL, then matching across files. This is a second pass after per-file extraction.

func NewCrossFileInterfaceMatcher

func NewCrossFileInterfaceMatcher(pool *pgxpool.Pool, iiRepo domain.InterfaceImplRepository) *CrossFileInterfaceMatcher

NewCrossFileInterfaceMatcher creates a CrossFileInterfaceMatcher.

func (*CrossFileInterfaceMatcher) MatchAll

func (m *CrossFileInterfaceMatcher) MatchAll(ctx context.Context, repoID int64) (int, error)

MatchAll detects cross-file interface implementations for a repository. Returns the number of new interface_impl records created.

type FileResult added in v0.2.0

type FileResult struct {
	Symbols      []domain.Symbol
	Imports      []domain.Import
	Endpoints    []domain.APIEndpoint
	Connections  []domain.ServiceConnection
	FuncCalls    []domain.FunctionCall
	TypeUsages   []domain.TypeUsage
	IfaceImpls   []domain.InterfaceImpl
	CompAPICalls []domain.ComponentAPICall
	Module       string
	Framework    *FrameworkHint
}

FileResult is the unified output of parsing any source file.

type FrameworkHint added in v0.2.0

type FrameworkHint struct {
	Framework            string
	EntryPointMultiplier float64
	Reason               string
}

FrameworkHint carries a detected framework and entry point multiplier.

func DetectFrameworkFromPath added in v0.2.0

func DetectFrameworkFromPath(filePath string) *FrameworkHint

DetectFrameworkFromPath infers a framework from the file path alone. Returns nil if no known framework pattern matches.

type GoCallPattern

type GoCallPattern struct {
	PackageSuffix   string   `yaml:"package_suffix"`
	PackageContains string   `yaml:"package_contains"`
	Function        string   `yaml:"function"`
	Functions       []string `yaml:"functions"`
	TargetArg       int      `yaml:"target_arg"`
	ConnType        string   `yaml:"conn_type"`
}

GoCallPattern describes a Go function call pattern to detect.

type GoHandler added in v0.2.0

type GoHandler struct{}

GoHandler implements LanguageHandler for Go source files.

func (*GoHandler) Extensions added in v0.2.0

func (h *GoHandler) Extensions() []string

func (*GoHandler) Language added in v0.2.0

func (h *GoHandler) Language() Language

func (*GoHandler) Parse added in v0.2.0

func (h *GoHandler) Parse(ctx context.Context, filePath string, cfg *PatternConfig) (*FileResult, error)

type JavaCallPattern added in v0.2.0

type JavaCallPattern struct {
	ImportContains  string `yaml:"import_contains"`
	Annotation      string `yaml:"annotation"`
	TargetAttribute string `yaml:"target_attribute"`
	MethodCall      string `yaml:"method_call"`
	TargetArgIndex  int    `yaml:"target_arg"`
	ConnType        string `yaml:"conn_type"`
}

JavaCallPattern describes a Java AST pattern for connection detection.

type JavaHandler added in v0.2.0

type JavaHandler struct{}

JavaHandler implements LanguageHandler for Java source files.

func (*JavaHandler) Extensions added in v0.2.0

func (h *JavaHandler) Extensions() []string

func (*JavaHandler) Language added in v0.2.0

func (h *JavaHandler) Language() Language

func (*JavaHandler) Parse added in v0.2.0

func (h *JavaHandler) Parse(ctx context.Context, filePath string, cfg *PatternConfig) (*FileResult, error)

type Language added in v0.2.0

type Language string

Language identifies a supported programming language.

const (
	LangGo         Language = "go"
	LangTypeScript Language = "typescript"
	LangPython     Language = "python"
	LangJava       Language = "java"
)

type LanguageHandler added in v0.2.0

type LanguageHandler interface {
	Language() Language
	Extensions() []string
	Parse(ctx context.Context, filePath string, cfg *PatternConfig) (*FileResult, error)
}

LanguageHandler is implemented once per language.

type ParseResult

type ParseResult struct {
	Symbols   []domain.Symbol
	Imports   []domain.Import
	Endpoints []domain.APIEndpoint
	Module    string
}

ParseResult holds the symbols, imports, and endpoints extracted from a source file.

func ParseFile

func ParseFile(filePath string) (*ParseResult, error)

ParseFile parses a Go source file and extracts symbols and imports.

func ParseJSXFile

func ParseJSXFile(filePath string) (*ParseResult, error)

ParseJSXFile parses a .tsx/.ts/.jsx/.js file and extracts symbols and imports. Symbol kinds produced: "component", "hook", "interface", "type_alias".

func ParseJavaFile added in v0.2.0

func ParseJavaFile(filePath string) (*ParseResult, error)

ParseJavaFile parses a Java source file using tree-sitter and extracts symbols (classes, methods), imports, and Spring MVC API endpoints.

func ParsePythonFile

func ParsePythonFile(filePath string) (*ParseResult, error)

ParsePythonFile parses a Python source file using tree-sitter and extracts symbols, imports, and API endpoints.

type PatternConfig

type PatternConfig struct {
	Go         []GoCallPattern   `yaml:"go"`
	TypeScript []TSAPIPattern    `yaml:"typescript"`
	Python     []PyCallPattern   `yaml:"python"`
	Java       []JavaCallPattern `yaml:"java"`
}

PatternConfig holds all detection patterns. Each language has a flat list of patterns — conn_type on each pattern determines what kind of connection it represents. No hardcoded categories, so any conn_type (grpc, kafka_consume, redis, nats, …) is supported.

func LoadPatterns

func LoadPatterns(repoPath string) (*PatternConfig, error)

LoadPatterns loads detection patterns with the following merged priority:

  1. Embedded default_patterns.yaml (base)
  2. Auto-discovered catalog patterns (from dep files)
  3. ~/.goatlas/goatlas.yaml (global user override)
  4. {repoPath}/goatlas.yaml (per-repo override, highest)

func LookupCatalog added in v0.2.0

func LookupCatalog(deps *ProjectDeps) *PatternConfig

LookupCatalog returns all patterns applicable to the given ProjectDeps.

type ProjectDeps added in v0.2.0

type ProjectDeps struct {
	GoModules       []string          // e.g. ["google.golang.org/grpc", "github.com/segmentio/kafka-go"]
	NPMPkgs         []string          // e.g. ["kafkajs", "@grpc/grpc-js", "axios"]
	PyPkgs          []string          // e.g. ["grpcio", "kafka-python", "httpx"]
	MavenPkgs       []string          // e.g. ["io.grpc:grpc-stub", "org.springframework.kafka:spring-kafka"]
	TSConfigAliases map[string]string // alias prefix → target prefix, e.g. {"@/": "src/"}
}

ProjectDeps holds discovered dependency identifiers per ecosystem.

func DiscoverDependencies added in v0.2.0

func DiscoverDependencies(repoPath string) (*ProjectDeps, error)

DiscoverDependencies reads root-level manifest files from repoPath. Missing or malformed files are silently skipped.

type PyCallPattern added in v0.2.0

type PyCallPattern struct {
	ModuleContains string `yaml:"module_contains"`
	CallPattern    string `yaml:"call_pattern"`
	TargetArgIndex int    `yaml:"target_arg"`
	TargetKeyword  string `yaml:"target_keyword"`
	ConnType       string `yaml:"conn_type"`
}

PyCallPattern describes a Python call pattern for connection detection.

type PythonHandler added in v0.2.0

type PythonHandler struct{}

PythonHandler implements LanguageHandler for Python source files.

func (*PythonHandler) Extensions added in v0.2.0

func (h *PythonHandler) Extensions() []string

func (*PythonHandler) Language added in v0.2.0

func (h *PythonHandler) Language() Language

func (*PythonHandler) Parse added in v0.2.0

func (h *PythonHandler) Parse(ctx context.Context, filePath string, cfg *PatternConfig) (*FileResult, error)

type Registry added in v0.2.0

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

Registry maps file extensions to language handlers.

func NewRegistry added in v0.2.0

func NewRegistry() *Registry

NewRegistry constructs a registry with all default language handlers registered.

func (*Registry) HandlerFor added in v0.2.0

func (r *Registry) HandlerFor(ext string) LanguageHandler

HandlerFor returns the handler for a given file extension, or nil.

func (*Registry) Register added in v0.2.0

func (r *Registry) Register(h LanguageHandler)

Register adds a handler for all extensions it declares. Panics if two handlers claim the same extension.

type TSAPIPattern

type TSAPIPattern struct {
	Pattern  string `yaml:"pattern"`
	ConnType string `yaml:"conn_type"`
	FileGlob string `yaml:"file_glob"`
}

TSAPIPattern describes a regex pattern to detect API service references in TS/JS files.

type TypeScriptHandler added in v0.2.0

type TypeScriptHandler struct{}

TypeScriptHandler implements LanguageHandler for JS/TS/JSX/TSX files.

func (*TypeScriptHandler) Extensions added in v0.2.0

func (h *TypeScriptHandler) Extensions() []string

func (*TypeScriptHandler) Language added in v0.2.0

func (h *TypeScriptHandler) Language() Language

func (*TypeScriptHandler) Parse added in v0.2.0

func (h *TypeScriptHandler) Parse(ctx context.Context, filePath string, cfg *PatternConfig) (*FileResult, error)

Jump to

Keyboard shortcuts

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