excalidraw-diagram
Generates Excalidraw diagrams for architecture and existing-code flows. Use when the user asks to explain, visualize, or draw a system, request path, runtime interaction, or codebase-backed flow. Explores the codebase when needed, writes a structured diagram spec first, then builds polished .excalidraw output with validation and preview rendering.
git clone https://github.com/shahzadahmadv1/ExcaliClaude
excalidraw-diagram/skill.mdExcalidraw Diagram Generator
Generate Excalidraw diagrams that are readable, code-aware, and visually consistent.
Do not freehand raw Excalidraw JSON unless the builder is unavailable. The default path is:
- discover the real flow
- choose the right diagram level
- write a compact diagram spec
- build the
file with the builder script.excalidraw - validate and preview it
Trigger Logic
Activate when the user asks to create, explain with, visualize, or draw:
- an architecture
- a flow
- a request path
- a runtime interaction
- an existing code path
- a service/system overview
- a multi-view or scenario pack
- a drill-down into a specific service or phase
Examples:
- "Explain the auth flow with a diagram"
- "Draw the payment processing path"
- "Visualize the customer acquisition architecture"
- "Show me how this service talks to Redis and Postgres"
- "Give me an overview and then a detailed flow for the checkout"
- "Draw an architecture overview plus a drill-down of the auth service"
Codebase Discovery
Explore The Codebase When
- the user is asking about an existing system
- the request mentions a repo, solution, project, namespace, service, or feature
- the user wants an explanation of "how it works now"
- the flow likely exists in code but the prompt does not name every component explicitly
Skip Discovery When
- the user is designing something new
- the user explicitly asks for a generic or conceptual template
- the prompt already contains all components and relationships needed for the diagram
Discovery Procedure
- Identify the repo or project path. If none is given, use the current working directory.
- Read
.references/codebase-discovery-prompt.md - Dispatch an Explore agent and ask it to return the structured output from that prompt.
- Use the discovered components and flow sequence as the source of truth.
- If no useful codebase evidence is found, fall back to a conceptual diagram and state that clearly.
View Modes
Choose one of these view modes for each diagram request:
— High-level system map showing all major entities with minimal internal detail. Use for "what exists" questions.overview
— A single runtime or request path through the system. Use for "what happens when" questions.focused-flow
— Detailed view of one service, phase, or subsystem. Use for "how does X work internally" questions.drill-down
— Emits an overview plus one or more focused/drill-down views as separate artifacts. Use for comprehensive documentation or when the user asks for both overview and detail.scenario-pack
Mode Selection Guidance
| User intent | View mode |
|---|---|
| "Show me the whole system" | |
| "What happens when a user logs in?" | |
| "How does the auth service work internally?" | |
| "Document the payment system end to end" | |
| "Give me an overview and detail" | |
If the user does not specify a mode, infer it from context. Default to
focused-flow for flow/path questions and overview for architecture/system questions.
Scope Controls
These controls shape what the diagram includes and how it is presented. Set them in the shared model when building the spec.
| Control | Values | Default | Purpose |
|---|---|---|---|
| , , | | How much metadata to surface (descriptions, technology, evidence) |
| , , | | Influences label verbosity and abstraction level |
| entity ids or group names | all | Limit views to a subset of the model |
| integer | none | Advisory node budget per view; triggers auto-split when exceeded |
Auto-Split Rules
- If a view would exceed
(or ~15 nodes when unset), split into overview + detail artifacts automatically.max_nodes - When auto-splitting, emit an overview first, then one detail artifact per dense group or phase.
- Use a base stem like
so multiple runs on the same day do not overwrite each other.{date}-{topic}-{shortid}
Drill-Down Continuity
- Overview diagrams should use entity ids that detail diagrams can reference.
- When emitting a scenario pack, share the same model across all views so entity names and ids are consistent.
- Report which overview entities have corresponding drill-down views in the final output.
Diagram Selection
Read
references/diagram-quality-bar.md before choosing the diagram kind.
Use a C4-inspired level within each view:
for request paths, runtime flows, and "what happens when" explanationsdynamic
for service/application compositioncontainer
for internals of a specific service/containercomponent
for high-level system boundariescontext
for broad layered overviews that do not fit neatly into one C4 levelarchitecture
for infrastructure and deployment topologydeployment
for data or event movement through the systemdata-flow
for security zones and trust perimeterstrust-boundary
for static service or package dependenciesdependency-map
Architecture Overview Defaults
For
overview views using layout: layers:
- keep owned ingress, processing, and persistence groups as horizontal core rows
- put external systems on the left or right when they are communication partners rather than internal tiers
- put queues, topics, and async backbones on the right by default instead of drawing them as a full-width messaging row
- use
when the diagram mixes internal layers with external systems or messagingoverview_style: core-with-sides - only keep
when the user explicitly wants a stacked tier diagrampure-layers
If the user asks for multiple levels at once, use
scenario-pack mode to generate the higher-level overview first plus detail views.
Required References
Read these before writing the spec:
references/diagram-quality-bar.mdreferences/diagram-spec.mdreferences/color-palette.md
Use these as examples when helpful:
— legacy single-view samplereferences/examples/enhanced-auth-flow.spec.json
— multi-view model samplereferences/examples/multi-view-auth.spec.json
— overview view modereferences/examples/overview-example.spec.json
— focused-flow view modereferences/examples/focused-flow-example.spec.json
— drill-down view modereferences/examples/drill-down-example.spec.json
— scenario-pack with evidence metadatareferences/examples/scenario-pack-example.spec.jsonreferences/examples/simple-flow.excalidrawreferences/examples/architecture.excalidraw
Generation Process
Step 1: Choose View Mode And Scope
Determine the view mode from the user's intent (see View Modes above). Set scope controls:
- Pick
anddetail_level
based on context.audience - Set
if the system is large or the user wants a focused view.max_nodes - Set
if the user names specific services or phases.scope_filter - For
, plan which views to include before writing the spec.scenario-pack
Step 2: Build A Shared Model
Build one semantic model that captures all entities and relationships relevant to the request. This model is the single source of truth — all views derive from it.
The model must include:
— system or project titletitle
— all components with ids, labels, roles, and groupsmodel.entities
— all connections with labels and kindsmodel.relationships- Scope controls:
,detail_level
,audience
,scope_filter
as neededmax_nodes
When discovery was performed, include evidence metadata on entities and relationships:
:evidence_source
,code
, orinferreduser-specified
:confidence
,high
, ormediumlow
,owner
,boundary
when knownruntime
Step 3: Define Views
Add one or more views to the
views array. Each view selects from the shared model.
Each view must include:
— unique identifier for artifact namingview_id
—view_mode
,overview
,focused-flow
, ordrill-downscenario-pack
— the abstraction leveldiagram_kind
andlayout
for flow diagramsdirection
for layered overview/container/context views when side columns help readabilityoverview_style- ordered
groups
— subset of model entities to include (null means all)entity_ids
For single-view requests, you may use the legacy single-view format (flat
nodes/edges without model/views). The builder supports both.
Quality rules:
- Give every important arrow a label.
- Use real class/service/system names when discovery was performed.
- Include
,node_type
, and shorttechnology
fields when they help explain the flow.description - Use
on the main interactions in dynamic diagrams.sequence - Use
only for meaningful branches.shape: "decision"
Step 4: Save The Spec
Create:
mkdir -p docs/diagrams/specs
Save the spec to:
docs/diagrams/specs/<date>-<topic>-<shortid>.diagram.json
Step 5: Build The Excalidraw File
Run:
python <skill-dir>/references/build_excalidraw_diagram.py <spec-file> --output docs/diagrams/<date>-<topic>-<shortid>.excalidraw
The builder handles layout, containers, legends, node sizing, and arrow label placement.
Step 6: Validate Structure
Run:
python <skill-dir>/references/validate_excalidraw.py <diagram-file>
If validation fails, fix the spec first and rebuild. Do not hand-edit raw JSON unless the problem is obviously builder-specific.
Step 7: Render Preview
Run:
python <skill-dir>/references/render_excalidraw.py <diagram-file>
If Playwright or browser rendering is unavailable:
- keep the
file.excalidraw - tell the user preview rendering was skipped
Step 8: Visual Review
Check the preview for:
- crowded lanes or layers
- labels that are too vague
- unlabeled important arrows
- too many boxes for one story
- missing legend or unclear line styles
If the diagram is weak, edit the spec and rebuild. Prefer spec changes over raw JSON tweaks.
Step 9: Done
Report:
- the
path(s) — list all artifacts when multiple views were generated.excalidraw - the spec path
- the preview path if rendering succeeded
- the view mode used
- whether the diagram is codebase-accurate or conceptual
- for multi-view output: which overview entities have drill-down views available
- evidence summary: how many entities are code-derived, inferred, or user-specified
Constraints
Quality Bar
- Every diagram needs a title.
- Important relationships need labels.
- Every node should explain what it is, not just name it.
- Prefer 6-10 primary nodes.
- Split mixed abstraction levels instead of forcing them together.
Complexity Limit
If the discovered flow is too large for one readable diagram:
- Use
mode to emit an overview plus detail views.scenario-pack - Or set
in the model to trigger auto-split.max_nodes - The compiler will split large models into overview + detail artifacts with deterministic naming.
Artifact naming for multi-view output:
for each view{output_stem}-{view_id}.excalidraw- Single-view output uses the
path directly--output - If the requested output path already exists, the builder appends a short unique suffix automatically to avoid overwriting artifacts
Iteration Rule
Iterate on the spec at most 2 times unless the user asks for more refinement.
Fallback
Only generate raw Excalidraw JSON directly if the builder script is broken or unavailable. If that happens, say so.