D2 Diagram logo

D2 Diagram

Community
diegomarino
d2-diagram

Generate a D2 diagram from a text description

Overview

Publisherdiegomarino
Repositoryclaude-toolshed
Skill named2-diagram
Stars
58
Forks
5
Bundled files
Instructions only
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by diegomarino on GitHub. Read the source before you install it.

Installation

Install the D2 Diagram AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/diegomarino/claude-toolshed/tree/main/plugins/d2/skills/d2-diagram
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/diegomarino/claude-toolshed.git /tmp/claude-toolshed
mkdir -p .claude/skills
cp -r /tmp/claude-toolshed/plugins/d2/skills/d2-diagram .claude/skills/d2-diagram
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable D2 Diagram in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads D2 Diagram on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so D2 Diagram is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

/d2-diagram

User request: "$ARGUMENTS"

Task

Generate a well-composed D2 diagram from the user's description.

Step 1: Setup

Resolve plugin path and read config:

bash
PLUGIN_DIR=$(find "$HOME/.claude/plugins/cache" -type d -name "d2" -path "*/skills/d2" 2>/dev/null | head -1)
[ -z "$PLUGIN_DIR" ] && PLUGIN_DIR=$(find "$HOME" -maxdepth 8 -type d -name "d2" -path "*/skills/d2" 2>/dev/null | head -1)
bash "$PLUGIN_DIR/scripts/ensure-deps.sh"

Read .claude/d2.json if it exists (theme_id, layout, sketch, output_directory, auto_validate, auto_render). If it does not exist, display a one-time nudge:

First time using the d2 plugin? Run /d2-config to pick a theme. Using defaults for now.

Step 2: Classify

Determine diagram type from the description:

IntentType
API calls, request/response, message passingSequence
System components, microservices, infrastructure, pipelines, workflowsArchitecture
Database tables, schema, foreign keys, entitiesER
Class hierarchy, OOP, interfaces, data modelsClass

If ambiguous between 2 types, ask one clarifying question. If clear, proceed.

Step 3: Structural Plan

Before writing any D2, build this plan internally. Apply the policies from $PLUGIN_DIR/SKILL.md.

Determine:

  • diagram_type — from Step 2
  • abstraction_level — infer from prompt: context, container, component, or deployment
  • grouping_criterion — infer or default: layer, domain, ownership, or environment
  • direction — from orientation heuristics (right for flows, down for hierarchies)
  • layout_engine — from engine selection table (<8 nodes: dagre, >=8: elk)
  • nodes — inventory with id (snake_case), label, kind (actor/service/database/queue/cache/gateway/external)
  • groups — with label and children node IDs
  • edges — with from, to, and optional label
  • budget_check — count total nodes, max group size, nesting depth, max fanout against visual budget limits
  • split_decision — pass or split_required

Visibility rule: If the budget check passes and there is no ambiguity in level or grouping, proceed directly to Step 4. If split is required OR the abstraction level or grouping is ambiguous, present a summary to the user:

text
I'm planning to generate:
- Type: {type} at {abstraction_level} level
- Grouping: by {criterion}
- Direction: {direction}
- {N} nodes in {M} groups
- Split: {overview + N detail diagrams | single diagram}

Proceed, or want to adjust?

Step 4: Load Specialist

Read the specialist for the classified type:

  • Sequence: $PLUGIN_DIR/specialists/d2-sequence.md
  • Architecture: $PLUGIN_DIR/specialists/d2-architecture.md
  • ER: $PLUGIN_DIR/specialists/d2-er.md
  • Class: $PLUGIN_DIR/specialists/d2-class.md

Use the specialist's compositional patterns and D2 syntax conventions. The structural plan from Step 3 governs the structure — the specialist provides type-specific syntax.

Step 5: Generate D2

Write the diagram following:

  1. Structural plan — governs structure (what nodes, what groups, what edges)
  2. Specialist patterns — governs D2 syntax (shapes, conventions, type-specific features)
  3. Global policies — governs conventions (IDs, labels, direction, engine)

Order in the .d2 file:

  1. vars block (theme, engine, sketch from config)
  2. direction declaration
  3. classes block (if >4 nodes of same type)
  4. Node and group declarations
  5. Connections

Non-negotiable conventions:

  • IDs: snake_case, no emojis, no spaces — api_gw, user_svc, orders_db
  • Labels: api_gw: "API Gateway" — emojis allowed in labels only
  • Direction: MUST appear right after vars block — direction: right for flows, direction: down for hierarchies. If unsure, use direction: right. Never omit.
  • Quote labels containing spaces or special characters.

Step 6: Repair Pass

Before delivering, run the 10-point repair checklist from $PLUGIN_DIR/SKILL.md:

  1. No level mixing
  2. Consistent grouping criterion
  3. Budget compliance (12 top-level, 7 per group, 3 nesting, 4 fanout)
  4. Labels <= 24 chars
  5. No orphan nodes
  6. No single-child groups
  7. No excessive fanout (>4 edges out)
  8. Self-loops converted to notes (sequences)
  9. Direction explicitly set
  10. Layout engine appropriate for complexity

Fix any violations silently. Do not ask the user — just fix them.

Step 7: Validate Syntax

bash
d2 validate {output_file}

Fix syntax errors using $PLUGIN_DIR/references/guides/troubleshooting.md.

Step 8: Save and Deliver

bash
mkdir -p {output_directory}

Filename: {type}-{short-description}-{YYYYMMDD}.d2

Render if auto_render=true or user asks:

bash
d2 {output_file} {output_directory}/{basename}.svg

Output:

text
{d2 code block}

**What this shows:** {1-2 sentences describing the diagram}
**Saved to:** {filename}
**Elements:** {N} nodes, {M} connections
**Layout:** {engine}, direction {direction}

Want to adjust? I can change the detail level, scope, grouping, or type.

If split was required, list all generated files.

Code/Script Flow Requests

If the user asks to "diagram the flow" of a file or script:

  1. Read the file and derive the flow from actual control paths
  2. Build the structural plan from the code structure
  3. Execute as the appropriate specialist

Frequently asked questions

What does the D2 Diagram AI skill do?

Generate a D2 diagram from a text description

Why use D2 Diagram on TypingMind?

Because you install it once and use it with any model. D2 Diagram is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install D2 Diagram in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/diegomarino/claude-toolshed/tree/main/plugins/d2/skills/d2-diagram. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use D2 Diagram?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with D2 Diagram?

As many as you like. As long as a model supports skills, you can use D2 Diagram with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the D2 Diagram AI skill free?

It is published on GitHub by diegomarino. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇