Call-Graph and Architecture Analysis for Go#
Before refactoring a Go codebase, engineers need structural answers that text search and single-hop references do not provide: which callers break if a signature changes, which tests transitively reach a modified function, and whether a pull request introduces a forbidden package import or a complexity regression.
gograph indexes a Go repository locally into an AST and optional type-checked (CHA/SSA) dependency graph. Query it from the terminal, enforce architectural constraints in CI, or expose the same graph to AI coding agents over stdio MCP—without hosted services, embeddings, or target-code execution.
Interactive browser demo → · CI Architecture Gates → · Compare with gopls, golangci-lint & ripgrep →
Core Workflows#
1. Blast-Radius and Call-Graph Inspection#
Trace transitive callers, interface implementations, and call paths before changing a shared function or interface. Render any call or package dependency slice as a Mermaid diagram.
gograph build . --precise
gograph impact Store.Save
gograph callers Store.Save --mermaid
gograph path HandleCheckout CommitLedger --mermaid
2. Targeted Test Selection and Coverage Gaps#
Map transitive static test reachability for uncommitted changes and combine it with go test -coverprofile to locate unexecuted lines.
# Print runnable `go test -run` commands for uncommitted changes
gograph tests --uncommitted --format go-test --max-depth 3
# List called production symbols with no static test path
gograph untested --exclude-interface-methods --top 20
# List changed lines that a coverage profile never executed
gograph uncovered --uncommitted --coverprofile cover.out
3. CI Package Boundaries and Quality Gates#
Commit layer import rules in gograph/boundaries.json and metric thresholds in .gograph.yml to enforce repository structure in CI.
gograph boundaries --create # Snapshot current package layers into gograph/boundaries.json
gograph gate init # Scaffold .gograph.yml complexity/instability/god-object limits
gograph build . --precise --strict && gograph boundaries && gograph gate
See the CI Architecture Gates guide → for policy schemas and GitHub Actions configuration.
4. Built-In Stdio MCP Server#
For teams using Claude Code, Cursor, Codex, Copilot, or Antigravity, the same binary provides a 70-tool local stdio MCP server (gograph mcp .). It builds an in-memory graph on first use and refreshes changed packages automatically, with no manual build step required.
See MCP & AI Agent Integration → or Official MCP Registry →.
Installation#
brew install --cask ozgurcd/tap/gograph
go install github.com/ozgurcd/gograph/cmd/gograph@latest
Follow the Getting Started guide → to index a module and run initial queries.
Indexed Signals#
| Structural Signal |
Queryable Facts |
| Symbols & Types |
Functions, methods, structs, interfaces, fields, embeddings, constructors, and constants |
| Call & Dispatch Graph |
Direct calls plus type-checked CHA/SSA interface dispatch and promoted-method forwarding |
| HTTP & SQL Surface |
net/http, Gin, Echo, and Chi routes; static PostgreSQL query access, tables, and verbs |
| Testing & Coverage |
Direct and transitive test-to-production paths, runnable go test -run filters, and coverprofile gaps |
| Architecture & Quality |
Package fan-in/fan-out instability, McCabe complexity, god objects, arity, and layer boundaries |
| Security & Concurrency |
Interprocedural source-to-sink taint candidates (flow), goroutines, channels, and sync primitives |
Documentation#
- Getting Started — Install
gograph, choose AST vs. --precise mode, and inspect a repository.
- Command Reference — Complete CLI flag, output-mode (
--json, --files-only, --mermaid), and MCP parity reference.
- CI Architecture Gates — Enforce package boundaries, instability limits, and complexity ceilings in CI.
- Tool Comparisons — How
gograph complements gopls, golangci-lint, go-callvis, and ripgrep.
- Engineering Workflows — Onboarding, safe-edit refactoring, package splits, and security-flow review playbooks.
- Evidence & Methodology — Reproducible structural-evidence benchmark and raw JSON outputs.
Local Go call-graph, blast-radius, and CI architecture-gate CLI, with a built-in stdio MCP server.
Install gograph, index a Go module, and run your first call-graph, test-selection, and architecture queries.
Requirements Go 1.27.0 or newer on PATH A local Go module (go.mod) or Go workspace (go.work) 1. Install the CLI Install with Homebrew or go install:
# Homebrew brew install --cask ozgurcd/tap/gograph # Or via Go toolchain go install github.com/ozgurcd/gograph/cmd/gograph@latest Verify the installed binary and check for PATH shadowing:
gograph version gograph doctor --json To build from source:
...
This reference documents every command available in the gograph CLI, compiled directly from the production source code.
Global Flags Global flags may appear before or after the command:
--json: Structured output for query/composed-analysis commands and workspace build, status, query, path, and impact. --files-only: Deduplicated paths for the commands listed under Output Modes; an empty result writes zero lines. --mermaid: Mermaid output for callers, callees, impact, endpoint, dependents, deps, path, and coupling. Bare gograph --mermaid is shorthand for gograph diagram. -i <message> / --intention <message>: Technical rationale recorded with CLI command telemetry. It is mandatory for analytical commands while an the caller selects an active audit session; session, MCP startup, build, installation, help, version, doctor, stale, stats, capabilities, wiki, and doc commands do not require it. --rev <ref>: Answer a graph query from the tree of a Git commit, branch or tag instead of the working tree (gograph --rev 3b37747 source internal/app/client.go, gograph callers Run --rev origin/main). The first query for a commit extracts the project with git archive into .gograph/revs/<commit>/ (a standalone repository, so the scanner applies only the commit’s own ignore rules) and builds an AST graph there; later queries reuse it. The graph uses the working graph’s recorded build tags and exclusions unless --tags or GOFLAGS -tags select others, which rebuilds it. Not accepted by build, mcp, stale or workspace, or with --uncommitted/--since. CLI only. Delete .gograph/revs to reclaim space. --no-refresh: Answer from the persisted graph even when it is stale (with the stale warning). Without it, a CLI graph query rebuilds a stale graph first: changed packages only, with the recorded precision, build tags and excluded directories, noted on stderr (or in warning under --json). GOGRAPH_NO_REFRESH=1 does the same for every call. A different build context, another caller’s active session and --rev never rebuild, nor do stale, stats, changes and the enforcement commands gate, check and boundaries (gate still fails on a stale graph). --session-id ID / GOGRAPH_SESSION=ID: Select the caller’s session returned by session create. The flag overrides the environment. Omission keeps a read-only caller outside other agents’ audits; writes still refuse when another caller owns an active session. Independent callers may create concurrently. CLI commands answer from the persisted graph. When selected files or the Go build context changed since the last build, graph-backed commands print a WARNING on stderr naming the changed files and asking for gograph build .; JSON output carries the same text in warning and reports graph_state.freshness: "stale". stale, stats and changes report freshness themselves and add no warning.
...
Linters such as golangci-lint catch local defects and style issues inside individual files, whereas architectural drift occurs across package boundaries: an HTTP handler imports a database package directly, a core struct accumulates dozens of methods, or a pull request raises cyclomatic complexity in a hot path.
gograph provides deterministic CLI gates that enforce repository-wide structure directly from the compiled call and import graph.
1. Package Boundary Enforcement (gograph boundaries) Define allowed import layers in a committed gograph/boundaries.json file so local runs and CI enforce the same architecture.
...
gograph does not replace your language server, linter, or text search tool. Each tool answers a different class of question; gograph covers repository-wide structural queries, transitive impact, and CI architecture gates.
Comparison Matrix Capability gograph gopls golangci-lint go-callvis ripgrep (rg) Primary Role Persisted call graph, blast radius & CI architecture gates Live editor LSP (autocomplete, rename, diagnostics) File/package lint rules & style checks Graphviz call-graph rendering Literal & regex text search Non-Compiling Code Yes (AST mode); --precise adds CHA/SSA Partial (requires valid workspace) No (most linters require type-checking) No (requires full SSA build) Yes Transitive Blast Radius (impact) Built-in CLI & MCP Single-hop references No Visual only No Change-Scoped Test Selection Built-in (tests --uncommitted --format go-test) No No No No CI Package Layer Boundaries Built-in (boundaries, gate, validate) No Via plugins (depguard) No No HTTP Route / SQL / Env / Flow Census Built-in No Limited (per-linter) No Regex heuristic only Machine-Readable JSON & Mermaid Native (--json, --mermaid, --files-only) LSP protocol / experimental MCP Lint reports (JSON/SARIF) DOT / SVG / PNG Line matches Built-In MCP Server 70 project + 4 workspace tools Experimental MCP No No No gograph vs gopls gopls is the official Go language server. It handles cursor-level, live compiler operations inside an editor: go-to-definition, rename refactoring, hover types, live diagnostics, and exact single-hop references.
...
To maximize efficiency, reduce latency, and guarantee safety when modifying codebases, we recommend following these standardized workflows. These steps can be programmed into AI system instructions or executed manually.
Workflow 1: Onboarding to a New Repo When opening an unfamiliar Go repository, use this workflow to get oriented in seconds:
Verify Index Status: gograph stats gograph stale If stale or missing, run gograph build .. Find High-Risk Hotspots: gograph hotspot --top 10 Identifies the most heavily referenced functions in the codebase. Map Package Coupling: gograph coupling Gives a high-level table showing package stability and dependencies. Inspect the Global API Surface: gograph skeleton Exposes every package signature with bodies stripped. Workflow 2: Safe-Edit Symbol Lifecycle Before changing the signature or behavior of any function, method, or struct, follow this cycle:
...
gograph is an agent-oriented static-analysis tool. Humans can use the CLI, while MCP clients such as Claude Code, Cursor, Copilot, Antigravity, and OpenCode can request the same structured repository evidence. Results follow the documented AST, precise-analysis, and heuristic limits; they are not runtime proof.
Text search, gopls, and gograph have different jobs For Codex, see the Codex MCP setup guide, including matching build/startup exclusions for symlinked skills directories.
rg, grep, and find are appropriate for literal text, documentation, configuration, generated content, and non-Go files. Text matching alone cannot resolve Go interface satisfaction or distinguish a call expression from a comment or string.
...
gograph is published to the official Model Context Protocol Registry under this server ID:
io.github.ozgurcd/gograph The server ID is a Registry identifier, not a web address. You can inspect its active versions in the official Registry API.
The official Registry is currently in preview. Its API, stored data, and client support may change before general availability.
Registry installation is a separate path Homebrew and go install place the normal gograph CLI on PATH. You then configure an MCP client to run gograph mcp <project-directory>. The Claude Code marketplace entry supplies workflow guidance but still needs that binary and a project registration.
...