@senad-d/drawme 0.2.0 → 0.4.0

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/CHANGELOG.md CHANGED
@@ -4,12 +4,27 @@ All notable changes to this project are documented here. The format is based on
4
4
  [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to
5
5
  [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
- ## [Unreleased]
7
+ ## [0.4.0] - 2026-12-06
8
+
9
+ ### Added
10
+
11
+ - `drawio_guide` returns the packaged authoring guides to agents that start without `/drawme`.
12
+
13
+ ### Changed
14
+
15
+ - `/drawme` guides Pi to read relevant implementation sources before drawing and check the result against them. The bundled purpose guide helps choose and review a composition for an architecture overview, request flow, data model, deployment, or user flow. The reply identifies key sources and any gaps instead of filling them with guesses.
8
16
 
9
17
  ### Fixed
10
18
 
19
+ - The Linux desktop opener invokes `/usr/bin/xdg-open` directly instead of resolving the launcher on `PATH`.
11
20
  - Explicit raster sizes are now subject to the 6,000,000-pixel budget, including the border. `drawio_export` exposes `width` only; `height` is internal. See the [export reference](docs/reference.md#drawio_export) for format-specific sizing.
12
21
 
22
+ ## [0.3.0] - 2026-12-02
23
+
24
+ - The README now illustrates how a prompt becomes an editable diagram and shareable exports, with the image and source included in the package.
25
+ - The package now includes a testing guide listing repository checks, their commands, and what they verify.
26
+ - DrawMe grounds code diagrams in relevant source and offers layouts tailored to five diagram purposes.
27
+
13
28
  ## [0.2.0] - 2026-12-01
14
29
 
15
30
  - Linux rendering requires an unprivileged user, explicit page selection requires draw.io 32.4.1 or later, and nondefault animation outputs use page-specific storyboard names.
package/README.md CHANGED
@@ -19,7 +19,7 @@
19
19
 
20
20
  DrawMe is a native Pi **extension** for diagram authoring. Describe a diagram and Pi plans it, writes editable `.drawio` XML (or Mermaid when the CLI supports conversion), lints every source revision, critiques the rendered preview when the active model can view images, and exports the final deliverable — fully autonomously, with no human intervention once started.
21
21
 
22
- > **Privacy:** DrawMe renders diagrams locally. Your request and any attached preview or storyboard images enter Pi's model context and may be sent to your configured hosted model provider. A text-only model, or one whose image support is unknown, gets no image attachment.
22
+ > **Privacy:** DrawMe renders diagrams locally. Your request, project source that Pi reads during authoring, and any attached preview or storyboard images may enter Pi's model context and be sent to your configured hosted model provider. A text-only model, or one whose image support is unknown, gets no image attachment.
23
23
 
24
24
  <table align="center">
25
25
  <tr>
@@ -51,6 +51,7 @@ DrawMe is a native Pi **extension** for diagram authoring. Describe a diagram an
51
51
 
52
52
  - [Implementation Status](#implementation-status)
53
53
  - [Extension Reference](#extension-reference)
54
+ - [Diagram views](#diagram-views)
54
55
  - [Quick Start](#quick-start)
55
56
  - [Installation](#installation)
56
57
  - [Commands](#commands)
@@ -71,7 +72,7 @@ DrawMe is a native Pi **extension** for diagram authoring. Describe a diagram an
71
72
 
72
73
  This checkout implements the DrawMe core loop as a Pi extension:
73
74
 
74
- - Ten model-callable tools (`drawio_check`, `drawio_export`, `drawio_animate`, `drawio_validate`, `drawio_fit_canvas`, `drawio_shapesearch`, `drawio_from_mermaid`, `drawio_layout`, `drawio_explain`, `drawio_open`) and three commands (`/drawme`, `/drawme-check`, `/drawme-export`).
75
+ - Eleven model-callable tools (`drawio_check`, `drawio_export`, `drawio_animate`, `drawio_validate`, `drawio_fit_canvas`, `drawio_shapesearch`, `drawio_from_mermaid`, `drawio_layout`, `drawio_explain`, `drawio_open`, `drawio_guide`) and three commands (`/drawme`, `/drawme-check`, `/drawme-export`).
75
76
  - A guided `/drawme` workflow that steers authoring, validation after every edit, a gated multi-pass visual review, and autonomous final multi-format export.
76
77
  - Pure-TypeScript structural linting, `-e` PNG IEND repair, shape search over a bundled index, and diagram-to-Markdown description — no Python runtime required.
77
78
  - Native draw.io binary resolution across macOS/Linux/Windows/WSL, headless-Linux `xvfb-run` handling, and version-gated Mermaid conversion and ELK auto-layout.
@@ -81,6 +82,14 @@ This checkout implements the DrawMe core loop as a Pi extension:
81
82
 
82
83
  [`docs/reference.md`](docs/reference.md) catalogs the extension's public surface — every command, tool option, default, output behavior, and functional limitation — for other projects and integrations that use DrawMe. It is documentation, not runtime input: the `/drawme` workflow and the registered tool descriptions carry the complete operational instructions themselves.
83
84
 
85
+ ## Diagram views
86
+
87
+ - **Architecture overview** — what each part does and how the parts interact.
88
+ - **Request/sequence flow** — what happens during one request, in order.
89
+ - **Data model** — which records exist and how they relate.
90
+ - **Deployment** — where the running parts live and how they connect.
91
+ - **User flow** — what a person can do and what they see next.
92
+
84
93
  ## Quick Start
85
94
 
86
95
  ### 1) Install the draw.io desktop CLI
@@ -162,16 +171,13 @@ Registered for the model to call directly.
162
171
  | `drawio_layout` | Re-place nodes / route edges with an ELK preset (`verticalFlow`, `horizontalFlow`, `verticalTree`, `horizontalTree`, `radialTree`, `organic`) for large graphs. Requires draw.io **30.2.4 or newer**. |
163
172
  | `drawio_explain` | Describe an existing `.drawio` as structured Markdown (components by container, relations) — for READMEs/PR summaries or model read-back. |
164
173
  | `drawio_open` | Open a `.drawio`/export in the OS default app (draw.io desktop) for fine-tuning. |
174
+ | `drawio_guide` | Return the packaged authoring guides `/drawme` pre-loads (diagram types, XML authoring, style presets, Mermaid authoring, troubleshooting), for agents that author without the command. |
165
175
 
166
176
  ## Architecture
167
177
 
168
- ```text
169
- Natural-language request
170
- └── Pi agent
171
- └── DrawMe extension (check · validate · export · shape search · Mermaid · layout · explain · open)
172
- └── draw.io desktop CLI (renders and exports, local process)
173
- └── Deliverables: .drawio source + PNG / SVG (static or animated) / PDF / JPG
174
- ```
178
+ ![DrawMe architecture: Pi turns a plain-language prompt into editable .drawio source. The DrawMe extension validates the diagram and uses draw.io Desktop to render shareable files locally.](docs/diagrams/drawme-architecture-overview.png)
179
+
180
+ [Editable draw.io source](docs/diagrams/drawme-architecture-overview.drawio)
175
181
 
176
182
  The extension factory in `src/index.ts` registers the tools and commands. Rendering, conversion, and layout launch the draw.io CLI on demand with an argument list rather than a shell; validation, shape search, and explanation run directly in the extension.
177
183
 
@@ -179,19 +185,19 @@ The extension factory in `src/index.ts` registers the tools and commands. Render
179
185
 
180
186
  `/drawme` injects a guided nine-step workflow that the model follows using the tools above:
181
187
 
182
- 1. **Check** — the command itself resolves the CLI and embeds the result plus the authoring references into the workflow message, including whether conversion and layout are supported, so the run starts with everything in context — no upfront tool calls or file reads.
183
- 2. **Plan** — pick the diagram type, relationships, finite canvas, and layout direction; motion requests plan an animated SVG plus a static fallback.
184
- 3. **Author** — write editable uncompressed XML (or Mermaid when supported), using exact searched shapes and optional ELK layout. Fit the finite canvas after authoring, conversion, or layout. Animation may use stored DrawMe motion, persistent connector flow, or portable native page sequences.
188
+ 1. **Check** — the command resolves the CLI and sends one follow-up with the result, including conversion and layout support, and the packaged authoring references. Pi need not reread references already in the message; they do not contain project source.
189
+ 2. **Plan** — honor the requested view or choose one using the [reader's question](assets/references/diagram-types.md#choose-a-view). For an existing implementation, read the relevant source before drawing and record the source location for each claim. Plan only a meaningful supported subset, note omissions, and explain what is missing instead of drawing if no useful subset is supported. For a conceptual diagram, work from the description without unrelated file reads. Motion requests plan an animated SVG plus a static fallback.
190
+ 3. **Author** — write editable uncompressed XML, or use supported Mermaid conversion or ELK layout when it preserves the chosen composition. Fit the finite canvas after authoring, conversion, or layout. Animation may use stored DrawMe motion, persistent connector flow, or portable native page sequences.
185
191
  4. **Validate after every edit** — fix all errors; fix each warning or record why it is reviewed and acceptable. An incomplete report is not clean. Malformed animation, dangling targets, invalid timing, and standalone-SVG-incompatible effects are diagnosed before export.
186
- 5. **Visual review in gated passes** — with the preview image attached (one preview per page for multi-page files), the model runs three focused passes, each answering explicit questions on its own preview: **fit and sizing** (does the diagram fit its page; does the canvas or an element need resizing), **element placement** (is every element positioned correctly; is there a visibly better arrangement), and **connections** (is every connection correct, cleanly routed, symmetric where the layout is symmetric, and anchored to the middle of the facing element side where possible). A fourth **holistic pass** reads every label word for word, checks contrast, semantics, and the diagram type's own review checklist, and re-checks the earlier passes for regressions. Concrete defects to hunt (overlapping or clipped text, labels struck through by lines, floating endpoints, edges through unrelated shapes, …) are spelled out per pass, and each finding lands in a numbered ledger naming the affected cells and planned fix. Without the image, the model reviews structurally with validation and explanation instead of describing renders.
187
- 6. **Fix and verify before the next pass** — a pass's findings become targeted edits, validation, and a replacement preview; compare only when the tool reports a comparable prior attachment for that page is still in model context. Otherwise inspect the new image against the written findings. Every addressed finding gets an explicit verdict (fixed / not fixed / regressed) — a fix counts only when the new render shows the defect gone, and the next pass starts only when the current pass's findings are fixed or explicitly accepted (except at the correction limit).
188
- 7. **Bound corrections** — pass inspection previews do not count as retries; permit at most eight targeted edit → validation → replacement-preview correction retries total. If a finding is still open at the limit, the run keeps the best validated state, finishes the remaining passes as inspection-only, continues to final export, and names the unresolved finding, its pass, and its last verdict in the report; `drawio_open` is offered afterwards for manual fine-tuning.
192
+ 5. **Visual review in gated passes** — with the preview image attached (one preview per page for multi-page files), the model runs three focused passes, each answering explicit questions on its own preview: **fit and sizing** (does the diagram fit its page; does the canvas or an element need resizing), **element placement** (is every element positioned correctly; is there a visibly better arrangement), and **connections** (is every connection correct, cleanly routed, symmetric where the layout is symmetric, and anchored to the middle of the facing element side where possible). A fourth **holistic pass** reads every label word for word, checks contrast, semantics, and the diagram type's own review checklist, and re-checks the earlier passes for regressions. Concrete defects to hunt (overlapping or clipped text, labels struck through by lines, floating endpoints, edges through unrelated shapes, …) are spelled out per pass, and each finding lands in a numbered ledger naming the affected cells and planned fix. Without an image, use validation and `drawio_explain`, then inspect the editable XML for relevant facts the explanation omits; report anything the file cannot establish without claiming visual review. On either path, compare implementation claims with the source before final export. Correct or remove unsupported claims and re-check affected claims after edits; if no validated version passes this check, report the limitation without delivering an implementation diagram, even at the correction limit.
193
+ 6. **Fix and verify before the next pass** — make a targeted edit and validate it. For visual findings, inspect a replacement preview; compare it with a prior image only when the tool reports a comparable attachment for that page. Without an image, repeat the structural checks instead. Record each verdict (fixed / not fixed / regressed). Start the next pass only when the current findings are fixed or explicitly accepted, except at the correction limit.
194
+ 7. **Bound corrections** — inspection previews do not count as retries. Allow at most eight edit → validation → verification cycles across the review. At the limit, stop editing, finish the remaining passes as inspection-only, and report each unresolved finding, its pass, and its last verdict.
189
195
  8. **No human gate** — the run never pauses for approval or feedback; if the user interrupts with feedback, it is handled as new critique findings and the run continues.
190
- 9. **Final export** — immediately after the holistic confirmation, export the requested formats (each page of a multi-page file separately). Use `drawio_animate` for DrawMe motion or `animated:true` for native motion, and normally include a static PNG fallback. Final export reports deliverables, animation verification, unresolved findings, and preview cleanup warnings.
196
+ 9. **Final export** — after review, export the requested formats when supported (each page of a multi-page file separately). Without a renderer, deliver validated editable XML and report that no preview or final export was produced. Use `drawio_animate` for DrawMe motion or `animated:true` for native motion, and normally include a static PNG fallback. The final reply reports deliverables, animation verification, unresolved findings, and preview cleanup warnings. For an implementation view, it also names key source locations and relevant gaps.
191
197
 
192
198
  Review each page, but don't count on keeping a file per page: a successful preview or final export may retire tracked previews for the same source, including other pages. DrawMe does not reconstruct preview tracking after restart. Transcript attachments are separate from files; see [preview behavior](docs/reference.md#preview-attachments-and-cleanup).
193
199
 
194
- Deterministic checks cover XML contracts, IDs/references, finite page and container bounds, outer margins, overlaps, explicit waypoint routes, edge-label placement, conservative font/wrapping cases, and pinned anchors that face away from their adjacent waypoint or auto-routed peer. Auto-routed edges remain renderer-dependent: validation warns that their route is unchecked and adds a focused observation when the direct connection line pierces a shape, but the preview remains the final arbiter. Rendered clipping and wrapping, contrast, typography at full-diagram scale, visual balance, semantics, and draw.io's automatic connector routes need rendered inspection, so the model critiques them only if a preview image is attached and reports them as unverified otherwise. Vision's job in the loop is to narrow every rendered defect down to specific cells (the authoring reference maps each defect to a source fix) and then to confirm from the replacement image that the defect is actually gone. A 2000px preview that makes labels unreadable requires a tighter/simpler layout, page splitting, or a focused re-export — it must never be accepted as-is.
200
+ Deterministic checks cover XML contracts, IDs/references, finite page and container bounds, outer margins, overlaps, explicit waypoint routes, edge-label placement, conservative font/wrapping cases, and pinned anchors that face away from their adjacent waypoint or auto-routed peer. Auto-routed edges remain renderer-dependent: validation warns that their route is unchecked and adds a focused observation when the direct connection line pierces a shape, but the preview remains the final arbiter. Rendered clipping and wrapping, contrast, typography at full-diagram scale, visual balance, and draw.io's automatic connector routes need rendered inspection, so the model critiques them only if a preview image is attached and reports them as unverified otherwise. Vision's job in the loop is to narrow every rendered defect down to specific cells (the authoring reference maps each defect to a source fix) and then to confirm from the replacement image that the defect is actually gone. A 2000px preview that makes labels unreadable requires a tighter/simpler layout, page splitting, or a focused re-export — it must never be accepted as-is.
195
201
 
196
202
  ## Bundled References and Assets
197
203
 
@@ -199,7 +205,7 @@ These stay plain Markdown files for easy editing. `/drawme` embeds the diagram-t
199
205
 
200
206
  - `docs/reference.md` — catalog of commands, tool options, defaults, output behavior, and limitations (documentation only; not read at runtime).
201
207
  - `assets/references/xml-authoring.md` — `.drawio` skeleton, cell/edge forms, containers, palette, spacing.
202
- - `assets/references/diagram-types.md` — per-type presets (ERD, UML, sequence, C4, architecture, ML, flowchart, SysML, BPMN, network, swimlane).
208
+ - `assets/references/diagram-types.md` — purpose-led compositions and per-type notation presets.
203
209
  - `assets/references/mermaid-authoring.md` — Mermaid authoring for supported renderers.
204
210
  - `assets/references/troubleshooting.md` — export/render failure recovery.
205
211
  - `assets/data/shape-index.json.gz` — the vendored draw.io shape index behind `drawio_shapesearch` (see its notice).
@@ -4,23 +4,30 @@ When the user requests a specific diagram type, apply the matching preset below
4
4
 
5
5
  Each preset ends with a **Review:** line — the type-specific defects to hunt during the visual review's holistic pass, on top of the generic fit, placement, connection, and typography checks.
6
6
 
7
- Read this file when:
8
- - The user names one of these diagram types (ERD, UML class, sequence, C4, architecture, ML/DL model, flowchart, SysML, BPMN, network topology, cross-functional/swimlane)
9
- - You're choosing shape vocabulary or layout direction for a new diagram
7
+ ## Choose a view
8
+
9
+ Honor an explicitly requested view or notation, including the other presets in this catalogue. Otherwise use the primary question to choose one composition; don't try to answer all five in one drawing. For an implementation view, use the relevant code, schema, or configuration to establish what belongs in it. For a conceptual view, work from the description without claiming it depicts an implementation.
10
+
11
+ - What is each part responsible for, and how do the parts interact? [Architecture overview](#architecture-diagram)
12
+ - What happens during this request, and in what order? [Request/sequence flow](#sequence-diagram)
13
+ - What records exist, and how do they relate? [Data model](#erd-entity-relationship-diagram)
14
+ - Where does this run, and how are the running parts connected? [Deployment](#deployment)
15
+ - What can the person do, and what do they see next? [User flow](#user-flow)
10
16
 
11
17
  ## ERD (Entity-Relationship Diagram)
12
18
 
13
- For SQL DDL, derive tables, primary keys, foreign keys, and crow's-foot relations from the schema before authoring. Mermaid ER conversion is suitable for a standard ERD if the CLI reports Mermaid support (draw.io 30.2.4 or newer); use XML with the styles below if conversion is unavailable or exact table styling or placement is required.
19
+ Show the entities, fields, and associations that answer the question. Put the entity name in a strong header, then left-align field names and relevant types in evenly spaced rows. Keep related cards near each other, with aligned tops and a clear side corridor for field-level connectors. Omit irrelevant fields rather than shrinking text. The layout is structural: do not impose a time axis, flow arrows, or an accent path.
20
+
21
+ Derive key roles, optionality, and multiplicity from constraints the schema actually establishes. Connect the relevant field rows on the facing sides when the relationship is field-based. For non-relational models or where a supported association has no established key or multiplicity, use a named association without those markers. Use Mermaid ER conversion only if supported and it preserves the needed field placement and end markers; otherwise place the cells in XML.
14
22
 
15
23
  | Element | Style | Notes |
16
24
  |---------|-------|-------|
17
- | Table | `shape=table;startSize=30;container=1;collapsible=1;childLayout=tableLayout;fixedRows=1;rowLines=0;fontStyle=1;strokeColor=#6c8ebf;fillColor=#dae8fc;` | Each table is a container |
18
- | Row (column) | `shape=tableRow;horizontal=0;startSize=0;swimlaneHead=0;swimlaneBody=0;fillColor=none;collapsible=0;dropTarget=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontSize=12;` | Child of table, `parent=tableId` |
19
- | PK column | Bold text: `fontStyle=1` on the row | Mark with `PK` prefix or key icon |
20
- | FK relationship | Dashed edge: `dashed=1;endArrow=ERmandOne;startArrow=ERmandOne;` | Use ER notation arrows |
21
- | Layout | TB, tables spaced 300px apart | Group related tables vertically |
25
+ | Table | `shape=table;startSize=30;container=1;collapsible=1;childLayout=tableLayout;fixedRows=1;rowLines=0;fontStyle=1;` | Each table is a container |
26
+ | Field row | `shape=tableRow;horizontal=0;startSize=0;swimlaneHead=0;swimlaneBody=0;fillColor=none;collapsible=0;dropTarget=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;align=left;fontSize=12;` | Child of table, `parent=tableId` |
27
+ | Key field | `fontStyle=1` on the row | Mark supported roles with `PK` or `FK` text |
28
+ | Association | `startArrow=none;endArrow=none;` for a named association without cardinality | For crow's-foot notation, set each supported end marker independently |
22
29
 
23
- **Review:** every column row fully readable inside its table; relationship lines meet tables at row level on the sides, never through the title band; ER end markers visible at both ends and clear of the table border; PK/FK markers present; relationship lines don't cross tables they don't join.
30
+ **Review:** trace both relationship ends to the correct entity or field and each key or multiplicity marker to its constraint. Check for misleading one-to-one defaults, lines through headers, and obscured end markers; all field rows must be readable.
24
31
 
25
32
  ## UML Class Diagram
26
33
 
@@ -38,18 +45,19 @@ For SQL DDL, derive tables, primary keys, foreign keys, and crow's-foot relation
38
45
 
39
46
  ## Sequence Diagram
40
47
 
41
- Prefer Mermaid conversion for a standard sequence diagram only when the CLI reports Mermaid support (draw.io 30.2.4 or newer). Use the styles below for XML diagrams when conversion is unavailable or exact lifelines, activation bars, message placement, or interaction frames are required.
48
+ Show the participants and messages needed to trace this request, not the complete component map. Put the initiator first, with participant headers aligned across the top on parallel lifelines. Give each evidenced interaction one horizontal message row; time runs top to bottom. Repeat the row gap, increasing it as needed for wrapped labels above their own arrows. Align calls from sender to recipient and show a return back to the caller only when the trace supports it. Label the action or meaningful payload/result, not just “request” or “response.”
49
+
50
+ Use the lifelines and row positions to show order, not numbered badges. If emphasis helps, accent the interaction the question turns on; distinguish returns by dash and direction, not hue. Preserve the participant columns and message rows if using supported Mermaid conversion. If they cannot be preserved, place the editable XML directly; do not re-layout a sequence with ELK.
42
51
 
43
52
  | Element | Style | Notes |
44
53
  |---------|-------|-------|
45
54
  | Actor/Object | `shape=umlLifeline;perimeter=lifelinePerimeter;whiteSpace=wrap;html=1;container=1;collapsible=0;recursiveResize=0;outlineConnect=0;portConstraint=eastwest;` | Lifeline with dashed vertical line |
46
- | Sync message | `html=1;verticalAlign=bottom;endArrow=block;` | Solid line, filled arrowhead |
47
- | Async message | `html=1;verticalAlign=bottom;endArrow=open;dashed=1;` | Dashed line, open arrowhead |
48
- | Return message | `html=1;verticalAlign=bottom;endArrow=open;dashed=1;strokeColor=#999999;` | Grey dashed |
49
- | Activation box | `shape=umlFrame;whiteSpace=wrap;` on the lifeline | Narrow rectangle on lifeline |
50
- | Layout | LR, lifelines spaced 200px apart | Time flows top to bottom |
55
+ | Sync message | `html=1;verticalAlign=bottom;endArrow=block;endFill=1;` | Solid line, filled arrowhead |
56
+ | Async message | `html=1;verticalAlign=bottom;endArrow=open;dashed=0;` | Solid line, open arrowhead |
57
+ | Return message | `html=1;verticalAlign=bottom;endArrow=open;dashed=1;` | Dashed line back to the caller |
58
+ | Activation box | `shape=umlFrame;whiteSpace=wrap;` on the lifeline | Narrow rectangle; use only for the supported activation span |
51
59
 
52
- **Review:** lifelines parallel, evenly spaced, and long enough for every message; messages horizontal with each label just above its own arrow, touching nothing; message order reads top→bottom as the described flow; activation boxes span exactly the messages they cover; returns dashed and grey.
60
+ **Review:** follow the request and its supported result down the page. Look for out-of-order rows, a call aimed at the wrong recipient, or an invented or reversed return. Each horizontal arrow should have a clear label above it and meet its lifelines at the intended row.
53
61
 
54
62
  ## C4 Model (System Context / Container / Component)
55
63
 
@@ -72,17 +80,19 @@ Use the styles below for C4 diagrams. A Mermaid C4 sketch works for a standard s
72
80
 
73
81
  ## Architecture Diagram
74
82
 
83
+ Show the components that matter, what each owns, and how they collaborate. Put the entry point or consumer where the reader starts, then collaborating components and their dependencies in a clear left-to-right or top-to-bottom arrangement. Align peers inside labeled responsibility boundaries and keep known external dependencies outside. Group only by real boundaries; don't impose Client / API / Service / Data tiers or turn an overview into a numbered execution trace. Use [C4](#c4-model-system-context--container--component) when that notation is requested.
84
+
85
+ Label boxes with a name and a short responsibility. Label directional connectors with domain verbs such as “queues jobs” or “reads settings” when those are the actual interactions. Use simple shapes and neutral groups; reserve emphasis for the component or interaction the reader came to understand.
86
+
75
87
  | Element | Style | Notes |
76
88
  |---------|-------|-------|
77
- | Layer/tier | `swimlane;startSize=30;` | Containers for grouping: Client / API / Service / Data |
78
- | Service | `rounded=1;whiteSpace=wrap;html=1;` + tier color | Use color palette by tier |
79
- | Database | `shape=cylinder3;whiteSpace=wrap;html=1;` | Green palette |
80
- | Queue/Bus | `rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;` | Yellow — place centrally for hub pattern |
81
- | Gateway/LB | `shape=mxgraph.aws4.resourceIcon;` or `rounded=1;` with orange | Orange palette |
82
- | External | `rounded=1;dashed=1;fillColor=#f5f5f5;strokeColor=#666666;` | Dashed border for external systems |
83
- | Layout | TB or LR by tier count; ≥4 tiers → TB | Hub nodes centered |
89
+ | Responsibility boundary | `swimlane;startSize=30;` | Label the responsibility and keep the title band clear |
90
+ | Component | `rounded=1;whiteSpace=wrap;html=1;` | Align peers and repeat their gaps |
91
+ | Database | `shape=cylinder3;whiteSpace=wrap;html=1;` | Use only for an actual data store |
92
+ | Queue/Bus | `rounded=1;whiteSpace=wrap;html=1;` | Center an actual hub when it shortens routes |
93
+ | External | `rounded=1;dashed=1;` | Label it as external; don't depend on fill color |
84
94
 
85
- **Review:** every child fully inside its tier container with padding on all sides; tier titles not overlapped by children or edges; hub/bus nodes reachable with short direct edges; no edge passes through an unrelated service; colors match the legend.
95
+ **Review:** can you explain what each boundary means in the source and what each arrow says the components do? Look for a plausible-looking but unsupported tier, a peer in the wrong group, or an arrow that substitutes proximity for a real interaction.
86
96
 
87
97
  ## ML / Deep Learning Model Diagram
88
98
 
@@ -200,6 +210,14 @@ Shared prefix (every node below): `fontColor=#0066CC;verticalAlign=top;verticalL
200
210
 
201
211
  **Review:** device labels below their icons, fully readable, and clear of links; every zone container fully encloses its devices with padding; link labels (interface/VLAN/CIDR) beside the line, never on it; tiers read top→bottom; no link passes through a device it doesn't terminate at.
202
212
 
213
+ ## Deployment
214
+
215
+ Show deployable workloads and the configured connections that answer where they run. Use labeled containers for the actual environment, host, cluster, or service boundaries at the level the configuration establishes. Nest workloads as editable children of the correct boundary, with aligned peers, even insets, and a clear title band. A flat manifest gives you peers, not invented regions or tiers. Put known externals outside the boundary with a dashed border and an explicit label. Use [Network Topology](#network-topology) for supplementary device and zone notation if needed; vendor icons are optional.
216
+
217
+ Use workload names and relevant runtime roles, not source directories or function calls. Leave routing space between boundaries and label each configured link with the established binding, endpoint, or protocol. Show direction only where the configuration establishes it; don't infer a port or draw a dependency as a live connection. Emphasize placement and any cross-boundary link central to the question, not a chronological main path.
218
+
219
+ **Review:** verify each workload's containment and each configured link against its manifest or runtime configuration. Look for siblings shown as nested, environment boundaries that don't exist, and labels that add an unconfigured endpoint or port.
220
+
203
221
  ## Cross-Functional Flowchart (Swimlane)
204
222
 
205
223
  A flowchart split by **who does what** — one lane per role/department. Node vocabulary reuses the Flowchart preset below; only the container skeleton differs.
@@ -227,3 +245,11 @@ A flowchart split by **who does what** — one lane per role/department. Node vo
227
245
  | Layout | TB, 200px vertical gap | Decisions branch LR, merge back to center |
228
246
 
229
247
  **Review:** flow reads top→bottom without backtracking; every decision has labeled Yes/No branches leaving different sides, with each label beside its own line; merge-back edges route around nodes through free corridors; start and end shapes visually distinct from process steps.
248
+
249
+ ## User Flow
250
+
251
+ Show one clear entry, the person's actions, what they see next, and the supported outcomes. Keep the primary journey on a single left-to-right or top-to-bottom axis with short action verbs and aligned, evenly spaced steps. Omit implementation hops and backend swimlanes unless requested. Borrow start/end, action, and decision shapes from [Flowchart](#flowchart-enhanced); use their shapes and labels to distinguish them even in Light.
252
+
253
+ Put real decisions on the primary path. Route alternatives in separate side lanes, with each actual condition or outcome beside its own outgoing line. Rejoin only where the journeys really converge; otherwise give each its own named end state. Use arrowheads to show the next step and accent the primary journey when it helps it stand out. Keep a linear journey linear instead of inventing a branch or failure state.
254
+
255
+ **Review:** start where the person starts and trace the primary path and each supported alternative to what they see next or where they end. Look for an unlabeled exit, a branch tied to the wrong condition, or an artificial merge that hides a distinct outcome.
@@ -1,8 +1,9 @@
1
1
  # Mermaid authoring → native .drawio
2
2
 
3
3
  Use Mermaid when the diagram is a standard type with no custom styling requirements and the CLI
4
- supports Mermaid conversion (draw.io 30.2.4 or newer). Mermaid keeps the input focused on structure
5
- while draw.io supplies the initial layout.
4
+ supports Mermaid conversion (draw.io 30.2.4 or newer), and only when conversion can preserve the
5
+ [chosen view](diagram-types.md#choose-a-view). Mermaid keeps the input focused on structure while
6
+ draw.io supplies the initial layout.
6
7
 
7
8
  Use the workflow's CLI status (or call `drawio_check` if it is not already known), then convert with:
8
9
 
@@ -21,7 +22,11 @@ Provide exactly one nonblank source: inline `mermaid` or an `input` `.mmd` file.
21
22
  |---|---|---|
22
23
  | **Mermaid → `drawio_from_mermaid`** | Flowchart, sequence, class, state, ER, gantt, mind map, timeline, journey, and similar standard diagrams | Concise structure and automatic initial layout |
23
24
  | **Uncompressed XML** | Official vendor icons, exact UML/BPMN notation, custom styling, swimlanes, containers, precise routing, or multi-page output | Full control over draw.io cells, styles, geometry, and pages |
24
- | **XML → `drawio_layout`** | Large or graph-heavy hand-authored diagrams when the CLI supports layout | Repositions nodes and routes edges with an allowlisted ELK preset |
25
+ | **XML → `drawio_layout`** | Large or graph-heavy hand-authored diagrams when the CLI supports layout and the view permits repositioning | Repositions nodes and routes edges with an allowlisted ELK preset |
26
+
27
+ Use hand placement when conversion or auto-layout would lose sequence message order or lifeline
28
+ columns, entity-row anchors or end markers, workload containment, or decision labels on their
29
+ branches. Do not apply generic ELK layout to a sequence.
25
30
 
26
31
  If the user requests Mermaid source rather than a `.drawio` deliverable, do not convert it unless they
27
32
  also ask for a draw.io file.
@@ -40,8 +45,11 @@ also ask for a draw.io file.
40
45
  - Match label language to the user's language.
41
46
  - Never apply `drawio_layout` to a Mermaid-converted file; conversion already lays it out.
42
47
 
43
- After conversion, treat the `.drawio` as the source of truth. Fit the finite canvas with
44
- `drawio_fit_canvas`, validate again, review a preview, then create the requested final exports.
48
+ After conversion, treat the `.drawio` as the source of truth. Apply the active theme's colors and
49
+ typography without changing notation or direction. Check the editable structure against the chosen
50
+ composition; correct it by hand or author directly in XML if conversion lost essential details.
51
+ Fit the finite canvas with `drawio_fit_canvas`, validate again, review a preview when available,
52
+ then create the requested final exports.
45
53
 
46
54
  ## ELK layout for XML-authored diagrams
47
55
 
@@ -13,16 +13,15 @@ Never switch themes on your own because a diagram type, a slide, or a README see
13
13
  ## Applying a theme
14
14
 
15
15
  - **Set the page background** on the model, for example `<mxGraphModel background="#FFFFFF" ...>`. Every export, the animated SVG, and the storyboard read it. DrawMe pins exported SVGs to the authored colors, so a viewer in dark mode never inverts a Light diagram or brightens a Dark one.
16
- - **One primary path.** Draw the main flow with the accent edge style (thicker, accent color) and every secondary connection with the neutral edge style. The reader should see the story before reading a label.
17
- - **Accent with restraint.** In Light and Dark, the accent marks only the main path, numbered step badges, and the one or two nodes the diagram is about. Everything else is neutral.
18
- - **Hierarchy through type.** Put a title (28px bold) and a one-line subtitle (16px, muted) top-left as `text` cells. Node labels use a bold name plus a muted detail line: `value="&lt;b&gt;API&lt;/b&gt;&lt;br&gt;&lt;font style=&quot;font-size:12px&quot; color=&quot;#64748B&quot;&gt;Process request&lt;/font&gt;"` (use the theme's muted color).
19
- - **Shape language.** Rounded corners with a fixed radius (`absoluteArcSize=1;arcSize=12;`), 1.5px strokes, no `shadow=1` (draw.io's shadow is heavy and dated), generous inner padding (`spacing=12;`). Keep peer nodes the same size.
20
- - **Containers recede.** Zones and groups use a near-background tint, a hairline stroke, and a small title at the top-left. They never compete with the nodes they hold.
21
- - **Numbered steps.** For a sequence, put a 28×28 accent badge with the number beside each step instead of numbering inside the label.
22
- - **Whitespace is part of the design.** Keep the spacing table from the XML authoring reference, align everything to a 10px grid, and run `drawio_fit_canvas`.
23
- - **Edge labels** use the page background as `labelBackgroundColor` so they sit cleanly on lines.
24
- - **Icons.** Prefer official vendor icons from `drawio_shapesearch` at a consistent size (48×48 inside or beside a node). Never mix icon families in one diagram.
25
- - **Legend.** Light and Dark need none unless the accent needs explaining. Multi-color lists exactly the roles used.
16
+ - **Accent with restraint.** Follow the view in [Diagram Type Presets](diagram-types.md#choose-a-view). Accent the subject, a key relationship, or a genuine primary journey; keep other connections neutral. Do not invent a main path for a data model or deployment map. Preserve structural connector styles such as dashed returns and ER end markers when applying theme colors.
17
+ - **Hierarchy through type.** Use one family (Helvetica by default). Put a title (28px bold) and, when useful, a one-line subtitle (16px, muted) top-left as `text` cells. Lead node labels with the name (14px); add detail only if useful (12px), e.g. `value="&lt;b&gt;API&lt;/b&gt;&lt;br&gt;&lt;font style=&quot;font-size:12px&quot; color=&quot;#64748B&quot;&gt;Process request&lt;/font&gt;"` (use the theme's muted color).
18
+ - **Shape language.** Use rounded corners (`absoluteArcSize=1;arcSize=12;`) for ordinary boxes, 1.5px strokes, no `shadow=1`, and generous inner padding (`spacing=12;`). Keep notation-specific shapes and size peers consistently without clipping their labels.
19
+ - **Containers recede.** Zones and groups use a near-background tint, a hairline stroke, and a small title at the top-left. Distinguish groups by boundary and label, not tint alone.
20
+ - **Numbered steps.** A 28×28 accent badge can mark an explicitly numbered step in a flow. Leave badges off sequence messages: row position shows their order.
21
+ - **Whitespace is part of the design.** Follow [XML layout tips](xml-authoring.md#layout-tips) for grid alignment, spacing, and fitting the canvas to the selected composition.
22
+ - **Edge labels.** Offset text from the line and set `labelBackgroundColor` to the actual background behind the label (page or container). Inspect muted detail and edge labels for contrast; do not rely on color alone for meaning.
23
+ - **Icons.** When icons help, prefer official vendor icons from `drawio_shapesearch` at a consistent size (48×48 inside or beside a node). Never mix icon families in one diagram.
24
+ - **Legend.** Light and Dark need none unless a visual convention needs explaining. Multi-color lists exactly the roles used.
26
25
 
27
26
  ## Light (default)
28
27
 
@@ -86,9 +85,9 @@ Keep the Light or Dark base (background, text, edges, containers, badges) and co
86
85
 
87
86
  Motion follows the theme: `drawio_animate` uses the theme accent for `highlight` and `travel` by default (`#2563EB` on a light page, `#60A5FA` on a dark one). Pass `color` only to match a Multi-color role. The motion should explain the diagram, not decorate it:
88
87
 
89
- - **Tell the story in order.** Reveal the title, then the first actor, then each hop of the main path: `popIn` or `slideIn` the node, `drawIn` the connector to the next node, `popIn` that node. Reveal containers before their children.
88
+ - **Reveal structure before detail.** Reveal the title and containers before their children. For a real flow, use its established order: `popIn` or `slideIn` the node, `drawIn` its connector, then `popIn` the next node. For a structural view, reveal groups and associations without implying execution order.
90
89
  - **Cascade peers.** Reveal a row of similar nodes in one step with `stagger` 80–150ms rather than one step per node.
91
- - **Show traffic after structure.** Once everything is visible, `travel` dots along the main path (use `parallel` to run several hops as a pipeline), then `highlight` the focus node.
90
+ - **Show traffic only where it exists.** Once everything is visible, `travel` dots along the actual flow (use `parallel` for concurrent hops), then `highlight` the focus node. Do not animate traffic along a structural association.
92
91
  - **Focus by dimming.** `dim` everything except the part being explained, then `fadeIn` it back.
93
92
  - **Pace for reading.** Entrances 400–700ms, connector draw-in 600–1000ms, a 300–600ms `wait` after each logical group, and a loop `hold` of 1500–2500ms so the final state can be read. Keep one full loop under about 15 seconds.
94
- - **Restraint.** Animate the primary path and its nodes; leave legends and annotations static or reveal them once at the end.
93
+ - **Restraint.** Animate only the part being explained; leave legends and annotations static or reveal them once at the end.
@@ -41,12 +41,12 @@ Background for manual sizing (what the fit computes): visible top-level vertex/c
41
41
 
42
42
  ### Typography, padding, and labels
43
43
 
44
- - Default to **14px for body/node labels** and **12px for connector labels** — set `fontSize=14;` on nodes and `fontSize=12;` on connectors instead of relying on draw.io's smaller default. Headings and title/hub nodes usually need 16–18px. Compact border ports and notation-mandated annotations may use 9–10px when their short labels remain legible; record the exception during review.
44
+ - Follow the [theme's type hierarchy](style-presets.md#applying-a-theme): one family, 28px title, 16px optional subtitle, **14px for body/node labels** and **12px for connectors and detail**. Compact border ports and notation-mandated annotations may use 9–10px when their short labels remain legible; record the exception during review.
45
45
  - Add `whiteSpace=wrap;html=1;` to labeled nodes. Use about 10–16px visual padding (`spacing=10;` or directional spacing) between text and shape borders.
46
46
  - Size a node for the rendered lines, not only character count. A conservative height is `line count × (fontSize × 1.25) + top/bottom padding`; allow additional room for container title bands and icon shapes.
47
47
  - Estimate width from the longest line (`characters × fontSize × 0.6 + left/right padding`), then verify by preview. Keep boxes visually snug: for a short label, prefer the estimated width plus about 24px total padding over a large reused default. Preserve intentional uniform sizing among peer nodes when it improves alignment. Insert deliberate `&#xa;` breaks for long labels rather than forcing a very wide node.
48
48
  - Prefer two or three concise lines. If a label remains long, enlarge the node, shorten the wording without changing meaning, or split details into a note/legend. Never reduce important body text merely to fit existing geometry.
49
- - A 2000px full-diagram preview scales the entire page. If labels become unreadable at that width, simplify the layout, tighten the canvas, split the diagram into pages, or use a focused review export; never accept an unreadable full view as passing typography.
49
+ - The editable canvas is fixed; a narrow viewer scales it rather than reflowing it. At a full-page overview, keep the subject, major groups, and direction discernible. Check full-size or zoomed content for uncut text and clear links. If labels are unreadable at normal review size, simplify the layout, shorten subordinate labels, tighten the canvas, or split into focused pages; never accept an unreadable full view as passing typography.
50
50
 
51
51
  ### Fix recipes: visual defect → source edit
52
52
 
@@ -54,10 +54,10 @@ When the preview critique narrows a finding down to specific cells, apply the ma
54
54
 
55
55
  | Visual defect (seen in the preview) | Fix |
56
56
  |-------------------------------------|-----|
57
- | Two shapes (or their labels) touch or overlap | Move the shapes apart per the spacing table, then `drawio_fit_canvas` — never shrink content |
57
+ | Two shapes (or their labels) touch or overlap | Increase the affected gap within the view's placement rules, then `drawio_fit_canvas` — never shrink content |
58
58
  | Label text touches or crosses its own shape border | Enlarge the node per the sizing formulas above, add `spacing=10;`, or insert `&#xa;` breaks |
59
59
  | Label text clipped / cut off mid-word | Same as above — the node is too small for the rendered lines |
60
- | Edge label struck through by its own line, or hugging it | Lift the label off the line with an offset in the edge's label geometry (example below) and add `labelBackgroundColor=#ffffff;` |
60
+ | Edge label struck through by its own line, or hugging it | Lift the label off the line with an offset in the edge's label geometry (example below) and match `labelBackgroundColor` to the background behind it |
61
61
  | Edge label overlaps another edge, label, or shape | Slide it along the edge (geometry `x` between `-1` and `1`) toward a clear stretch, plus the offset/background above |
62
62
  | Any text with a line running underneath it | Reroute the edge around the text with waypoints, or move the label — text over lines is never acceptable |
63
63
  | Arrowhead buried in a bend or hidden by a shape | Keep the final segment before the target ≥20px: move the last waypoint or increase spacing |
@@ -65,7 +65,7 @@ When the preview critique narrows a finding down to specific cells, apply the ma
65
65
  | Two edges stacked on the same path | Spread their entry/exit points (see the distribution table below) |
66
66
  | Edge detours or makes needless 90° bends | Re-pin its exit/entry to the side facing the peer (see the facing table below); add waypoints only if a shape still blocks the corridor |
67
67
  | Box has excessive empty side margins | Tighten it using the label-width estimate while preserving deliberate uniform sizing among peer nodes, then `drawio_fit_canvas` |
68
- | Icon shape's label overlaps the icon artwork | Move the label outside: `verticalLabelPosition=bottom;verticalAlign=top;labelBackgroundColor=#ffffff;` |
68
+ | Icon shape's label overlaps the icon artwork | Move the label outside: `verticalLabelPosition=bottom;verticalAlign=top;` with a label backing that matches the actual background |
69
69
  | Content touching a page edge, uneven margins, or big empty areas | Re-space the elements if needed, then run `drawio_fit_canvas` |
70
70
 
71
71
  **Positioning an edge label** — the edge's own label is placed by its geometry: `x` runs along the edge from `-1` (source) through `0` (center) to `1` (target), and an `<mxPoint as="offset">` shifts it in page pixels (negative `y` = up):
@@ -115,7 +115,7 @@ The examples use Light theme colors; swap in the active theme's colors.
115
115
 
116
116
  ### Containers and groups
117
117
 
118
- For architecture diagrams with nested elements, use draw.io's parent-child containment — do **not** just place shapes on top of larger shapes.
118
+ For nested elements (such as components within a responsibility boundary or workloads within an environment), use draw.io's parent-child containment — do **not** just place shapes on top of larger shapes. Reserve a title band above children (`startSize` for horizontal swimlanes) and leave an even inset on open sides. For example, start with a 30px title band and 20px child inset; grow the band for wrapped titles and keep routes clear of the text.
119
119
 
120
120
  | Type | Style | When to use |
121
121
  |------|-------|-------------|
@@ -146,7 +146,7 @@ For architecture diagrams with nested elements, use draw.io's parent-child conta
146
146
  **CRITICAL:** Every edge `mxCell` must contain a `<mxGeometry relative="1" as="geometry" />` child element. Self-closing edge cells (`<mxCell ... edge="1" ... />`) are **invalid** and will not render. Always use the expanded form.
147
147
 
148
148
  ```xml
149
- <!-- Directed arrow — always include rounded, orthogonalLoop, jettySize for clean routing -->
149
+ <!-- Generic orthogonal arrow — use the selected notation for specialized edges -->
150
150
  <mxCell id="10" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="1" source="2" target="3">
151
151
  <mxGeometry relative="1" as="geometry" />
152
152
  </mxCell>
@@ -168,8 +168,8 @@ For architecture diagrams with nested elements, use draw.io's parent-child conta
168
168
 
169
169
  **Edge style rules:**
170
170
  - **Animated connectors:** add `flowAnimation=1;` to an edge style to show moving dashes from source to target. Optional controls are `flowAnimationDuration=500;` (positive milliseconds; larger is slower), `flowAnimationTimingFunction=linear;` (`linear`, `ease`, `ease-in`, `ease-out`, or `ease-in-out`), and `flowAnimationDirection=normal;` (`normal`, `reverse`, `alternate`, or `alternate-reverse`). Example: `style="edgeStyle=orthogonalEdgeStyle;flowAnimation=1;flowAnimationDuration=1200;flowAnimationDirection=normal;rounded=1;..."`. A verified animated SVG preserves this motion; PNG/PDF/JPG remain static.
171
- - **Always** include `rounded=1;orthogonalLoop=1;jettySize=auto` — these enable smart routing that avoids overlaps
172
- - Pin `exitX/exitY/entryX/entryY` on every edge when a node has 2+ connections. Pick the side facing each peer and spread that side's edges over evenly spaced slots so they do not stack or cross at the boundary.
171
+ - For general orthogonal edges, start with `rounded=1;orthogonalLoop=1;jettySize=auto`. Do not replace a view's straight message arrows, row-level associations, or other notation with generic routing.
172
+ - Pin `exitX/exitY/entryX/entryY` on the facing sides when multiple connections need separation. Space ordinary edges over clear slots; preserve specific message heights, field-row anchors, and decision exits where they carry meaning.
173
173
  - Add `<Array as="points">` waypoints when an edge must detour around an intermediate shape
174
174
  - **Leave room for arrowheads:** the final straight segment between the last bend and the target shape must be ≥20px long. If too short, the arrowhead overlaps the bend and looks broken. Fix by increasing node spacing or adding explicit waypoints
175
175
  - **Obstacle-avoiding routing (draw.io ≥ 30):** the desktop editor can recompute connectors around shapes without moving nodes. This is an interactive editor feature, not a `drawio_layout` preset. If a dense diagram still has crossings after preview, offer to open the `.drawio` in draw.io desktop for manual routing.
@@ -254,7 +254,7 @@ Rules:
254
254
 
255
255
  ### Distributing connections on a shape
256
256
 
257
- When multiple edges connect to the same shape, assign different entry/exit points to prevent stacking:
257
+ For ordinary box-to-box edges, assign different entry/exit points to prevent stacking. Keep the notation's own anchors for lifelines, field rows, and other specialized endpoints.
258
258
 
259
259
  | Position | exitX/entryX | exitY/entryY | Use when |
260
260
  |----------|-------------|-------------|----------|
@@ -282,7 +282,7 @@ Before spreading multiple edges on one side, pick the side that faces the peer.
282
282
 
283
283
  ### Color palette (fillColor / strokeColor)
284
284
 
285
- *Classic draw.io palette. Use it only when the user explicitly asks for the classic draw.io colors; otherwise use the active theme from `references/style-presets.md` (Light unless the user asks for Dark or Multi-color).*
285
+ *Classic draw.io palette. Use it only when the user explicitly asks for the classic draw.io colors; otherwise use the active [theme](style-presets.md) (Light unless the user asks for Dark or Multi-color).*
286
286
 
287
287
  | Color name | fillColor | strokeColor | Use for |
288
288
  |-----------|-----------|-------------|---------|
@@ -296,7 +296,7 @@ Before spreading multiple edges on one side, pick the side that faces the peer.
296
296
 
297
297
  ### Legend (auto-generate from the palette)
298
298
 
299
- When a Multi-color (or explicitly requested classic) diagram uses 3+ semantic colors, add a legend so the color coding is self-explanatory. Generate it mechanically from the roles actually present — never invent legend entries that aren't in the diagram:
299
+ Include a legend for Multi-color role coding, or when another visual convention needs explaining. Use only meanings actually present; do not make a legend the sole cue for boundaries, return messages, or decisions:
300
300
 
301
301
  ```xml
302
302
  <!-- Legend container: place in a corner clear of the diagram (e.g. below-left) -->
@@ -312,11 +312,11 @@ When a Multi-color (or explicitly requested classic) diagram uses 3+ semantic co
312
312
  </mxCell>
313
313
  ```
314
314
 
315
- Rules: swatch colors come from the active palette (preset or the table above) with the **role name** as the label (Service, Database, Queue, …); height = `30 + 24 × rows`; the legend is a container (`parent="legend"`, relative coordinates); skip it entirely for single-color diagrams.
315
+ For a role legend, swatch colors come from the active palette with the **role name** as the label (Service, Database, Queue, …). In this example, height = `30 + 24 × rows`, and legend children use `parent="legend"` and relative coordinates.
316
316
 
317
317
  ### Layout tips
318
318
 
319
- **Spacing — scale with complexity:**
319
+ Use the [selected view](diagram-types.md#choose-a-view) to set the composition first. The gaps below are starting points for **independent boxes**, not for sequence message rows, entity fields, or nested children. Give each peer set a repeated gap and align its leading edges or centers. Leave enough height for wrapped labels rather than reducing type.
320
320
 
321
321
  | Diagram complexity | Nodes | Horizontal gap | Vertical gap |
322
322
  |-------------------|-------|----------------|--------------|
@@ -324,21 +324,19 @@ Rules: swatch colors come from the active palette (preset or the table above) wi
324
324
  | Medium | 6–10 | 280px | 200px |
325
325
  | Complex | >10 | 350px | 250px |
326
326
 
327
- **Routing corridors:** between shape rows/columns, leave an extra ~80px empty corridor where edges can route without crossing shapes. Never place a shape in a gap that edges need to traverse.
327
+ **Routing corridors:** reserve an open route between rows, columns, or group boundaries where edges need to pass. Start with about 80px of additional space where labels or multiple routes need clearance; widen that corridor rather than inflating all the gaps. Keep arrowheads and endpoint markers visible.
328
328
 
329
- **Grid alignment:** snap all `x`, `y`, `width`, `height` values to **multiples of 10** — this ensures shapes align cleanly on draw.io's default grid and makes manual editing easier.
329
+ **Grid alignment:** use the **10px grid** for main boxes and groups. Preserve notation-specific sizes and coordinates where the grid would move a field anchor or break a message row.
330
330
 
331
331
  **General rules:**
332
332
  - Run `drawio_fit_canvas` after every layout change so `pageWidth`/`pageHeight` track the content; it keeps the recommended 40px outer margin (DrawMe warns below the 20px minimum)
333
333
  - Plan a grid before assigning x/y coordinates — sketch node positions on paper/mentally first
334
- - Group related nodes in the same horizontal or vertical band
335
- - Use `swimlane` cells for logical grouping with visible borders
336
- - Place heavily-connected "hub" nodes centrally so edges radiate outward instead of crossing
334
+ - Align related peers horizontally or vertically; use visible `swimlane` boundaries only for real groups the view needs to show
335
+ - Place actual hubs centrally if that improves routing without breaking the view's composition
337
336
  - To force straight vertical connections, pin entry/exit points explicitly on edges:
338
337
  `exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0`
339
- - Always center-align a child node under its parent (same center x) to avoid diagonal routing
340
- - **Event bus pattern**: place Kafka/bus nodes in the **center of the service row**, not below — services on either side can reach it with short horizontal arrows (`exitX=1` left side, `exitX=0` right side), eliminating all line crossings
341
- - Horizontal connections (`exitX=1` or `exitX=0`) never cross vertical nodes in the same row; use them for peer-to-peer and publish connections
338
+ - Center a child under its parent in a tree when that supports straight routing; in a container, align children as peers with clear title and border insets
339
+ - **Event bus pattern:** if the architecture has a bus and the composition permits it, center it on the service row for shorter horizontal connections; inspect the route for crossings
342
340
 
343
341
  **Avoiding edge-shape overlap:**
344
342
  - Before finalizing coordinates, trace each edge path mentally — if it must cross an unrelated shape, either move the shape or add waypoints