1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
|
# Importing, Exporting & DSL Reference
`design-it` supports **four workflows** for bringing architectures in and out:
1. **Readable Text DSL (`.dit.txt`)** — git-diffable, editable by hand or generated by scripts, mirrored live in the **Source** view.
2. **C/C++ Codebase Scanner (`--scan` / `:scan`)** — parses real `.h` / `.hpp` headers into an auto-laid-out interactive UML diagram.
3. **Fast Binary Project Format (`.dit`)** — direct flat-pool dump for instant microsecond save/load of huge diagrams.
4. **Themed Vector SVG Export (`--export-svg` / `:export`)** — crisp standalone `.svg` files matching your active color scheme.
---
## 1. Opening, Saving & Exporting
### From the Command Line
```sh
# Open a readable DSL file or binary .dit file
design-it path/to/architecture.dit.txt
design-it path/to/architecture.dit
# Start from a built-in template
design-it --template=arch # Design-It engine architecture (default)
design-it --template=ecs # Data-oriented ECS game engine
design-it --template=microservices # Event-driven backend
design-it --template=compiler # Frontend -> SSA IR -> Codegen pipeline
design-it --template=uml # Classic UML class & design patterns
design-it --template=stress # 1,000 nodes / 1,935 edges benchmark
# Scan a C/C++ file or directory into a live interactive diagram
design-it --scan=/path/to/project/source
# Headless SVG export (no Wayland window required — great for CI & docs!)
design-it architecture.dit.txt --export-svg=architecture.svg
design-it architecture.dit.txt --set="color scheme=mono light" --export-svg=light.svg
design-it --scan=./include --set="color scheme=nord" --export-svg=codebase.svg
```
### Inside the App (`:` Command Bar)
```text
:open examples/sample_engine.dit.txt # Load .dit.txt (DSL) or .dit (binary)
:save my_arch.dit.txt # Save readable DSL (any extension except .dit)
:save my_arch.dit # Save fast binary snapshot (.dit extension)
:export my_arch.svg # Export crisp vector SVG in current color scheme
:scan ../mp3_player/source # Scan C/C++ headers into the current workspace
:tpl compiler # Load a built-in showcase template
```
> **Tip:** Format selection on `:save` / `:open` is automatic by extension: `.dit` uses binary mode; `.dit.txt` (or any other extension) uses the readable text DSL.
---
## 2. The `.dit.txt` DSL Specification
Every diagram can be written directly in plain text, versioned in Git, or generated programmatically. You can inspect the exact DSL of your current diagram at any time in the **Source** view (`:view source`).
### Top-Level Header
```text
diagram "My Software Architecture" routing=orthogonal
```
- `routing=` accepts `orthogonal`, `straight`, or `bezier` (optional, defaults to `orthogonal`).
- Comments start with `#` or `//`.
### Declaring Nodes
```text
<kind> "<Display Name>" [attributes...] [{ ...body... }]
```
- **Supported `<kind>` values:** `struct`, `class`, `interface`, `enum`, `module`, `system`, `storage`, `state`, `note`.
- **Optional attributes** (space-separated `key=value` pairs):
- `id=<identifier>` — unique key referenced by edges (auto-generated from name if omitted).
- `stereo="<subtitle>"` — stereotype or subtitle shown under the title (e.g. `stereo="<<interface>>"` or `stereo="lock-free"`).
- `tag=<layer_name>` — assigns the node to a filterable layer in the **Layers** view.
- `color=#RRGGBB` or `color=#RRGGBBAA` — custom accent color override.
- `x=<num> y=<num>` — explicit world coordinates. **If omitted for all nodes, `design-it` automatically runs hierarchical Sugiyama layout on load!**
- `w=<num> h=<num>` — explicit manual size override.
- `collapsed=1` — start collapsed.
### Node Body: Notes, Custom Sections, Members & Nested Children
Inside `{ ... }`, a node can contain:
- `note "<text>"` — inline summary line under the header.
- `section "<Title>" { ... }` — any number of custom compartments.
- Inside a section, each non-empty line is a member:
```text
[vis] <name> [: <type>] [[<badge>]]
```
where `[vis]` is optionally one of `+`, `-`, `#`, `~`, `@`, `*` followed by a space.
- **Nested child nodes** inside a `module` block — any node declared inside a `module { ... }` automatically has that module as its parent container!
### Declaring Edges
Edges go at the top level (after the nodes they reference):
```text
<src_id> <symbol> <dst_id> [: "<label>"] [[<src_mult> -> <dst_mult>]] [route=<mode>] [tag=<layer>]
```
- **Edge `<symbol>` operators:**
- `->` association
- `..>` dependency
- `-|>` inheritance
- `..|>` implements / realizes
- `*->` composition (filled diamond at source)
- `o->` aggregation (hollow diamond at source)
- `==>` dataflow (thick solid accent line)
- `~>` async message
- `<->` bidirectional
- `--` undirected link
- **Optional edge modifiers:**
- `: "label"` — center label pill.
- `[1 -> 0..*]` — source and target UML multiplicities.
- `route=orthogonal|straight|bezier` — per-edge routing override.
- `tag=<layer>` — layer tag for filtering.
### Complete Minimal Example (Auto-Laid-Out)
Notice you do **not** need `x=`/`y=` coordinates — omit them and `design-it` lays out the graph cleanly for you:
```text
diagram "Task Queue Subsystem" routing=orthogonal
module "Runtime" id=rt tag=core {
interface "Job" id=job stereo="<<interface>>" {
section "contract" {
+ run(ctx) : void [pure]
}
}
struct "JobQueue" id=queue stereo="MPSC ring" {
section "memory (64 B)" {
+ head : atomic<u64> [0x00]
+ tail : atomic<u64> [0x40]
- slots : Job*[] [ring]
}
}
system "WorkerPool" id=pool {
section "methods" {
+ submit(Job*) : bool [lock-free]
+ shutdown() : void
}
}
}
pool *-> queue : "owns" [1 -> 1]
queue o-> job : "buffers" [1 -> 0..*]
pool ==> job : "executes"
```
See [examples/sample_engine.dit.txt](../examples/sample_engine.dit.txt) for a larger ready-to-open example.
---
## 3. Importing Real C / C++ Codebases (`:scan` / `--scan`)
`design-it` includes a built-in zero-dependency C/C++ structure scanner that turns real header trees into interactive architecture diagrams in milliseconds:
```sh
# Open interactively
design-it --scan=/home/nasr/dev/mp3_player/source
# Or scan a single header file
design-it --scan=/home/nasr/dev/design-it/source/diagram/diagram.h
# Or export directly to SVG without opening a window
design-it --scan=/home/nasr/dev/mp3_player/source --export-svg=mp3_player_arch.svg
```
### What the Scanner Extracts
1. **Modules:** Each subdirectory becomes a `module` container (empty directories, `build/`, `protocols/`, and `node_modules/` are skipped).
2. **Types:** Scans `.h` and `.hpp` files (up to depth 4) for `struct`, `class`, and `enum` / `enum class` definitions.
3. **Members:** Extracts up to 14 fields per struct/class (preserving pointer `*` markers) and enumerators per enum; tags each node with its source header filename so you can filter by header in the **Layers** view!
4. **Relationships (auto-inferred):**
- C++ base classes (`: public Base`) become `-|>` **inheritance** edges.
- Embedded struct fields (`Foo member;`) become `*->` **composition** edges **pinned directly to that field row**.
- Pointer fields (`Foo *ptr;`) become `->` **association** edges **pinned directly to that field row**.
5. **Auto-Layout:** Runs Sugiyama layered layout and fits all module containers automatically.
### Tips for Large Codebases
- After scanning a big repo, press **`F`** (Focus Mode) and click any core struct to immediately isolate its 1-hop or 2-hop dependency neighborhood!
- Use the **Layers** view to hide utility headers (e.g. `base_*.h`) and focus on domain modules.
- Save the curated result with `:save architecture.dit.txt` so your manual tweaks, notes, and custom layouts are preserved in Git.
---
## 4. Importing from Other Languages & External Tools
Because `.dit.txt` is line-oriented and supports automatic layout when `x`/`y` are omitted, writing a 20-line importer from **any** source (Rust, Go, TypeScript, Python AST, SQL schemas, OpenAPI, Terraform, or JSON) is trivial:
```python
#!/usr/bin/env python3
# Example: generate a design-it diagram from a JSON schema / service list
import json, sys
data = json.load(sys.stdin)
print(f'diagram "{data["title"]}" routing=orthogonal\n')
for svc in data["services"]:
print(f'system "{svc["name"]}" id={svc["id"]} tag={svc.get("layer", "app")} {{')
if svc.get("endpoints"):
print(' section "endpoints" {')
for ep in svc["endpoints"]:
print(f' @ {ep["path"]} : {ep["method"]}')
print(' }')
print('}')
for edge in data["links"]:
print(f'{edge["from"]} {edge.get("op", "->")} {edge["to"]} : "{edge.get("label", "")}"')
```
Pipe the generated file straight into `design-it`:
```sh
python3 gen_diagram.py < services.json > services.dit.txt
design-it services.dit.txt
```
---
## Documentation, source links, bends and sequences
```text
diagram "Login" routing=orthogonal repo="https://github.com/you/project" ref="main"
doc """
Diagram level documentation. Line breaks are kept,
the block's indentation is removed.
"""
struct "Queue" id=queue link="src/queue.h:42" x=0 y=0 {
doc """
Lock free single producer / single consumer ring.
"""
}
class "Worker" id=worker x=400 y=0
queue -> worker : "feeds" via=200,100;200,40 {
doc """
Why this relationship exists.
"""
}
lifeline "Client" id=client x=0 y=300
lifeline "Server" id=server x=300 y=300
client ->> server : "GET /" y=400
server -->> client : "200" y=444
```
- `doc """ ... """`: on the diagram (top level), inside a node body, or inside an edge's `{ }` body.
- `link=`: `path/in/repo.c:42`, `file.c#L42` or a full url. `gx` opens it online (needs `repo=`),
`gf` opens the local file (set `DESIGN_IT_EDITOR="code -g {file}:{line}"` to land on the line).
- `repo=` / `ref=` / `root=`: where links open online and on disk. `:repo detect` reads them from `.git`.
- `via=x,y;x,y`: the bends of an edge (up to 8).
- `lifeline` / `actor` nodes with `->>` (message), `-->>` (reply) and `~>` (async) edges; `y=` is the
message's height.
## Mermaid & PlantUML
```sh
design-it diagram.mmd # open (also .mermaid, .puml, .plantuml)
design-it diagram.dit.txt --export=out.mmd # class / flowchart / sequence, picked from the diagram
design-it diagram.dit.txt --export=out.mmd --export-style=flowchart
design-it diagram.dit.txt --export=README.md # mermaid in a ```mermaid block
design-it diagram.dit.txt --export=out.puml
design-it diagram.dit.txt --export=out.png --export-style=2 # needs a display
```
In the app: `:open`, `:import` (merge into the current diagram), `:export`, or paste Mermaid /
PlantUML text straight onto the canvas with `p` / `Ctrl+V`.
|