@diagrammo/dgmo 0.8.2 → 0.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/commands/dgmo-diagram-this.md +60 -0
- package/.claude/commands/dgmo-document-project.md +128 -0
- package/.claude/commands/dgmo.md +185 -50
- package/.cursorrules +32 -37
- package/.github/copilot-instructions.md +35 -44
- package/.windsurfrules +32 -37
- package/README.md +4 -4
- package/dist/cli.cjs +189 -194
- package/dist/editor.cjs +336 -0
- package/dist/editor.cjs.map +1 -0
- package/dist/editor.d.cts +27 -0
- package/dist/editor.d.ts +27 -0
- package/dist/editor.js +305 -0
- package/dist/editor.js.map +1 -0
- package/dist/index.cjs +3699 -1564
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.js +3699 -1564
- package/dist/index.js.map +1 -1
- package/docs/language-reference.md +822 -1060
- package/gallery/fixtures/arc.dgmo +18 -0
- package/gallery/fixtures/area.dgmo +19 -0
- package/gallery/fixtures/bar-stacked.dgmo +10 -0
- package/gallery/fixtures/bar.dgmo +10 -0
- package/gallery/fixtures/c4-full.dgmo +52 -0
- package/gallery/fixtures/c4.dgmo +17 -0
- package/gallery/fixtures/chord.dgmo +12 -0
- package/gallery/fixtures/class-basic.dgmo +14 -0
- package/gallery/fixtures/class-full.dgmo +43 -0
- package/gallery/fixtures/doughnut.dgmo +8 -0
- package/gallery/fixtures/flowchart-basic.dgmo +3 -0
- package/gallery/fixtures/flowchart-colors.dgmo +5 -0
- package/gallery/fixtures/flowchart-complex.dgmo +17 -0
- package/gallery/fixtures/flowchart-decision.dgmo +5 -0
- package/gallery/fixtures/flowchart-full.dgmo +13 -0
- package/gallery/fixtures/flowchart-groups.dgmo +10 -0
- package/gallery/fixtures/flowchart-loop.dgmo +7 -0
- package/gallery/fixtures/flowchart-nested.dgmo +7 -0
- package/gallery/fixtures/flowchart-shapes.dgmo +5 -0
- package/gallery/fixtures/function.dgmo +8 -0
- package/gallery/fixtures/funnel.dgmo +7 -0
- package/gallery/fixtures/gantt-full.dgmo +49 -0
- package/gallery/fixtures/gantt.dgmo +42 -0
- package/gallery/fixtures/heatmap.dgmo +8 -0
- package/gallery/fixtures/infra-full.dgmo +78 -0
- package/gallery/fixtures/infra-overload.dgmo +25 -0
- package/gallery/fixtures/infra.dgmo +47 -0
- package/gallery/fixtures/initiative-status-full.dgmo +46 -0
- package/gallery/fixtures/initiative-status-phases.dgmo +29 -0
- package/gallery/fixtures/initiative-status.dgmo +9 -0
- package/gallery/fixtures/line.dgmo +19 -0
- package/gallery/fixtures/multi-line.dgmo +11 -0
- package/gallery/fixtures/org-basic.dgmo +16 -0
- package/gallery/fixtures/org-full.dgmo +69 -0
- package/gallery/fixtures/org-teams.dgmo +25 -0
- package/gallery/fixtures/pie.dgmo +9 -0
- package/gallery/fixtures/polar-area.dgmo +8 -0
- package/gallery/fixtures/quadrant.dgmo +18 -0
- package/gallery/fixtures/radar.dgmo +8 -0
- package/gallery/fixtures/sankey.dgmo +31 -0
- package/gallery/fixtures/scatter.dgmo +21 -0
- package/gallery/fixtures/sequence-tags-protocols.dgmo +45 -0
- package/gallery/fixtures/sequence-tags.dgmo +41 -0
- package/gallery/fixtures/sequence.dgmo +35 -0
- package/gallery/fixtures/sitemap-basic.dgmo +12 -0
- package/gallery/fixtures/sitemap-full.dgmo +156 -0
- package/gallery/fixtures/slope.dgmo +8 -0
- package/gallery/fixtures/spr-eras.dgmo +62 -0
- package/gallery/fixtures/state.dgmo +30 -0
- package/gallery/fixtures/timeline-intraday.dgmo +14 -0
- package/gallery/fixtures/timeline.dgmo +32 -0
- package/gallery/fixtures/venn.dgmo +10 -0
- package/gallery/fixtures/wordcloud.dgmo +24 -0
- package/package.json +51 -2
- package/src/c4/layout.ts +372 -90
- package/src/c4/parser.ts +113 -62
- package/src/chart.ts +149 -64
- package/src/class/parser.ts +84 -28
- package/src/class/renderer.ts +2 -2
- package/src/cli.ts +179 -77
- package/src/completion.ts +381 -182
- package/src/d3.ts +1026 -428
- package/src/dgmo-mermaid.ts +16 -13
- package/src/dgmo-router.ts +70 -24
- package/src/echarts.ts +682 -169
- package/src/editor/dgmo.grammar +69 -0
- package/src/editor/dgmo.grammar.d.ts +2 -0
- package/src/editor/dgmo.grammar.js +18 -0
- package/src/editor/dgmo.grammar.terms.d.ts +5 -0
- package/src/editor/dgmo.grammar.terms.js +35 -0
- package/src/editor/highlight.ts +36 -0
- package/src/editor/index.ts +28 -0
- package/src/editor/keywords.ts +220 -0
- package/src/editor/tokens.ts +30 -0
- package/src/er/parser.ts +55 -29
- package/src/er/renderer.ts +112 -53
- package/src/gantt/calculator.ts +91 -29
- package/src/gantt/parser.ts +291 -97
- package/src/gantt/renderer.ts +1120 -350
- package/src/graph/flowchart-parser.ts +48 -75
- package/src/graph/state-parser.ts +54 -27
- package/src/infra/parser.ts +161 -177
- package/src/infra/renderer.ts +723 -271
- package/src/infra/types.ts +0 -1
- package/src/initiative-status/parser.ts +144 -56
- package/src/kanban/parser.ts +27 -19
- package/src/org/layout.ts +111 -44
- package/src/org/parser.ts +71 -27
- package/src/org/resolver.ts +3 -3
- package/src/palettes/index.ts +3 -2
- package/src/render.ts +1 -2
- package/src/sequence/parser.ts +209 -100
- package/src/sitemap/parser.ts +73 -44
- package/src/utils/arrows.ts +2 -22
- package/src/utils/duration.ts +39 -21
- package/src/utils/legend-constants.ts +0 -2
- package/src/utils/parsing.ts +82 -72
- package/src/utils/tag-groups.ts +4 -41
- package/src/infra/serialize.ts +0 -67
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# /dgmo-diagram-this — Generate Diagrams from Code
|
|
2
|
+
|
|
3
|
+
You are reading the user's code and generating DGMO diagrams that document what it does. Don't ask what kind of diagram — figure it out from the code.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
Verify DGMO MCP tools are available by calling `mcp__dgmo__list_chart_types`. If not available, tell the user to run `/dgmo` first to set up the MCP server.
|
|
8
|
+
|
|
9
|
+
## Step 1 — Determine Scope
|
|
10
|
+
|
|
11
|
+
The user may provide:
|
|
12
|
+
- **A file path** — diagram that specific file
|
|
13
|
+
- **A function/class name** — diagram that specific piece
|
|
14
|
+
- **A directory** — diagram the module/package
|
|
15
|
+
- **Nothing** — look at the current working directory and diagram the overall project structure
|
|
16
|
+
|
|
17
|
+
If scope is unclear, read the project root (`package.json`, `README.md`, `src/` listing) and pick the most interesting thing to diagram.
|
|
18
|
+
|
|
19
|
+
## Step 2 — Read the Code
|
|
20
|
+
|
|
21
|
+
Read the relevant source files. Look for:
|
|
22
|
+
- Function signatures and call chains
|
|
23
|
+
- API endpoints and request handlers
|
|
24
|
+
- Database models, schemas, ORM entities
|
|
25
|
+
- State machines, status enums, workflow transitions
|
|
26
|
+
- Service-to-service calls, message passing
|
|
27
|
+
- Infrastructure config (Docker, k8s, terraform)
|
|
28
|
+
- Import graphs and module dependencies
|
|
29
|
+
|
|
30
|
+
## Step 3 — Pick the Diagram Type
|
|
31
|
+
|
|
32
|
+
| What you found | Diagram type |
|
|
33
|
+
|---|---|
|
|
34
|
+
| API handler calling other services/DB | `sequence` |
|
|
35
|
+
| Multiple models with relationships | `er` |
|
|
36
|
+
| Service/module dependency graph | `c4` (container level) |
|
|
37
|
+
| State enum, FSM, workflow transitions | `state` |
|
|
38
|
+
| Decision logic, branching control flow | `flowchart` |
|
|
39
|
+
| Docker/k8s/cloud infra config | `infra` |
|
|
40
|
+
| Class hierarchy with methods | `class` |
|
|
41
|
+
| Team/org structure data | `org` |
|
|
42
|
+
|
|
43
|
+
If a single file contains multiple diagrammable things (e.g., models AND an API handler), generate multiple diagrams.
|
|
44
|
+
|
|
45
|
+
## Step 4 — Generate
|
|
46
|
+
|
|
47
|
+
1. Call `mcp__dgmo__get_language_reference("<type>")` for syntax.
|
|
48
|
+
2. Call `mcp__dgmo__get_examples("<type>")` for idiomatic patterns.
|
|
49
|
+
3. Write the DGMO using **real names from the code** — actual function names, model names, service names, field types.
|
|
50
|
+
4. Call `mcp__dgmo__validate_diagram(dgmo)` — fix any errors.
|
|
51
|
+
5. Call `mcp__dgmo__preview_diagram([{dgmo, title}])` to show the result.
|
|
52
|
+
6. Save to `<descriptive-name>.dgmo` in the project.
|
|
53
|
+
|
|
54
|
+
## Rules
|
|
55
|
+
|
|
56
|
+
- **Use real names** — `UserService`, `orders` table, `POST /api/auth/login` — not generic placeholders
|
|
57
|
+
- **Keep it focused** — a sequence diagram with 5-8 messages is better than one with 30. Show the main flow, not every edge case.
|
|
58
|
+
- **Lean on inference** — don't declare `PostgresDB is a database` (the name auto-infers). Only use `is a` when the name doesn't match.
|
|
59
|
+
- **No colons in directives** — `sequence Auth Flow`, not `chart: sequence`
|
|
60
|
+
- **Multiple diagrams are fine** — if the code has both a schema and an API flow, generate both and use `preview_diagram` with multiple entries
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# /dgmo-document-project — Generate Diagrams for a Codebase
|
|
2
|
+
|
|
3
|
+
You are generating a suite of DGMO diagrams that document the user's project. Your goal is to read the codebase, understand its architecture, and produce 3–6 diagrams that capture how the system works.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
Before starting, verify that the DGMO MCP tools are available by calling `mcp__dgmo__list_chart_types`. If the tools are not available, tell the user to run `/dgmo` first to set up the MCP server, then come back to this command.
|
|
8
|
+
|
|
9
|
+
## Step 1 — Understand the Project
|
|
10
|
+
|
|
11
|
+
Read these files (skip any that don't exist):
|
|
12
|
+
|
|
13
|
+
1. **README.md** or **README** — project purpose and overview
|
|
14
|
+
2. **package.json** / **Cargo.toml** / **go.mod** / **pyproject.toml** / **requirements.txt** — tech stack and dependencies
|
|
15
|
+
3. **docker-compose.yml** / **Dockerfile** / **k8s/** / **terraform/** — infrastructure
|
|
16
|
+
4. **src/** or **app/** directory listing — code structure
|
|
17
|
+
5. **.env.example** or config files — external services and integrations
|
|
18
|
+
|
|
19
|
+
From this, determine:
|
|
20
|
+
- What the project does (one sentence)
|
|
21
|
+
- The tech stack (language, framework, database, message broker, etc.)
|
|
22
|
+
- Key modules or services
|
|
23
|
+
- External dependencies and integrations
|
|
24
|
+
- Data models (if database-backed)
|
|
25
|
+
|
|
26
|
+
## Step 2 — Decide Which Diagrams to Generate
|
|
27
|
+
|
|
28
|
+
Pick 3–6 diagrams based on what the project actually has. Don't force a diagram type that doesn't fit. Use this decision matrix:
|
|
29
|
+
|
|
30
|
+
| Signal in codebase | Diagram type | What to show |
|
|
31
|
+
|---|---|---|
|
|
32
|
+
| Multiple services, APIs, or modules | **c4** (context or container) | System components and their relationships |
|
|
33
|
+
| REST/GraphQL endpoints, API handlers | **sequence** | 1–2 key request flows (e.g., auth, main business operation) |
|
|
34
|
+
| Database models, ORM entities, schema files | **er** | Entity relationships and key fields |
|
|
35
|
+
| Docker, k8s, cloud infra, load balancers | **infra** | Traffic flow and infrastructure components |
|
|
36
|
+
| State machines, workflow engines, status fields | **state** | Key state transitions |
|
|
37
|
+
| Multiple packages or layers | **flowchart** | Request lifecycle or data flow |
|
|
38
|
+
| Microservices with message queues | **sequence** | Async event flow between services |
|
|
39
|
+
|
|
40
|
+
**Rules:**
|
|
41
|
+
- Always include a C4 context or container diagram — every project benefits from a high-level view
|
|
42
|
+
- Prefer sequence diagrams for showing **behavior** (how things interact at runtime)
|
|
43
|
+
- Prefer ER diagrams only if there's a real database schema to document
|
|
44
|
+
- Don't generate infra diagrams for projects without infrastructure config
|
|
45
|
+
- Don't generate more than 2 sequence diagrams — pick the most important flows
|
|
46
|
+
|
|
47
|
+
## Step 3 — Get Syntax Help
|
|
48
|
+
|
|
49
|
+
For each diagram type you'll generate, call:
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
mcp__dgmo__get_language_reference("<type>")
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Also call `mcp__dgmo__get_examples("<type>")` to see real examples of that chart type. Use these as patterns — they show idiomatic DGMO style.
|
|
56
|
+
|
|
57
|
+
## Step 4 — Generate the Diagrams
|
|
58
|
+
|
|
59
|
+
Write the DGMO markup for each diagram. Follow these rules:
|
|
60
|
+
|
|
61
|
+
- **Keep diagrams focused** — a C4 diagram with 5–8 components is better than one with 20
|
|
62
|
+
- **Use real names from the codebase** — actual service names, model names, endpoint paths
|
|
63
|
+
- **Lean on inference** — don't declare participant types unless the name doesn't match (e.g., `User` auto-infers as actor, `PostgresDB` as database)
|
|
64
|
+
- **Add tags for color coding** when there are natural groupings (teams, domains, layers)
|
|
65
|
+
- **Title every diagram** — the title goes on the first line after the chart type
|
|
66
|
+
|
|
67
|
+
### Syntax reminders (no colons in directives or data):
|
|
68
|
+
```
|
|
69
|
+
sequence Auth Flow // first line: type + title
|
|
70
|
+
tag Layer alias l // tag declaration (no colon)
|
|
71
|
+
Frontend(blue)
|
|
72
|
+
Backend(green)
|
|
73
|
+
|
|
74
|
+
User -POST /login-> API // sync arrow
|
|
75
|
+
API ~publish~> Queue // async arrow
|
|
76
|
+
note Validates JWT // note (no colon)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Step 5 — Validate Before Rendering
|
|
80
|
+
|
|
81
|
+
For each diagram, call `mcp__dgmo__validate_diagram(dgmo)` to check for errors. Fix any issues before proceeding.
|
|
82
|
+
|
|
83
|
+
## Step 6 — Generate the Report
|
|
84
|
+
|
|
85
|
+
Once all diagrams validate, bundle them into a report:
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
mcp__dgmo__generate_report({
|
|
89
|
+
title: "<Project Name> — Architecture Diagrams",
|
|
90
|
+
subtitle: "Auto-generated from codebase analysis",
|
|
91
|
+
sections: [
|
|
92
|
+
{ title: "System Context (C4)", description: "High-level view of ...", dgmo: "..." },
|
|
93
|
+
{ title: "Auth Flow", description: "How authentication works", dgmo: "..." },
|
|
94
|
+
...
|
|
95
|
+
],
|
|
96
|
+
theme: "dark",
|
|
97
|
+
palette: "nord",
|
|
98
|
+
include_source: true,
|
|
99
|
+
open: true
|
|
100
|
+
})
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Step 7 — Save Source Files
|
|
104
|
+
|
|
105
|
+
Write each diagram to a `diagrams/` directory in the project root:
|
|
106
|
+
|
|
107
|
+
- `diagrams/c4-context.dgmo`
|
|
108
|
+
- `diagrams/sequence-auth.dgmo`
|
|
109
|
+
- `diagrams/er-schema.dgmo`
|
|
110
|
+
- etc.
|
|
111
|
+
|
|
112
|
+
Use descriptive filenames. Create the `diagrams/` directory if it doesn't exist.
|
|
113
|
+
|
|
114
|
+
## Step 8 — Report to the User
|
|
115
|
+
|
|
116
|
+
Summarize what was generated:
|
|
117
|
+
|
|
118
|
+
1. List each diagram with a one-line description
|
|
119
|
+
2. Mention the HTML report was opened in the browser
|
|
120
|
+
3. Note the saved `.dgmo` files in `diagrams/`
|
|
121
|
+
4. Suggest which diagrams might be worth expanding or adding next
|
|
122
|
+
|
|
123
|
+
## Important Notes
|
|
124
|
+
|
|
125
|
+
- This skill works with **any** project — not just TypeScript or JavaScript
|
|
126
|
+
- Don't ask the user what diagrams to generate — make the decision based on what you find in the code. They can request changes after.
|
|
127
|
+
- If the project is very small (single file, script), generate just 1–2 diagrams instead of forcing 6
|
|
128
|
+
- If you can't determine the project structure, ask the user to point you at the main source directory
|
package/.claude/commands/dgmo.md
CHANGED
|
@@ -58,6 +58,18 @@ Then proceed with the user's original request using CLI fallback (see "Other out
|
|
|
58
58
|
|
|
59
59
|
> **Note for future users:** To set up in one step from the terminal before starting a Claude Code session, run `dgmo --install-claude-code-integration`. It handles everything: installs `@diagrammo/dgmo-mcp`, writes the skill, and configures the MCP server.
|
|
60
60
|
|
|
61
|
+
## Project Awareness
|
|
62
|
+
|
|
63
|
+
At the start of a session (or when the user first invokes `/dgmo`), scan for existing `.dgmo` files:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
find . -name '*.dgmo' -not -path '*/node_modules/*' -not -path '*/.git/*' 2>/dev/null | head -20
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
If you find any, mention them briefly: "I see N diagrams in your project (e.g. `diagrams/auth-flow.dgmo`, `diagrams/er-schema.dgmo`). I can edit any of these or create new ones."
|
|
70
|
+
|
|
71
|
+
Don't block on this — if no files found, just proceed.
|
|
72
|
+
|
|
61
73
|
## Getting Syntax Help
|
|
62
74
|
|
|
63
75
|
**Always use the MCP tool first** if it's available in this session:
|
|
@@ -69,19 +81,89 @@ mcp__dgmo__get_language_reference("sequence") // specific chart type
|
|
|
69
81
|
|
|
70
82
|
This is the authoritative, always-up-to-date syntax reference. Use it before guessing syntax.
|
|
71
83
|
|
|
84
|
+
For **examples** of real diagrams, call `mcp__dgmo__get_examples("<type>")` — these are curated gallery fixtures that show idiomatic DGMO patterns. Use them as few-shot references when generating.
|
|
85
|
+
|
|
72
86
|
## Your Workflow
|
|
73
87
|
|
|
74
88
|
**Primary goal: get the user seeing a visualization as fast as possible.**
|
|
75
89
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
1. **
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
90
|
+
### Creating a new diagram
|
|
91
|
+
|
|
92
|
+
1. **Pick the right chart type** — don't ask the user. Use these heuristics:
|
|
93
|
+
- "show our API" / "how does X work" → `sequence`
|
|
94
|
+
- "architecture" / "system overview" → `c4`
|
|
95
|
+
- "database" / "schema" / "models" → `er`
|
|
96
|
+
- "infrastructure" / "deployment" / "traffic" → `infra`
|
|
97
|
+
- "process" / "decision" / "flow" → `flowchart`
|
|
98
|
+
- "states" / "lifecycle" / "transitions" → `state`
|
|
99
|
+
- "org" / "team" / "hierarchy" → `org`
|
|
100
|
+
- "roadmap" / "project status" → `initiative-status` or `gantt`
|
|
101
|
+
- "compare" / "metrics" / "data" → `bar`, `line`, `pie`, etc.
|
|
102
|
+
- If genuinely ambiguous, suggest your best guess with a one-line rationale.
|
|
103
|
+
2. **Get syntax + examples** — call `mcp__dgmo__get_language_reference("<type>")` and `mcp__dgmo__get_examples("<type>")`.
|
|
104
|
+
3. **Write the `.dgmo` content** — compose the markup.
|
|
105
|
+
4. **Validate first** — call `mcp__dgmo__validate_diagram(dgmo)` to catch syntax errors before rendering. If errors come back, fix them and validate again.
|
|
106
|
+
5. **Open in browser** — call `mcp__dgmo__preview_diagram([{dgmo, title}])` without asking. This is always the right default.
|
|
107
|
+
6. **Save the source file** (if working in a project) — write it to `<name>.dgmo` so the user has an editable copy.
|
|
82
108
|
|
|
83
109
|
Do not ask the user how they want to view the diagram. Just open it. They can ask for other formats if they want.
|
|
84
110
|
|
|
111
|
+
### Editing an existing diagram
|
|
112
|
+
|
|
113
|
+
When the user asks to modify a `.dgmo` file or says "update this diagram":
|
|
114
|
+
|
|
115
|
+
1. **Read the file** — use the Read tool to get the current content.
|
|
116
|
+
2. **Understand it** — identify the chart type, key elements, and structure.
|
|
117
|
+
3. **Make the change** — edit the file using the Edit tool. Preserve the user's style and organization.
|
|
118
|
+
4. **Validate** — call `mcp__dgmo__validate_diagram(dgmo)` on the updated content.
|
|
119
|
+
5. **Preview** — call `mcp__dgmo__preview_diagram` so the user sees the result immediately.
|
|
120
|
+
|
|
121
|
+
Keep the diff minimal — don't rewrite the whole file when adding one element.
|
|
122
|
+
|
|
123
|
+
### Diagramming from code
|
|
124
|
+
|
|
125
|
+
When the user says "diagram this", "diagram this file", or "show me how X works":
|
|
126
|
+
|
|
127
|
+
1. **Read the relevant source code** — the file, function, or module they're pointing at.
|
|
128
|
+
2. **Choose the best diagram type** based on what the code does:
|
|
129
|
+
- API handler / controller → `sequence` showing the request flow
|
|
130
|
+
- Database models / ORM entities → `er` showing relationships
|
|
131
|
+
- State machine / status enum → `state` showing transitions
|
|
132
|
+
- Module imports / service dependencies → `c4` or `flowchart`
|
|
133
|
+
- Infrastructure config (Docker, k8s, terraform) → `infra`
|
|
134
|
+
3. **Extract real names** — use actual function names, service names, model names from the code.
|
|
135
|
+
4. **Generate, validate, preview** — same as creating a new diagram.
|
|
136
|
+
|
|
137
|
+
### Error recovery
|
|
138
|
+
|
|
139
|
+
When `validate_diagram` or `render_diagram` returns errors:
|
|
140
|
+
|
|
141
|
+
1. **Read the error messages** — they include line numbers and descriptions.
|
|
142
|
+
2. **Fix the specific issues** — don't regenerate from scratch unless there are many errors.
|
|
143
|
+
3. **Validate again** — loop until clean.
|
|
144
|
+
4. **Then render** — only call `preview_diagram` or `render_diagram` after validation passes.
|
|
145
|
+
|
|
146
|
+
Common fixes:
|
|
147
|
+
- "Unknown directive" → check spelling, remove colons from directives
|
|
148
|
+
- "Expected number" → data rows use spaces not colons: `Label 100` not `Label: 100`
|
|
149
|
+
- Duplicate name → parentheses strip color from display name; `App (TS)` and `App (Rust)` both become `App`
|
|
150
|
+
|
|
151
|
+
### Side-by-side variants
|
|
152
|
+
|
|
153
|
+
When the user asks to compare layouts, themes, or approaches:
|
|
154
|
+
|
|
155
|
+
```
|
|
156
|
+
mcp__dgmo__preview_diagram([
|
|
157
|
+
{ title: "Option A — Detailed", dgmo: "..." },
|
|
158
|
+
{ title: "Option B — Simplified", dgmo: "..." }
|
|
159
|
+
])
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
This opens a single page with both diagrams. Use this for:
|
|
163
|
+
- Light vs dark theme comparisons
|
|
164
|
+
- Different levels of detail
|
|
165
|
+
- Alternative structures for the same data
|
|
166
|
+
|
|
85
167
|
### Other output options (only when explicitly requested)
|
|
86
168
|
|
|
87
169
|
| What the user wants | How to do it |
|
|
@@ -93,6 +175,39 @@ Do not ask the user how they want to view the diagram. Just open it. They can as
|
|
|
93
175
|
| **Shareable URL** | `mcp__dgmo__share_diagram(dgmo)` → returns a URL; immediately run `open <url>` — do NOT just display the URL |
|
|
94
176
|
| **Copy markup to clipboard** | Run `echo '<dgmo markup>' \| pbcopy` |
|
|
95
177
|
|
|
178
|
+
### Embedding diagrams in docs
|
|
179
|
+
|
|
180
|
+
When the user wants a diagram in a README, PR description, or markdown file:
|
|
181
|
+
|
|
182
|
+
1. **Generate a share URL** — `mcp__dgmo__share_diagram(dgmo)` returns a `diagrammo.app` URL.
|
|
183
|
+
2. **Render a PNG** — `mcp__dgmo__render_diagram(dgmo, format:"png", theme:"light", palette:"nord")` returns a temp path.
|
|
184
|
+
3. **Insert into markdown** — either:
|
|
185
|
+
- Copy the PNG to the project (e.g. `docs/images/auth-flow.png`) and reference it: ``
|
|
186
|
+
- Use the share URL directly: ``
|
|
187
|
+
4. **For PRs** — prefer share URLs (no binary file to commit). For README/docs — prefer committed PNGs (they work offline).
|
|
188
|
+
|
|
189
|
+
Always generate both light and dark variants if the doc will be viewed in both modes, or use `theme:"transparent"` for universal backgrounds.
|
|
190
|
+
|
|
191
|
+
### Batch rendering
|
|
192
|
+
|
|
193
|
+
When the user asks to render all diagrams in a directory:
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
for f in diagrams/*.dgmo; do dgmo "$f" -o "${f%.dgmo}.png" --theme dark --palette nord; done
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Or for SVG: replace `.png` with `.svg` in the output.
|
|
200
|
+
|
|
201
|
+
### Share link to clipboard
|
|
202
|
+
|
|
203
|
+
After generating a share link, always copy it to the clipboard automatically:
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
echo '<url>' | pbcopy
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Then tell the user it's been copied.
|
|
210
|
+
|
|
96
211
|
## CLI Reference
|
|
97
212
|
|
|
98
213
|
```
|
|
@@ -141,37 +256,31 @@ Key options:
|
|
|
141
256
|
| `initiative-status` | Project roadmap with dependency tracking |
|
|
142
257
|
| `sitemap` | Website / app navigation structure |
|
|
143
258
|
| `infra` | Infrastructure traffic flow with rps computation |
|
|
259
|
+
| `gantt` | Project scheduling with dependencies |
|
|
144
260
|
|
|
145
261
|
## Key Syntax Patterns
|
|
146
262
|
|
|
147
263
|
### Common to all diagrams
|
|
148
264
|
|
|
149
265
|
```
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
palette: catppuccin // override palette
|
|
266
|
+
sequence Auth Flow // first line: chart type + optional title
|
|
267
|
+
palette catppuccin // directives are space-separated (no colon)
|
|
153
268
|
|
|
154
269
|
// This is a comment (only // syntax — not #)
|
|
155
270
|
```
|
|
156
271
|
|
|
157
|
-
Inline colors on most elements: append `(colorname)` — e.g. `North(red)
|
|
272
|
+
Inline colors on most elements: append `(colorname)` — e.g. `North(red) 850`, `[Process(blue)]`.
|
|
158
273
|
Named colors: `red`, `orange`, `yellow`, `green`, `blue`, `purple`, `teal`, `cyan`, `gray`.
|
|
159
274
|
|
|
160
275
|
### sequence (most commonly used)
|
|
161
276
|
|
|
162
277
|
```
|
|
163
|
-
|
|
164
|
-
title: Auth Flow
|
|
165
|
-
|
|
166
|
-
// Participants auto-inferred, or declare explicitly:
|
|
167
|
-
User is an actor
|
|
168
|
-
API is a service
|
|
169
|
-
DB is a database
|
|
278
|
+
sequence Auth Flow
|
|
170
279
|
|
|
171
280
|
User -Login-> API
|
|
172
281
|
API -Find user-> DB
|
|
173
282
|
DB -user record-> API
|
|
174
|
-
note
|
|
283
|
+
note
|
|
175
284
|
Indexed lookup on email column
|
|
176
285
|
|
|
177
286
|
if credentials valid
|
|
@@ -181,16 +290,17 @@ else
|
|
|
181
290
|
|
|
182
291
|
== Logout ==
|
|
183
292
|
|
|
184
|
-
note
|
|
293
|
+
note session cleanup
|
|
185
294
|
User -Logout-> API
|
|
186
295
|
API -Delete session-> DB
|
|
187
296
|
```
|
|
188
297
|
|
|
189
298
|
- Sync: `A -label-> B` · Async: `A ~label~> B` · Unlabeled: `A -> B`
|
|
190
299
|
- Blocks: `if` / `else`, `loop`, `parallel` — closed by indentation (no `end` keyword)
|
|
191
|
-
- Notes: place `note
|
|
192
|
-
- Single-line: `note
|
|
193
|
-
- Multi-line: `note
|
|
300
|
+
- Notes: place `note text` after a message — it naturally associates with that position.
|
|
301
|
+
- Single-line: `note text`
|
|
302
|
+
- Multi-line: `note` then indent continuation lines beneath it
|
|
303
|
+
- Anchored: `note right of API` then indent continuation lines
|
|
194
304
|
- Sections: `== Title ==`
|
|
195
305
|
- Groups: `[Group Name]` with indented participants
|
|
196
306
|
|
|
@@ -208,34 +318,34 @@ Shapes: `(oval)` `[rect]` `<diamond>` `/parallelogram/` `[[subroutine]]` `[docum
|
|
|
208
318
|
|
|
209
319
|
```
|
|
210
320
|
// bar
|
|
211
|
-
|
|
212
|
-
series
|
|
213
|
-
North
|
|
214
|
-
South
|
|
321
|
+
bar Revenue by Region
|
|
322
|
+
series Revenue
|
|
323
|
+
North 850
|
|
324
|
+
South 620
|
|
215
325
|
|
|
216
326
|
// line (multi-series)
|
|
217
|
-
series
|
|
218
|
-
Q1
|
|
219
|
-
Q2
|
|
327
|
+
series Sales(red), Costs(blue)
|
|
328
|
+
Q1 100, 50
|
|
329
|
+
Q2 120, 55
|
|
220
330
|
|
|
221
331
|
// pie
|
|
222
|
-
|
|
223
|
-
labels
|
|
224
|
-
Company A
|
|
225
|
-
Company B
|
|
332
|
+
pie Market Share
|
|
333
|
+
labels percent
|
|
334
|
+
Company A 40
|
|
335
|
+
Company B 35
|
|
226
336
|
```
|
|
227
337
|
|
|
228
338
|
### er
|
|
229
339
|
|
|
230
340
|
```
|
|
231
341
|
users
|
|
232
|
-
id
|
|
233
|
-
email
|
|
342
|
+
id int [pk]
|
|
343
|
+
email varchar [unique]
|
|
234
344
|
1-writes-* posts
|
|
235
345
|
|
|
236
346
|
posts
|
|
237
|
-
id
|
|
238
|
-
author_id
|
|
347
|
+
id int [pk]
|
|
348
|
+
author_id int [fk]
|
|
239
349
|
```
|
|
240
350
|
|
|
241
351
|
### org
|
|
@@ -253,19 +363,20 @@ CEO
|
|
|
253
363
|
### infra
|
|
254
364
|
|
|
255
365
|
```
|
|
256
|
-
|
|
366
|
+
infra
|
|
367
|
+
|
|
257
368
|
edge
|
|
258
|
-
rps
|
|
369
|
+
rps 10000
|
|
259
370
|
-> CDN
|
|
260
371
|
|
|
261
372
|
CDN
|
|
262
|
-
cache-hit
|
|
373
|
+
cache-hit 80%
|
|
263
374
|
-> API
|
|
264
375
|
|
|
265
376
|
API
|
|
266
|
-
instances
|
|
267
|
-
max-rps
|
|
268
|
-
latency-ms
|
|
377
|
+
instances 3
|
|
378
|
+
max-rps 500
|
|
379
|
+
latency-ms 45
|
|
269
380
|
```
|
|
270
381
|
|
|
271
382
|
## Anti-Patterns
|
|
@@ -278,17 +389,41 @@ parallel else ❌ not supported — use separate parallel blocks
|
|
|
278
389
|
== Foo(#ff0000) == ❌ hex colors not supported — use named colors: == Foo(red) ==
|
|
279
390
|
A -routes to /api-> B ❌ -> inside a label is ambiguous — rephrase the label
|
|
280
391
|
end ❌ not needed — indentation closes blocks in sequence diagrams
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
392
|
+
chart: sequence ❌ use `sequence Title` as the first line (no colon)
|
|
393
|
+
title: My Diagram ❌ title goes on the first line after chart type
|
|
394
|
+
series: A, B ❌ use `series A, B` (no colon)
|
|
395
|
+
Label: 100 ❌ use `Label 100` (no colon in data rows)
|
|
396
|
+
tag: Group ❌ use `tag Group` (no colon)
|
|
397
|
+
note: text ❌ use `note text` (no colon)
|
|
286
398
|
```
|
|
287
399
|
|
|
288
400
|
## Tips
|
|
289
401
|
|
|
290
|
-
- Default theme: `dark`, default palette: `nord`
|
|
402
|
+
- Default theme: `dark`, default palette: `nord` — use these unless the user requests otherwise.
|
|
403
|
+
- Always validate before rendering — `validate_diagram` is much faster than a failed render.
|
|
404
|
+
- Always call `get_examples` before generating an unfamiliar chart type — real examples beat guessing.
|
|
291
405
|
- Stdin mode for quick renders: `echo "..." | dgmo -o out.png`
|
|
292
406
|
- For C4, `--c4-level` drills from context → containers → components → deployment.
|
|
293
|
-
- When auto-detection picks the wrong chart type, add an explicit
|
|
407
|
+
- When auto-detection picks the wrong chart type, add an explicit type as the first word on the first line.
|
|
294
408
|
- `mcp__dgmo__preview_diagram` accepts multiple diagrams at once — useful for showing variants side by side.
|
|
409
|
+
- When the user says "diagram this" while looking at code, read the code first and pick the chart type yourself — don't ask.
|
|
410
|
+
|
|
411
|
+
## Related Commands
|
|
412
|
+
|
|
413
|
+
Tell the user about these when relevant:
|
|
414
|
+
|
|
415
|
+
- **`/dgmo-diagram-this`** — Point it at a file, function, or module and it generates the right diagram from the code. Use when the user says "diagram this" or "how does this work?"
|
|
416
|
+
- **`/dgmo-document-project`** — Scans the entire codebase and generates a suite of 3–6 architecture diagrams (C4, sequence, ER, infra) as an HTML report. Use when the user wants project documentation.
|
|
417
|
+
|
|
418
|
+
## AI Integrations Beyond Claude Code
|
|
419
|
+
|
|
420
|
+
DGMO works with other AI tools too. If the user asks about using Diagrammo with other editors or AI assistants, point them to **https://diagrammo.app/ai** which covers:
|
|
421
|
+
|
|
422
|
+
- **Cursor** — `.cursorrules` file provides DGMO syntax context to the AI
|
|
423
|
+
- **Windsurf** — `.windsurfrules` file works the same way with Cascade
|
|
424
|
+
- **GitHub Copilot** — `.github/copilot-instructions.md` teaches Copilot the syntax
|
|
425
|
+
- **OpenAI Codex CLI** — `AGENTS.md` + `.codex/config.toml` configuration
|
|
426
|
+
|
|
427
|
+
These context files are already included in the `@diagrammo/dgmo` npm package. For any project using dgmo as a dependency, the AI tool picks them up automatically.
|
|
428
|
+
|
|
429
|
+
The MCP server (`@diagrammo/dgmo-mcp`) also works with **Claude Desktop** and any MCP-compatible client — not just Claude Code.
|
package/.cursorrules
CHANGED
|
@@ -13,8 +13,7 @@ When the user asks for a diagram, visualization, or chart, generate a `.dgmo` fi
|
|
|
13
13
|
|
|
14
14
|
### Sequence diagram
|
|
15
15
|
```
|
|
16
|
-
|
|
17
|
-
title: Auth Flow
|
|
16
|
+
sequence Auth Flow
|
|
18
17
|
|
|
19
18
|
User -Login-> API
|
|
20
19
|
API -Find user-> DB
|
|
@@ -27,8 +26,7 @@ DB -user-> API
|
|
|
27
26
|
|
|
28
27
|
### Flowchart
|
|
29
28
|
```
|
|
30
|
-
|
|
31
|
-
title: Process
|
|
29
|
+
flowchart Process
|
|
32
30
|
|
|
33
31
|
(Start) -> <Valid?>
|
|
34
32
|
-yes-> [Process] -> (Done)
|
|
@@ -37,34 +35,32 @@ title: Process
|
|
|
37
35
|
|
|
38
36
|
### Bar chart
|
|
39
37
|
```
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
series: USD
|
|
38
|
+
bar Revenue
|
|
39
|
+
series USD
|
|
43
40
|
|
|
44
|
-
North
|
|
45
|
-
South
|
|
46
|
-
East
|
|
41
|
+
North 850
|
|
42
|
+
South 620
|
|
43
|
+
East 1100
|
|
47
44
|
```
|
|
48
45
|
|
|
49
46
|
### ER diagram
|
|
50
47
|
```
|
|
51
|
-
|
|
52
|
-
title: Schema
|
|
48
|
+
er Schema
|
|
53
49
|
|
|
54
50
|
users
|
|
55
|
-
id
|
|
56
|
-
email
|
|
51
|
+
id int [pk]
|
|
52
|
+
email varchar [unique]
|
|
57
53
|
|
|
58
54
|
posts
|
|
59
|
-
id
|
|
60
|
-
user_id
|
|
55
|
+
id int [pk]
|
|
56
|
+
user_id int [fk]
|
|
61
57
|
|
|
62
58
|
users 1--* posts : writes
|
|
63
59
|
```
|
|
64
60
|
|
|
65
61
|
### Org chart
|
|
66
62
|
```
|
|
67
|
-
|
|
63
|
+
org
|
|
68
64
|
|
|
69
65
|
CEO
|
|
70
66
|
VP Engineering
|
|
@@ -75,25 +71,24 @@ CEO
|
|
|
75
71
|
|
|
76
72
|
### C4 architecture
|
|
77
73
|
```
|
|
78
|
-
|
|
79
|
-
title: System
|
|
74
|
+
c4 System
|
|
80
75
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
76
|
+
Web App is a container | description: SPA, tech: React
|
|
77
|
+
-Uses-> API
|
|
78
|
+
User is a person
|
|
79
|
+
-Browses-> Web App
|
|
84
80
|
```
|
|
85
81
|
|
|
86
82
|
### Infra chart
|
|
87
83
|
```
|
|
88
|
-
|
|
89
|
-
direction: LR
|
|
84
|
+
infra
|
|
90
85
|
|
|
91
86
|
edge
|
|
92
|
-
rps
|
|
87
|
+
rps 10000
|
|
93
88
|
-> CDN
|
|
94
89
|
|
|
95
90
|
CDN
|
|
96
|
-
cache-hit
|
|
91
|
+
cache-hit 80%
|
|
97
92
|
-> LB
|
|
98
93
|
|
|
99
94
|
LB
|
|
@@ -101,25 +96,25 @@ LB
|
|
|
101
96
|
-/web-> Web | split: 30%
|
|
102
97
|
|
|
103
98
|
API
|
|
104
|
-
instances
|
|
105
|
-
max-rps
|
|
106
|
-
latency-ms
|
|
99
|
+
instances 3
|
|
100
|
+
max-rps 500
|
|
101
|
+
latency-ms 45
|
|
107
102
|
```
|
|
108
103
|
|
|
109
|
-
Properties: `cache-hit`, `firewall-block`, `ratelimit-rps`, `
|
|
104
|
+
Properties: `cache-hit`, `firewall-block`, `ratelimit-rps`, `max-rps`, `instances` (N or N-M), `latency-ms`, `cb-error-threshold`. Groups: `[Name]` with children. Roles are inferred from behavior.
|
|
110
105
|
|
|
111
106
|
## All 32 chart types
|
|
112
107
|
|
|
113
|
-
bar, line, multi-line, area, pie, doughnut, radar, polar-area, bar-stacked, scatter, sankey, chord, function, heatmap, funnel, slope, wordcloud, arc, timeline, venn, quadrant, sequence, flowchart, state, class, er, org, kanban, c4, initiative-status, sitemap, infra
|
|
108
|
+
bar, line, multi-line, area, pie, doughnut, radar, polar-area, bar-stacked, scatter, sankey, chord, function, heatmap, funnel, slope, wordcloud, arc, timeline, venn, quadrant, sequence, flowchart, state, class, er, org, kanban, c4, initiative-status, sitemap, infra, gantt
|
|
114
109
|
|
|
115
110
|
## Common patterns
|
|
116
111
|
|
|
117
|
-
- `
|
|
118
|
-
- `
|
|
112
|
+
- `TYPE Title` — first line declares chart type and optional title (no colon)
|
|
113
|
+
- `directive value` — directives are space-separated (no colon)
|
|
119
114
|
- `// comment` — only `//` comments (not `#`)
|
|
120
|
-
- `(colorname)` — inline colors: `Label(red)
|
|
121
|
-
- `series
|
|
122
|
-
- `tag
|
|
115
|
+
- `(colorname)` — inline colors: `Label(red) 100`
|
|
116
|
+
- `series A(red), B(blue)` — multi-series with colors
|
|
117
|
+
- `tag Group alias g` — tag groups for metadata
|
|
123
118
|
|
|
124
119
|
## Rendering
|
|
125
120
|
|
|
@@ -136,7 +131,7 @@ Install: `brew install diagrammo/dgmo/dgmo` or `npm install -g @diagrammo/dgmo`
|
|
|
136
131
|
- Don't use `#` for comments — use `//`
|
|
137
132
|
- Don't use `end` to close sequence blocks — indentation closes them
|
|
138
133
|
- Don't use hex colors in section headers — use named colors
|
|
139
|
-
- Don't
|
|
134
|
+
- Don't use colons in chart type, title, directives, or data rows — use spaces
|
|
140
135
|
- Sequence arrows: `->` (sync), `~>` (async) — always left-to-right
|
|
141
136
|
|
|
142
137
|
Full reference: `docs/language-reference.md`
|