| name | golang-architecture |
| description | Go package dependency analysis and call graph visualization using goda, go-callvis, go mod graph, and go list. Use when asked to visualize architecture, understand package relationships, find circular dependencies, or map call flows in a Go project. Equivalent to "und export -dependencies" from SciTools Understand.
|
| allowed-tools | Bash(go *), Bash(goda *), Bash(go-callvis *), Bash(dot *), Read |
Go Architecture & Dependency Analysis
This skill handles dependency graphs, call graphs, and package structure analysis — the Go equivalent
of und export -dependencies and the Architecture Diagrams view in SciTools Understand.
Quick Reference
| Und Command | Go Equivalent |
|---|
und export -dependencies | goda list ./...:all (текст) / goda tree ./...:all (дерево) |
| Architecture Diagrams | go-callvis (SVG/PNG) / goda graph | dot (SVG) |
| Dependency Weight | goda cut ./...:all |
| Dependency Tree | go mod graph / goda tree ./...:all |
und list files | go list ./... |
und list functions | go list -json ./... |
Tool Installation Check
which goda || echo "MISSING: go install github.com/loov/goda@latest"
which go-callvis || echo "MISSING: go install github.com/ofabry/go-callvis@latest"
which dot || echo "MISSING: brew install graphviz (macOS) / apt install graphviz (Linux)"
Workflow A — Package Dependency Analysis (goda)
Важно: goda graph выводит текст в формате DOT (для программ типа graphviz).
Для читаемого вывода в терминале используйте goda list и goda tree.
A1. Список зависимостей (текст)
goda list ./...:all
goda list github.com/myorg/myproject/cmd/server:...
goda list ./...:all | grep -v "^std"
A2. Дерево зависимостей (текст, наглядная структура)
goda tree ./...:all
goda tree github.com/myorg/myproject/cmd/server:...
A3. Анализ веса зависимостей
goda cut ./...:all
goda weight ./path/to/binary
A4. Поиск циклических зависимостей
go list -json -e ./... | jq -r 'select(.Error != null) | "\(.ImportPath): \(.Error.Err)"'
go build ./... 2>&1 | grep -i "import cycle"
A5. Экспорт в SVG/PNG (только если нужна картинка)
goda graph ./... > deps.dot
dot -Tsvg deps.dot -o deps.svg
open deps.svg
xdg-open deps.svg
dot -Tpng deps.dot -o deps.png
Workflow B — Call Graph (go-callvis)
B1. Basic Call Graph
MODULE=$(go list -m)
go-callvis -group pkg,dom -file callgraph.svg $MODULE
go-callvis -group pkg,dom -focus github.com/myorg/myproject/internal/service -file service-calls.svg $MODULE
B2. Filtered Call Graph
go-callvis -nostd -group pkg,dom -file callgraph-noext.svg $MODULE
go-callvis -include "github.com/myorg/myproject" -group pkg -file internal-only.svg $MODULE
go-callvis -group type,pkg -file type-graph.svg $MODULE
Workflow C — Module Dependency Tree
go mod graph
go mod graph | grep "^$(go list -m) " | sort
go mod graph | awk '{ print $1 " -> " $2 }' | sort -u | \
awk 'BEGIN { print "digraph {" } { print " \"" $1 "\" -> \"" $3 "\"" } END { print "}" }' > modules.dot
dot -Tsvg modules.dot -o modules.svg
Workflow D — Project Inventory (go list)
go list ./...
go list -json ./...
go list -json -e ./... | jq 'select(.Error != null) | {pkg: .ImportPath, err: .Error.Err}'
go list -json ./... | jq -r '.Imports[]' | sort -u | grep -v "^$(go list -m)"
go list -json ./... | jq '{pkg: .ImportPath, imports: (.Imports | length)}'
Workflow E — Code Documentation (go doc)
go doc net/http.ListenAndServe
go doc -all ./internal/service
go list ./... | xargs -I{} go doc {} 2>/dev/null | grep "^func\|^type\|^var\|^const" | head -100
Reading Architecture Output
When interpreting goda tree / goda list output:
- Каждая строка в
goda list — один пакет с его полным import path
- В
goda tree вложенность показывает транзитивные зависимости
- Пакет, встречающийся глубоко во многих ветках
goda tree — общая зависимость (potential bottleneck)
- Packages с длинной цепочкой в
goda cut — кандидаты на замену более лёгкими альтернативами
- Cycles (
A → B → A) = ошибка import cycle not allowed при сборке — критично
Key architectural questions to answer with these tools:
- Cycles? —
go build ./... 2>&1 | grep -i cycle
- Heaviest deps? —
goda cut ./...:all
- Dependency depth? —
goda tree ./...:all (depth of nesting)
- Isolation check — are
internal/ packages only referenced from within their parent?
- Layering — does the flow respect
cmd → internal → pkg without back-references?
Supporting Files