How meian/rev-callgraph works
Project type and purpose
• rev-callgraph is a command-line tool written in Go.
• It analyzes Go code in a workspace and produces a reverse call graph for a specified function or method.
File structure
• Top-level:
• cmd/ and main.go – CLI entrypoint and command definitions (cobra-style).
• internal/ – core packages not exposed externally:
• astquery – AST‐based caller extraction
• callgraph – reverse call graph traversal
• format – output serializers (tree, JSON, dot)
• gomod – module scanning and workspace resolution
• grep – text-based search (fallback or test)
• symbol – symbol parsing and representation
• testdata/ – sample Go modules and code for e2e tests
• e2e_test.go – end-to-end test harness
• config/devcontainer, .github, Makefile, etc. – CI/dev env support
README for additional insights
• Describes CLI flags, supported output formats, examples.
• No pre-drawn architecture but clarifies the core flow: directory scan → parsing → graph build → formatting.
a. Main components:
1. CLI Frontend
2. Workspace Scanner (gomod)
3. AST Query Engine (astquery + symbol)
4. Call Graph Analyzer (callgraph)
5. Formatter (format)
6. File System / Go Toolchain (external)
b. Relationships & data flow:
• User invokes CLI → parses flags/target.
• CLI calls Workspace Scanner to locate modules and package roots.
• For each package, invoke AST Query Engine to locate call sites and build symbol table.
• Feed AST‐based results into Call Graph Analyzer for reverse traversal up to max-depth.
• Pass final graph structure into Formatter for desired output (tree, JSON, dot).
• Formatter writes to STDOUT (or file).
c. Architectural patterns/design principles:
• Separation of concerns – each internal/ package has a single responsibility.
• Layered pipeline – scanner → parser → analyzer → serializer.
• Pure Go, no external services or databases.
d. Key technologies/frameworks:
• Go 1.24+ language and standard library (go/parser, ast, etc.)
• Cobra/Viper style CLI in cmd/ (implicit from root.go)
• JSON/DOT serialization in internal/format
• Go modules for workspace discovery