diagramming-code
Original:🇺🇸 English
Translated
1 scriptsChecked / no sensitive code detected
Generates Mermaid diagrams from Trailmark code graphs. Produces call graphs, class hierarchies, module dependency maps, containment diagrams, complexity heatmaps, and attack surface data flow visualizations. Use when visualizing code architecture, drawing call graphs, generating class diagrams, creating dependency maps, producing complexity heatmaps, or visualizing data flow and attack surface paths as Mermaid diagrams.
19installs
Sourcetrailofbits/skills
Added on
NPX Install
npx skill4agent add trailofbits/skills diagramming-codeTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →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.
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 skill)
trailmark - Mutation testing triage (use the skill)
genotoxic - Architecture diagrams not derived from code (draw by hand)
Prerequisites
trailmark must be installed. If fails, run:
uv run trailmarkbash
uv pip install trailmarkDO 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.
Quick Start
bash
uv run {baseDir}/scripts/diagram.py \
--target {targetDir} --type call-graph \
--focus main --depth 2Output is raw Mermaid text. Wrap in a fenced code block:
markdown
```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
- [ ] Step 5: Verify output is non-empty and well-formed
- [ ] Step 6: Embed diagram in responseStep 1: Run . Install
if it fails. Then run pre-analysis via the programmatic API:
uv run trailmark analyze --summary {targetDir}python
from trailmark.query.api import QueryEngine
engine = QueryEngine.from_directory("{targetDir}", language="{lang}")
engine.preanalysis()Pre-analysis enriches the graph with blast radius, taint propagation,
and privilege boundary data used by diagrams.
data-flowStep 2: Match the user's request to a using the decision tree
above.
--typeStep 3: For and , identify the focus function.
Default . Use for dependency flows.
call-graphdata-flow--depth 2--direction LRStep 4: Run the script and capture stdout.
Step 5: Check: output starts with or ,
contains at least one node. If empty or malformed, consult
references/mermaid-syntax.md.
flowchartclassDiagramStep 6: Wrap output in code fence.
```mermaid ```Script Reference
uv run {baseDir}/scripts/diagram.py [OPTIONS]| Argument | Short | Default | Description |
|---|---|---|---|
| | required | Directory to analyze |
| | | Source language |
| | required | Diagram type (see above) |
| | none | Center diagram on this node |
| | | BFS traversal depth |
| | Layout: | |
| | Min complexity for |
Examples
bash
# 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_queryCustomization
Direction: Use (default) for hierarchical views, for
left-to-right flows like dependency chains.
TBLRDepth: Increase to see more of the call graph. Decrease to
reduce clutter. The script warns if the diagram exceeds 100 nodes.
--depthFocus: Always use for on non-trivial codebases.
For , omitting focus auto-targets the top 10 complexity hotspots.
--focuscall-graphdata-flowSupporting 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