Diagramming Code
Trail of BitsOfficialPublished by Trail of Bits
- Skill
- Content generator
- Software development
- CC-BY-SA-4.0
- Low risk
- Has scripts
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides a systematic way to visualize codebases by converting Trailmark code graph data into Mermaid diagrams. It supports various architectural views, including call graphs, class hierarchies, module dependencies, and complexity heatmaps. By leveraging the underlying graph structure, it ensures accurate representations of code relationships, helping developers identify hotspots, trace data flows, and understand structural dependencies without manual diagramming.
What it does
- Generates Mermaid call graphs to visualize function invocation paths.
- Creates class hierarchy and containment diagrams to show structural relationships.
- Maps module dependencies to clarify project architecture.
- Produces complexity heatmaps to identify high-risk code areas.
- Visualizes data flow paths from entrypoints to sensitive functions.
- Automatically handles node ID sanitization and Mermaid syntax formatting.
When to use it
- When you need to document or understand the call structure of a specific function.
- When analyzing the inheritance or composition of classes in a codebase.
- When identifying high-complexity functions that may require refactoring.
- When tracing how data moves through an application to assess attack surfaces.
- When mapping module-level dependencies to simplify project navigation.
Advantages
- Ensures accuracy by deriving diagrams directly from parsed code graphs.
- Reduces manual effort in creating and maintaining architectural documentation.
- Provides consistent styling for complexity and edge confidence levels.
- Supports focused visualization to prevent cluttered, unreadable diagrams.
- Integrates seamlessly with Trailmark's analysis capabilities.
Usage examples
- “Generate a call graph for the function 'process_payment' in the current directory.”
- The agent runs the diagram script with the call-graph type focused on 'process_payment' and returns a Mermaid flowchart.
- “Show me a complexity heatmap for the src folder.”
- The agent generates a Mermaid flowchart where functions are color-coded by cyclomatic complexity, highlighting high-complexity areas.
- “Map the module dependencies for this project.”
- The agent produces a Mermaid flowchart showing the import relationships between modules in the target directory.
- “Visualize the data flow from entrypoints to the 'authenticate' function.”
- The agent creates a Mermaid diagram tracing the path from system entrypoints to the specified function.
Install
Download the skill as a ZIP:
https://autogineer.com/agent-skills/trailofbits/diagramming-code/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip diagramming-code.zip -d .agents/skills
Documentation by Trail of Bits
Diagramming 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 tool install trailmark
# Python snippets: uv run --with trailmark python - (a tool env is not importable)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/nullIf 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 <function> --depth 2
# Trailmark 0.4.0+ equivalent after the Version Gate succeeds
uv run trailmark diagram \
--target {targetDir} --language auto --type call-graph \
--focus <function> --depth 2Output 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-flowFor 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 responseStep 1: Run uv run trailmark analyze --language auto --summary {targetDir}. Install
if it fails. Do not run engine.preanalysis() for a diagram: the diagram
command builds its own graph and does not use pre-analysis data, so every
diagram type is identical with or without it. data-flow uses the
entrypoints Trailmark records while parsing.
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/ -l auto -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/ -l auto -T module-deps --direction LR
# Class members
uv run {baseDir}/scripts/diagram.py -t src/ -l auto -T containment
# Complexity heatmap (threshold 5)
uv run {baseDir}/scripts/diagram.py -t src/ -l auto -T complexity --threshold 5
# Data flow from entrypoints to a specific function
uv run {baseDir}/scripts/diagram.py -t src/ -l auto -T data-flow -f execute_queryCustomization
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
Files
- ATTRIBUTION.mdAdded by AutoGineer935 B
- LICENSELicence file added by AutoGineer19.7 KiB
- SKILL.md6.7 KiB
- agents/openai.yaml241 B
- assets/trail-of-bits-mark.svg3.0 KiB
- references/diagram-types.md5.1 KiB
- references/mermaid-syntax.md2.9 KiB
- scripts/diagram.pyScript389 B
- scripts/test_skill_commands.pyScript1.1 KiB
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Needs Python, Needs Node.js
Security
What our scanner noticed· Low risk
- Scripts that your agent may run
This skill includes scripts that your agent may run. Read them before you use it.
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Published by
- Trail of Bits
- Publisher
- Trail of Bits (Official)
- Source
- trailofbits/skills · plugins/trailmark/skills/diagramming-code · commit e4dd0bb
- Licence
- Creative Commons Attribution-ShareAlike 4.0 International (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by Trail of Bits or Trail of Bits.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download diagramming-code.zip