D2 Diagramのロゴ

D2 Diagram

コミュニティ
diegomarino
d2-diagram

Generate a D2 diagram from a text description

概要

公開者diegomarino
リポジトリclaude-toolshed
スキル名d2-diagram
スター
58
フォーク
5
同梱ファイル
指示のみ
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 指示だけで完結

    モデルに必要なものはすべて指示に含まれているため、別途同期するファイルはありません。

  • オープンソース

    diegomarinoがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキル「D2 Diagram」をTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/diegomarino/claude-toolshed/tree/main/plugins/d2/skills/d2-diagram
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

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
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでD2 Diagramを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあるとすぐに、モデルが自動的にD2 Diagramを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、D2 Diagramは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、スキルを使わない間は指示の読み込みにトークンを消費しません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

/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

よくある質問

AIスキル「D2 Diagram」では何ができますか?

Generate a D2 diagram from a text description

TypingMindでD2 Diagramを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。D2 Diagramはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにD2 Diagramをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/diegomarino/claude-toolshed/tree/main/plugins/d2/skills/d2-diagramを貼り付けてください。TypingMindがSKILL.mdを読み込み、チャットごとに有効にできるスキルとしてインストールします。

D2 Diagramを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストの内容がこのスキルの用途に合ったときに、このスキルを読み込めます。

D2 Diagramで使えるAIモデルの数に制限はありますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもD2 Diagramを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「D2 Diagram」は無料ですか?

diegomarinoがGitHubで公開しています。ライセンス条件はリポジトリでご確認ください。ご利用のAIプロバイダーに支払うのは、使用したトークンの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇