A Go tool that generates visual graphs of your code structure using Mermaid diagrams. It can show you import relationships, function calls, and highlight specific parts of your codebase.
This tool parses your Go code and creates three types of graphs:
Import graphs - Shows how your packages depend on each other. You can see it at the package level or drill down to individual files.
Call graphs - Maps out which functions call which other functions across your codebase. Useful for understanding code flow.
Target graphs - Lets you mark specific structs or functions with comments and then visualizes where they're used throughout your project.
All the output is in Mermaid format, so you can view it in GitHub, most markdown viewers, or any tool that supports Mermaid diagrams. The tool now uses the go-mermaid package under the hood for generating the diagrams.
go install gmonarque/go-code-graph@latest
Or if you want to build it yourself:
git clone https://github.com/gmonarque/go-code-graph.git
cd go-code-graph
go build -o go-code-graph ./cmd/go-code-graph
# Show file-level imports for current directory
go-code-graph import
# Package-level view instead
go-code-graph import --package-level
# Save to a specific file
go-code-graph import -o my-imports.mmd
# Show public function calls
go-code-graph call
# Include internal/private calls too
go-code-graph call --include-internal
# Save it somewhere
go-code-graph call -o calls.mmd
First, mark the stuff you care about in your code:
// @gocodegraph:include
func SomeImportantFunction() {
// this will show up in target graphs
}
// @gocodegraph:include
type KeyStruct struct {
// this too
}
Then generate the graph:
go-code-graph target -o targets.mmd
Here's what you get - a simple Mermaid diagram:
graph TD;
main_go["main.go"];
internal_parser_parser_go["internal/parser/parser.go"];
main_go --> internal_parser_parser_go;
You can paste this into GitHub markdown, Notion, or any Mermaid viewer to see the actual diagram.
Global stuff:
-o, --output
- where to save the output file
Import graphs:
--package-level
- group by packages instead of individual files
Call graphs:
--include-internal
- show private function calls too (can get noisy)
It's handy when you're trying to understand a new codebase, refactoring, or just want to visualize how your code is structured. The target graphs are especially useful for tracking down where important types or functions are being used.