
Diagramming Code
FreeVisualize code architecture with Mermaid diagrams.
Free · Opens the source repo
What Diagramming Code does
Diagramming Code is a skill designed for developers who need to create visual representations of their code architecture using Mermaid diagrams. By generating diagrams from Trailmark's code graphs, this skill provides a straightforward way to visualize complex relationships within codebases. It supports various types of diagrams, including call graphs, class hierarchies, module dependencies, containment diagrams, complexity heatmaps, and data flow visualizations. This capability is particularly useful for understanding the structure and flow of large codebases, making it easier to identify potential issues or areas for improvement.
The skill operates by utilizing a pre-made script that handles the conversion of code graphs into Mermaid syntax. Users can specify the type of diagram they want to generate and set parameters such as the focus function and depth of traversal. This flexibility allows for tailored visualizations that can highlight specific aspects of the code, such as function calls or class structures. The integration with Trailmark ensures that the diagrams are based on accurate and up-to-date representations of the code, eliminating the need for manual diagramming.
This skill is ideal for software engineers, architects, and technical leads who need to communicate complex code structures visually. By providing a clear and concise way to illustrate relationships and dependencies, it aids in discussions about architecture, design decisions, and code reviews. Moreover, the ability to generate complexity heatmaps can help teams focus their efforts on the most challenging parts of the code, facilitating better resource allocation and risk management.
To use this skill effectively, users must have Trailmark installed, as it is a prerequisite for generating the diagrams. The skill also includes a version check to ensure compatibility with the native diagram command in Trailmark, providing a seamless experience whether using the bundled script or the latest CLI features.
When to use it
Use this skill when you need to create visual diagrams of code architecture, such as call graphs or class hierarchies, to aid in analysis and communication.
When not to use it
This skill is not suitable for querying code graphs without visualization or for tasks like mutation testing; use relevant skills for those purposes instead.
What you can build with it
Visualizing Call Paths
Generate a call graph to visualize the paths between functions in your code, helping identify dependencies.
Mapping Class Inheritance
Create a class hierarchy diagram to understand the relationships and inheritance structures among classes.
Highlighting Complexity Hotspots
Use complexity heatmaps to identify areas in your code that may require refactoring or optimization.
How to install Diagramming Code
View source1. Install with the skills CLI
npx skills add trailofbits/skills/diagramming-code --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by trailofbitsDiagramming Code
Generates Mermaid diagrams from Trailmark's code graph. A pre-made script
handles Mermaid syntax generation; Claude selects the diagram type and
parameters. Trailmark 0.4.0 includes a native trailmark diagram command; use
it only after a version/command check, otherwise use this skill's bundled
script.
When to Use
- Visualizing call paths between functions
- Drawing class inheritance hierarchies
- Mapping module import dependencies
- Showing class structure with members
- Highlighting complexity hotspots with color coding
- Tracing data flow from entrypoints to sensitive functions
When NOT to Use
- Querying the graph without visualization (use the
trailmarkskill) - Mutation testing triage (use the
genotoxicskill) - Architecture diagrams not derived from code (draw by hand)
Prerequisites
trailmark must be installed. If uv run trailmark fails, run:
uv pip install trailmark
DO NOT fall back to hand-writing Mermaid from source code reading. The script uses Trailmark's parsed graph for accuracy. If installation fails, report the error to the user.
Version Gate
Check whether native v0.4 diagram support exists:
trailmark diagram --help 2>/dev/null || uv run trailmark diagram --help 2>/dev/null
If this succeeds, you may use trailmark diagram. If it fails, use
uv run {baseDir}/scripts/diagram.py, which keeps the older skill workflow
intact. Do not assume the native CLI exists on Trailmark 0.2.x.
Quick Start
uv run {baseDir}/scripts/diagram.py \
--target {targetDir} --language auto --type call-graph \
--focus main --depth 2
# Trailmark 0.4.0+ equivalent after the Version Gate succeeds
uv run trailmark diagram \
--target {targetDir} --language auto --type call-graph \
--focus main --depth 2
Output is raw Mermaid text. Wrap in a fenced code block:
```mermaid
flowchart TB
...
```
Diagram Types
├─ "Who calls what?" → --type call-graph
├─ "Class inheritance?" → --type class-hierarchy
├─ "Module dependencies?" → --type module-deps
├─ "Class members and structure?" → --type containment
├─ "Where is complexity highest?" → --type complexity
└─ "Path from input to function?" → --type data-flow
For detailed examples of each type, see references/diagram-types.md.
Workflow
Diagram Progress:
- [ ] Step 1: Verify trailmark is installed
- [ ] Step 2: Identify diagram type from user request
- [ ] Step 3: Determine focus node and parameters
- [ ] Step 4: Run diagram.py script (or native trailmark diagram on v0.4+)
- [ ] Step 5: Verify output is non-empty and well-formed
- [ ] Step 6: Embed diagram in response
Step 1: Run uv run trailmark analyze --language auto --summary {targetDir}. Install
if it fails. Then run pre-analysis via the programmatic API:
from trailmark.query.api import QueryEngine
engine = QueryEngine.from_directory("{targetDir}", language="auto")
engine.preanalysis()
Pre-analysis enriches the graph with blast radius, taint propagation,
and privilege boundary data used by data-flow diagrams.
If auto-detection is wrong for the target, rerun with an explicit language or
comma-separated list such as python,rust.
Step 2: Match the user's request to a --type using the decision tree
above.
Step 3: For call-graph and data-flow, identify the focus function.
Default --depth 2. Use --direction LR for dependency flows.
Step 4: Run the script and capture stdout. If the native v0.4 CLI is available, either command is acceptable; prefer the bundled script when you need behavior consistent with this skill's references.
Step 5: Check: output starts with flowchart or classDiagram,
contains at least one node. If empty or malformed, consult
references/mermaid-syntax.md.
Step 6: Wrap output in ```mermaid ``` code fence.
Script Reference
uv run {baseDir}/scripts/diagram.py [OPTIONS]
# or, on Trailmark 0.4.0+:
uv run trailmark diagram [OPTIONS]
| Argument | Short | Default | Description |
|---|---|---|---|
--target | -t | required | Directory to analyze |
--language | -l | python | Source language |
--type | -T | required | Diagram type (see above) |
--focus | -f | none | Center diagram on this node |
--depth | -d | 2 | BFS traversal depth |
--direction | TB | Layout: TB (top-bottom) or LR (left-right) | |
--threshold | 10 | Min complexity for complexity type |
Examples
# Call graph centered on a function
uv run {baseDir}/scripts/diagram.py -t src/ -T call-graph -f parse_file
# Class hierarchy for a Rust project
uv run {baseDir}/scripts/diagram.py -t src/ -l rust -T class-hierarchy
# Module dependency map, left-to-right
uv run {baseDir}/scripts/diagram.py -t src/ -T module-deps --direction LR
# Class members
uv run {baseDir}/scripts/diagram.py -t src/ -T containment
# Complexity heatmap (threshold 5)
uv run {baseDir}/scripts/diagram.py -t src/ -T complexity --threshold 5
# Data flow from entrypoints to a specific function
uv run {baseDir}/scripts/diagram.py -t src/ -T data-flow -f execute_query
Customization
Direction: Use TB (default) for hierarchical views, LR for
left-to-right flows like dependency chains.
Depth: Increase --depth to see more of the call graph. Decrease to
reduce clutter. The script warns if the diagram exceeds 100 nodes.
Focus: Always use --focus for call-graph on non-trivial codebases.
For data-flow, omitting focus auto-targets the top 10 complexity hotspots.
Language: Prefer --language auto for polyglot or unfamiliar repos.
Use an explicit language only when you know the target is single-language or
you need to exclude unrelated components.
Supporting Documentation
- references/diagram-types.md - Detailed docs and Mermaid examples for each diagram type
- references/mermaid-syntax.md - ID sanitization, escaping, style definitions, and common pitfalls
Frequently asked questions about Diagramming Code
Similar skills
Markdown to HTML Conversion
Efficiently convert Markdown documents to HTML.
Code Tour
Create structured walkthroughs for codebases.
Acquire Codebase Knowledge
Streamline onboarding with comprehensive codebase documentation.
Documentation & Modernization
Streamline codebase documentation and modernization planning.
Azure Resource Visualizer
Generate architecture diagrams for Azure resources.
CLAUDE.md Improver
Optimize your CLAUDE.md files for better project context.
