c4studio 0.3.0__tar.gz → 0.5.0__tar.gz
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.
- {c4studio-0.3.0 → c4studio-0.5.0}/PKG-INFO +248 -14
- {c4studio-0.3.0 → c4studio-0.5.0}/README.md +243 -13
- {c4studio-0.3.0 → c4studio-0.5.0}/pyproject.toml +5 -1
- c4studio-0.5.0/src/c4studio/bundled_icons.py +164 -0
- c4studio-0.5.0/src/c4studio/cli/main.py +890 -0
- c4studio-0.5.0/src/c4studio/diff.py +417 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/generators/json_export.py +26 -9
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/graph/view_graph.py +511 -35
- c4studio-0.5.0/src/c4studio/icon_library.py +126 -0
- c4studio-0.5.0/src/c4studio/icon_packs/tabler/LICENSE +21 -0
- c4studio-0.5.0/src/c4studio/icon_packs/tabler/README.md +24 -0
- c4studio-0.5.0/src/c4studio/icon_packs/tabler/icons.json +4830 -0
- c4studio-0.5.0/src/c4studio/icons.py +303 -0
- c4studio-0.5.0/src/c4studio/impact.py +288 -0
- c4studio-0.5.0/src/c4studio/layout_sidecar.py +365 -0
- c4studio-0.5.0/src/c4studio/lint.py +484 -0
- c4studio-0.5.0/src/c4studio/logo_library.py +210 -0
- c4studio-0.5.0/src/c4studio/markdown.py +259 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/models/views.py +17 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/parser/dsl.py +722 -69
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/parser/json_parser.py +98 -1
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/parser/locations.py +52 -0
- c4studio-0.5.0/src/c4studio/publish.py +501 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/render.py +85 -1
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/renderer/diagram-render.mjs +2279 -782
- c4studio-0.5.0/src/c4studio/style_edit.py +399 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/themes.py +9 -3
- c4studio-0.5.0/src/c4studio/webapp/graph.py +338 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/webapp/model_graph.py +3 -0
- c4studio-0.5.0/src/c4studio/webapp/perspectives.py +164 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/webapp/server.py +960 -179
- c4studio-0.5.0/src/c4studio/webapp/static/assets/index-DhOzvpS3.js +96 -0
- c4studio-0.5.0/src/c4studio/webapp/static/assets/index-TnH5vjSh.css +1 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/webapp/static/index.html +2 -2
- c4studio-0.3.0/src/c4studio/cli/main.py +0 -447
- c4studio-0.3.0/src/c4studio/icons.py +0 -100
- c4studio-0.3.0/src/c4studio/webapp/graph.py +0 -140
- c4studio-0.3.0/src/c4studio/webapp/static/assets/index-B7IeVhQr.js +0 -80
- c4studio-0.3.0/src/c4studio/webapp/static/assets/index-BosnE_L9.css +0 -1
- {c4studio-0.3.0 → c4studio-0.5.0}/LICENSE +0 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/__init__.py +0 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/__main__.py +0 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/cli/__init__.py +0 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/diagnostics.py +0 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/generators/__init__.py +0 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/generators/flowchart.py +0 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/generators/mermaid.py +0 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/generators/mermaid_common.py +0 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/graph/__init__.py +0 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/models/__init__.py +0 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/models/deployment.py +0 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/models/documentation.py +0 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/models/elements.py +0 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/models/enums.py +0 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/models/workspace.py +0 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/parser/__init__.py +0 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/parser/docs.py +0 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/parser/expressions.py +0 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/parser/implied.py +0 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/parser/sourcemap.py +0 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/py.typed +0 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/templates/deployment.dsl +0 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/templates/full-c4.dsl +0 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/templates/minimal.dsl +0 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/templates/system-context.dsl +0 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/templates.py +0 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/webapp/__init__.py +0 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/webapp/assistant.py +0 -0
- {c4studio-0.3.0 → c4studio-0.5.0}/src/c4studio/webapp/loader.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: c4studio
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: Parse Structurizr DSL/JSON and generate C4 diagrams in Mermaid, with a CLI and a React web app
|
|
5
5
|
Keywords: structurizr,c4,architecture,diagrams,dsl
|
|
6
6
|
Author: Geoffrey Koh
|
|
@@ -21,7 +21,11 @@ Requires-Dist: pytest>=8.0 ; extra == 'dev'
|
|
|
21
21
|
Requires-Dist: pytest-cov>=5.0 ; extra == 'dev'
|
|
22
22
|
Requires-Dist: anthropic>=1.0 ; extra == 'dev'
|
|
23
23
|
Requires-Python: >=3.13
|
|
24
|
+
Project-URL: Homepage, https://geoffkoh.github.io/c4studio/
|
|
24
25
|
Project-URL: Repository, https://github.com/geoffkoh/c4studio
|
|
26
|
+
Project-URL: Documentation, https://geoffkoh.github.io/c4studio/getting-started.html
|
|
27
|
+
Project-URL: Issues, https://github.com/geoffkoh/c4studio/issues
|
|
28
|
+
Project-URL: Migration guide, https://geoffkoh.github.io/c4studio/migration.html
|
|
25
29
|
Provides-Extra: assistant
|
|
26
30
|
Provides-Extra: dev
|
|
27
31
|
Description-Content-Type: text/markdown
|
|
@@ -32,6 +36,11 @@ Python implementation of [Structurizr](https://structurizr.com/) for architectur
|
|
|
32
36
|
modeling and C4 diagram generation — with a local-first **Studio** for writing
|
|
33
37
|
the DSL and watching the diagram follow.
|
|
34
38
|
|
|
39
|
+
**Documentation: [geoffkoh.github.io/c4studio](https://geoffkoh.github.io/c4studio/)**
|
|
40
|
+
— guides, the DSL reference, c4studio's extensions to the DSL, and a
|
|
41
|
+
[live example](https://geoffkoh.github.io/c4studio/example/index.html)
|
|
42
|
+
published from the model of c4studio itself.
|
|
43
|
+
|
|
35
44
|
## Install
|
|
36
45
|
Published on PyPI as **`c4studio`**; the import package is `c4studio`
|
|
37
46
|
and the command is `c4`:
|
|
@@ -57,7 +66,11 @@ Requires Python 3.13+ (uv/uvx can provision it automatically).
|
|
|
57
66
|
- ✅ Mermaid diagram generation — C4 syntax or `flowchart`/`subgraph`
|
|
58
67
|
- ✅ Headless SVG rendering for CI and docs-as-code
|
|
59
68
|
- ✅ Comprehensive type hints
|
|
60
|
-
- ✅
|
|
69
|
+
- ✅ **Perspectives** — annotate elements and relationships with security,
|
|
70
|
+
ownership or anything else, then show one over the diagram
|
|
71
|
+
- ✅ **`c4 lint`** — model standards in CI: orphans, missing descriptions,
|
|
72
|
+
duplicate relationships, styles that match nothing
|
|
73
|
+
- ✅ Custom properties on all elements
|
|
61
74
|
- ✅ Deployment infrastructure modeling
|
|
62
75
|
- ✅ Style and configuration management
|
|
63
76
|
- ⚙️ Optional AI assistant — off by default, and the only feature that
|
|
@@ -90,8 +103,11 @@ uv run c4 webapp samples/ --viewer # read-only, for a kiosk or an embed
|
|
|
90
103
|
|
|
91
104
|
### Editing
|
|
92
105
|
|
|
93
|
-
The
|
|
94
|
-
the diagram
|
|
106
|
+
The source editor is a [CodeMirror 6](https://codemirror.net/) panel that
|
|
107
|
+
opens beside the diagram — from the **Source** button at the right of the
|
|
108
|
+
top bar, the `e` key, the rail on the diagram's right edge, or *Open in
|
|
109
|
+
Source* on any element. The diagram stays put while it opens, and a ● on
|
|
110
|
+
the button marks unsaved work behind a closed editor.
|
|
95
111
|
|
|
96
112
|
- **Syntax highlighting and autocomplete** for DSL keywords, your own element
|
|
97
113
|
identifiers, and view keys — drawn from the loaded workspace, so it knows
|
|
@@ -127,11 +143,12 @@ independent of any curated view — at a selectable abstraction level
|
|
|
127
143
|
(systems / containers / components), with search across every element
|
|
128
144
|
(press `/`), and a details panel showing an element's metadata,
|
|
129
145
|
relationships, the views it appears in (click to jump) and a
|
|
130
|
-
show-definition link
|
|
146
|
+
show-definition link that opens the source editor.
|
|
131
147
|
|
|
132
148
|
The built SPA ships inside the package (`c4studio/webapp/static/`),
|
|
133
149
|
so end users need no Node toolchain. To rebuild the frontend after
|
|
134
|
-
changes (requires Node
|
|
150
|
+
changes (requires Node 20.19+ or 22.12+, what Vite asks for — distinct
|
|
151
|
+
from the Node 18+ that `c4 render` needs at runtime, below):
|
|
135
152
|
|
|
136
153
|
The frontend is an npm workspace: `packages/diagram-core` holds the
|
|
137
154
|
diagram layer (layout, node/edge components, image export) and
|
|
@@ -274,11 +291,229 @@ uv run c4 generate architecture.dsl -f flowchart # flowchart
|
|
|
274
291
|
uv run c4 generate architecture.dsl -f flowchart -o out # one .mmd per view
|
|
275
292
|
```
|
|
276
293
|
|
|
294
|
+
## Perspectives
|
|
295
|
+
A perspective is a named annotation you hang on elements and
|
|
296
|
+
relationships — security, ownership, cost, anything — and then **show over
|
|
297
|
+
the diagram**. What carries it keeps its place and gets a badge with its
|
|
298
|
+
value; everything else fades. The legend follows, listing the values
|
|
299
|
+
rather than the element styles the diagram is no longer painted with.
|
|
300
|
+
|
|
301
|
+
```
|
|
302
|
+
api = container "Payments API" "Authorises and captures." "Python, FastAPI" {
|
|
303
|
+
perspectives {
|
|
304
|
+
"security" "mTLS to the ledger, PCI DSS scope." "High"
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+

|
|
312
|
+
|
|
313
|
+
Colour comes from ordinary styles, matched on the perspective and
|
|
314
|
+
optionally on its value:
|
|
315
|
+
|
|
316
|
+
```
|
|
317
|
+
element "Perspective:security[value==High]" {
|
|
318
|
+
background #2e7d32
|
|
319
|
+
color #ffffff
|
|
320
|
+
}
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
The same overlay is available everywhere the diagram is:
|
|
324
|
+
|
|
325
|
+
```bash
|
|
326
|
+
uv run c4 render architecture.dsl --perspective security -o diagrams/
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
and in the VS Code preview through **C4Studio: Show Perspective…**. A
|
|
330
|
+
perspective carrying a `url` instead of a value has that value **read
|
|
331
|
+
live** — off by default, because the addresses come from the workspace
|
|
332
|
+
file; `c4 webapp --dynamic-perspectives` turns it on.
|
|
333
|
+
|
|
334
|
+
## Publish a site
|
|
335
|
+
Turn the model into something people read without installing anything:
|
|
336
|
+
|
|
337
|
+
```bash
|
|
338
|
+
uv run c4 publish architecture.dsl -o site/
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
Every view becomes its own page — not one page with a switcher, so a link
|
|
342
|
+
to a diagram survives being pasted into a ticket — with the `!docs` prose
|
|
343
|
+
and the ADRs beside them and navigation between. The result is
|
|
344
|
+
**self-contained**: diagrams are inlined SVG and theme icons are embedded
|
|
345
|
+
as `data:` URIs, so it works from a `file://` path, on an air-gapped
|
|
346
|
+
machine, or on any static host.
|
|
347
|
+
|
|
348
|
+
Published diagrams follow the layout you arranged in the Studio
|
|
349
|
+
(`--no-layout` for a fresh one), and `--perspective security` draws the
|
|
350
|
+
whole site through one perspective.
|
|
351
|
+
|
|
352
|
+
To publish on every merge, add the site to a Pages workflow (the
|
|
353
|
+
[complete workflow](https://geoffkoh.github.io/c4studio/ci.html#publish-the-model-to-github-pages),
|
|
354
|
+
with its permissions, is on the site):
|
|
355
|
+
|
|
356
|
+
```yaml
|
|
357
|
+
- uses: actions/checkout@v7
|
|
358
|
+
- uses: actions/setup-node@v7 # c4 publish draws SVG with Node
|
|
359
|
+
with:
|
|
360
|
+
node-version: 20
|
|
361
|
+
- uses: actions/setup-python@v7 # runners default to an older Python
|
|
362
|
+
with:
|
|
363
|
+
python-version: "3.13"
|
|
364
|
+
- run: pip install c4studio
|
|
365
|
+
- run: c4 publish architecture.dsl -o site/
|
|
366
|
+
- uses: actions/upload-pages-artifact@v5
|
|
367
|
+
with:
|
|
368
|
+
path: site/
|
|
369
|
+
- uses: actions/deploy-pages@v5
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
## What changed (`c4 diff`)
|
|
373
|
+
A pull request that changes the architecture should say what it changed:
|
|
374
|
+
|
|
375
|
+
```bash
|
|
376
|
+
uv run c4 diff architecture.dsl # working tree vs HEAD
|
|
377
|
+
uv run c4 diff architecture.dsl --from main --to HEAD --json
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
Elements and relationships added, removed and changed — and **the views a
|
|
381
|
+
reviewer has to look at again**. A comment-only edit produces nothing,
|
|
382
|
+
which is the signal worth having.
|
|
383
|
+
|
|
384
|
+
Renaming an element that has an alias is reported as a change. Renaming
|
|
385
|
+
one *without* an alias reads as a removal and an addition, because its id
|
|
386
|
+
comes from its name and nothing ties the two together; when a removal and
|
|
387
|
+
an addition share a name, the pair is flagged as a **possible** rename
|
|
388
|
+
rather than assumed. A diff that invents a rename hides a deletion.
|
|
389
|
+
|
|
390
|
+
### On every pull request
|
|
391
|
+
|
|
392
|
+
`c4 diff` needs no Node, so a short workflow can post the answer on each
|
|
393
|
+
pull request that touches the model, updating its own comment on every
|
|
394
|
+
push rather than adding one per push:
|
|
395
|
+
|
|
396
|
+
```yaml
|
|
397
|
+
name: Architecture diff
|
|
398
|
+
|
|
399
|
+
on:
|
|
400
|
+
pull_request:
|
|
401
|
+
paths:
|
|
402
|
+
- "architecture/**"
|
|
403
|
+
|
|
404
|
+
permissions:
|
|
405
|
+
contents: read
|
|
406
|
+
pull-requests: write # to comment
|
|
407
|
+
|
|
408
|
+
jobs:
|
|
409
|
+
diff:
|
|
410
|
+
runs-on: ubuntu-latest
|
|
411
|
+
steps:
|
|
412
|
+
- uses: actions/checkout@v7
|
|
413
|
+
with:
|
|
414
|
+
fetch-depth: 0 # c4 diff reads the base revision from git history
|
|
415
|
+
|
|
416
|
+
- uses: actions/setup-python@v7 # runners default to an older Python
|
|
417
|
+
with:
|
|
418
|
+
python-version: "3.13"
|
|
419
|
+
|
|
420
|
+
- run: pip install c4studio # no Node needed: diff compares models
|
|
421
|
+
|
|
422
|
+
- name: Diff the model against the target branch
|
|
423
|
+
env:
|
|
424
|
+
BASE: origin/${{ github.base_ref }}
|
|
425
|
+
run: |
|
|
426
|
+
{
|
|
427
|
+
echo "### Architecture changes"
|
|
428
|
+
echo
|
|
429
|
+
echo '```text'
|
|
430
|
+
# A failure is shown rather than failing the job: a workspace
|
|
431
|
+
# the base branch does not have yet cannot be compared.
|
|
432
|
+
c4 diff architecture/workspace.dsl --from "$BASE" --to HEAD 2>&1 \
|
|
433
|
+
|| echo "c4 diff could not compare these revisions (exit $?)"
|
|
434
|
+
echo '```'
|
|
435
|
+
} > architecture-diff.md
|
|
436
|
+
# The job summary works where a comment cannot: a pull request
|
|
437
|
+
# from a fork gets a read-only token.
|
|
438
|
+
cat architecture-diff.md >> "$GITHUB_STEP_SUMMARY"
|
|
439
|
+
|
|
440
|
+
- name: Comment on the pull request
|
|
441
|
+
env:
|
|
442
|
+
GH_TOKEN: ${{ github.token }}
|
|
443
|
+
PR: ${{ github.event.pull_request.number }}
|
|
444
|
+
run: gh pr comment "$PR" --body-file architecture-diff.md --edit-last --create-if-none
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
It reads the base branch from git history, hence `fetch-depth: 0`. A
|
|
448
|
+
workspace the base branch does not have yet cannot be compared, and the
|
|
449
|
+
comment says so instead of failing the job. `--edit-last` edits the
|
|
450
|
+
latest comment made with the workflow's token, so keep this the only
|
|
451
|
+
step that comments with it — or give it a token of its own. Diagrams are
|
|
452
|
+
the action's job (`mode: comment`); this posts the model change, which is
|
|
453
|
+
what a reviewer needs before looking at any of them.
|
|
454
|
+
|
|
455
|
+
## Impact analysis
|
|
456
|
+
What else is involved when one element changes — asked of the model
|
|
457
|
+
rather than of whoever remembers:
|
|
458
|
+
|
|
459
|
+
```bash
|
|
460
|
+
uv run c4 impact architecture.dsl paymentsApi
|
|
461
|
+
uv run c4 impact architecture.dsl paymentsApi --json --depth 2
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
Dependents (what reaches it, and so may break when it changes),
|
|
465
|
+
dependencies (what it reaches, and so may break it), each with how many
|
|
466
|
+
relationships away it is, plus **the views that draw it** — so a change
|
|
467
|
+
advisory board knows which diagrams to open.
|
|
468
|
+
|
|
469
|
+
Containment counts in both directions: a relationship declared against a
|
|
470
|
+
container is one its software system takes part in, which is the same
|
|
471
|
+
rule the views apply when they lift an edge to the nearest visible
|
|
472
|
+
ancestor. An answer that ignored the hierarchy would disagree with the
|
|
473
|
+
diagrams it is about.
|
|
474
|
+
|
|
475
|
+
The same answer is on the Diagrams page: select an element, open its
|
|
476
|
+
details (`i`), and choose **Show impact**. The view repaints — the element
|
|
477
|
+
and whatever contains it marked *Changed*, what depends on it and what it
|
|
478
|
+
depends on in their own colours, the rest faded — and the card gives the
|
|
479
|
+
model-wide counts and how many views draw it. It stays on as you move
|
|
480
|
+
between views; the chip in the toolbar clears it, and choosing a
|
|
481
|
+
perspective replaces it.
|
|
482
|
+
|
|
483
|
+
## Model standards (`c4 lint`)
|
|
484
|
+
Where `c4 check` asks whether a file parses, `c4 lint` asks whether it is
|
|
485
|
+
a good model — the review comments someone would otherwise have to make
|
|
486
|
+
every time:
|
|
487
|
+
|
|
488
|
+
```bash
|
|
489
|
+
uv run c4 lint architecture.dsl
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
Orphaned elements, missing descriptions and technologies, relationships
|
|
493
|
+
declared twice, and styles whose tag nothing carries (invisible
|
|
494
|
+
otherwise, because the legend only lists styles in use). Every finding is
|
|
495
|
+
a warning — a model that breaks a house style still parses and renders —
|
|
496
|
+
so the **exit code** is what gates CI: 1 on any finding, `--exit-zero` to
|
|
497
|
+
report without failing on a model nobody has linted before.
|
|
498
|
+
|
|
499
|
+
Configure it in `c4studio.lint.json` beside the workspace:
|
|
500
|
+
|
|
501
|
+
```json
|
|
502
|
+
{"ignore": ["missing-technology"], "naming": {"container": "^[A-Z]"}}
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
`--json` emits the same shape editors already read, so findings land in
|
|
506
|
+
the Studio's problems list and the VS Code Problems panel.
|
|
507
|
+
|
|
277
508
|
## Headless SVG Rendering
|
|
278
509
|
`c4 render` draws diagrams as standalone SVG with no browser
|
|
279
510
|
and no server — for CI, docs-as-code pipelines and static sites. Layout is
|
|
280
511
|
the same code the web app runs, so positions match what you see in the
|
|
281
|
-
viewer, including any layout you have saved for a view.
|
|
512
|
+
viewer, including any layout you have saved for a view. The Studio is the
|
|
513
|
+
reference for everything else too: box heights, shapes, lines, labels and
|
|
514
|
+
the legend are drawn as the canvas draws them, and a browser test holds
|
|
515
|
+
the two together on the samples built for it (`shapes_gallery.dsl`,
|
|
516
|
+
`line_styles.dsl`, `icons_and_groups.dsl`, `deployment_flow.dsl`).
|
|
282
517
|
|
|
283
518
|
```bash
|
|
284
519
|
uv run c4 render architecture.dsl -o diagrams/ # one .svg per view
|
|
@@ -323,7 +558,7 @@ jobs:
|
|
|
323
558
|
runs-on: ubuntu-latest
|
|
324
559
|
steps:
|
|
325
560
|
- uses: actions/checkout@v4
|
|
326
|
-
- uses: geoffkoh/c4studio@v0.
|
|
561
|
+
- uses: geoffkoh/c4studio@v0.5.0
|
|
327
562
|
id: diagrams
|
|
328
563
|
with:
|
|
329
564
|
workspace: docs/architecture.dsl
|
|
@@ -349,11 +584,10 @@ diff when the model has not changed.
|
|
|
349
584
|
|
|
350
585
|
## VS Code Extension
|
|
351
586
|
[`editors/vscode/`](./editors/vscode/) ships a VS Code extension with
|
|
352
|
-
Structurizr DSL syntax highlighting
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
thing the preview must not do. Build and install it locally:
|
|
587
|
+
Structurizr DSL syntax highlighting, problems as you type, and a preview
|
|
588
|
+
that draws one view as an SVG beside the editor (via `c4 render`, so no
|
|
589
|
+
server and no port), redrawn as you save. *Open in Studio (browser)*
|
|
590
|
+
starts the full Studio when you want it. Build and install it locally:
|
|
357
591
|
|
|
358
592
|
```bash
|
|
359
593
|
cd editors/vscode && npm install && npm run package
|
|
@@ -361,8 +595,8 @@ code --install-extension c4studio-vscode-*.vsix
|
|
|
361
595
|
```
|
|
362
596
|
|
|
363
597
|
## Documentation
|
|
598
|
+
- **[DSL Reference](./docs/dsl-reference.md)** - **How to write DSL for c4studio**: every construct, the `c4studio.*` extensions, and what is silently ignored. Examples are parsed by the test suite
|
|
364
599
|
- **[DSL Language Support](./docs/dsl-support.md)** - Every keyword in the Structurizr DSL and whether c4studio supports it
|
|
365
|
-
- **[Data Models Reference](./docs/data-models.md)** - Complete guide to all Structurizr models and their fields
|
|
366
600
|
- **[Getting Started](./docs/README.md)** - Workflow and common patterns
|
|
367
601
|
- **[Studio Editor Plan](./docs/studio-editor-plan.md)** - How the editor was designed and built, and the decisions behind it
|
|
368
602
|
- **[Migration Guide](./docs/MIGRATION.md)** - Breaking changes, including the 0.3.0 Studio-by-default flip
|
|
@@ -4,6 +4,11 @@ Python implementation of [Structurizr](https://structurizr.com/) for architectur
|
|
|
4
4
|
modeling and C4 diagram generation — with a local-first **Studio** for writing
|
|
5
5
|
the DSL and watching the diagram follow.
|
|
6
6
|
|
|
7
|
+
**Documentation: [geoffkoh.github.io/c4studio](https://geoffkoh.github.io/c4studio/)**
|
|
8
|
+
— guides, the DSL reference, c4studio's extensions to the DSL, and a
|
|
9
|
+
[live example](https://geoffkoh.github.io/c4studio/example/index.html)
|
|
10
|
+
published from the model of c4studio itself.
|
|
11
|
+
|
|
7
12
|
## Install
|
|
8
13
|
Published on PyPI as **`c4studio`**; the import package is `c4studio`
|
|
9
14
|
and the command is `c4`:
|
|
@@ -29,7 +34,11 @@ Requires Python 3.13+ (uv/uvx can provision it automatically).
|
|
|
29
34
|
- ✅ Mermaid diagram generation — C4 syntax or `flowchart`/`subgraph`
|
|
30
35
|
- ✅ Headless SVG rendering for CI and docs-as-code
|
|
31
36
|
- ✅ Comprehensive type hints
|
|
32
|
-
- ✅
|
|
37
|
+
- ✅ **Perspectives** — annotate elements and relationships with security,
|
|
38
|
+
ownership or anything else, then show one over the diagram
|
|
39
|
+
- ✅ **`c4 lint`** — model standards in CI: orphans, missing descriptions,
|
|
40
|
+
duplicate relationships, styles that match nothing
|
|
41
|
+
- ✅ Custom properties on all elements
|
|
33
42
|
- ✅ Deployment infrastructure modeling
|
|
34
43
|
- ✅ Style and configuration management
|
|
35
44
|
- ⚙️ Optional AI assistant — off by default, and the only feature that
|
|
@@ -62,8 +71,11 @@ uv run c4 webapp samples/ --viewer # read-only, for a kiosk or an embed
|
|
|
62
71
|
|
|
63
72
|
### Editing
|
|
64
73
|
|
|
65
|
-
The
|
|
66
|
-
the diagram
|
|
74
|
+
The source editor is a [CodeMirror 6](https://codemirror.net/) panel that
|
|
75
|
+
opens beside the diagram — from the **Source** button at the right of the
|
|
76
|
+
top bar, the `e` key, the rail on the diagram's right edge, or *Open in
|
|
77
|
+
Source* on any element. The diagram stays put while it opens, and a ● on
|
|
78
|
+
the button marks unsaved work behind a closed editor.
|
|
67
79
|
|
|
68
80
|
- **Syntax highlighting and autocomplete** for DSL keywords, your own element
|
|
69
81
|
identifiers, and view keys — drawn from the loaded workspace, so it knows
|
|
@@ -99,11 +111,12 @@ independent of any curated view — at a selectable abstraction level
|
|
|
99
111
|
(systems / containers / components), with search across every element
|
|
100
112
|
(press `/`), and a details panel showing an element's metadata,
|
|
101
113
|
relationships, the views it appears in (click to jump) and a
|
|
102
|
-
show-definition link
|
|
114
|
+
show-definition link that opens the source editor.
|
|
103
115
|
|
|
104
116
|
The built SPA ships inside the package (`c4studio/webapp/static/`),
|
|
105
117
|
so end users need no Node toolchain. To rebuild the frontend after
|
|
106
|
-
changes (requires Node
|
|
118
|
+
changes (requires Node 20.19+ or 22.12+, what Vite asks for — distinct
|
|
119
|
+
from the Node 18+ that `c4 render` needs at runtime, below):
|
|
107
120
|
|
|
108
121
|
The frontend is an npm workspace: `packages/diagram-core` holds the
|
|
109
122
|
diagram layer (layout, node/edge components, image export) and
|
|
@@ -246,11 +259,229 @@ uv run c4 generate architecture.dsl -f flowchart # flowchart
|
|
|
246
259
|
uv run c4 generate architecture.dsl -f flowchart -o out # one .mmd per view
|
|
247
260
|
```
|
|
248
261
|
|
|
262
|
+
## Perspectives
|
|
263
|
+
A perspective is a named annotation you hang on elements and
|
|
264
|
+
relationships — security, ownership, cost, anything — and then **show over
|
|
265
|
+
the diagram**. What carries it keeps its place and gets a badge with its
|
|
266
|
+
value; everything else fades. The legend follows, listing the values
|
|
267
|
+
rather than the element styles the diagram is no longer painted with.
|
|
268
|
+
|
|
269
|
+
```
|
|
270
|
+
api = container "Payments API" "Authorises and captures." "Python, FastAPI" {
|
|
271
|
+
perspectives {
|
|
272
|
+
"security" "mTLS to the ledger, PCI DSS scope." "High"
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+

|
|
280
|
+
|
|
281
|
+
Colour comes from ordinary styles, matched on the perspective and
|
|
282
|
+
optionally on its value:
|
|
283
|
+
|
|
284
|
+
```
|
|
285
|
+
element "Perspective:security[value==High]" {
|
|
286
|
+
background #2e7d32
|
|
287
|
+
color #ffffff
|
|
288
|
+
}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
The same overlay is available everywhere the diagram is:
|
|
292
|
+
|
|
293
|
+
```bash
|
|
294
|
+
uv run c4 render architecture.dsl --perspective security -o diagrams/
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
and in the VS Code preview through **C4Studio: Show Perspective…**. A
|
|
298
|
+
perspective carrying a `url` instead of a value has that value **read
|
|
299
|
+
live** — off by default, because the addresses come from the workspace
|
|
300
|
+
file; `c4 webapp --dynamic-perspectives` turns it on.
|
|
301
|
+
|
|
302
|
+
## Publish a site
|
|
303
|
+
Turn the model into something people read without installing anything:
|
|
304
|
+
|
|
305
|
+
```bash
|
|
306
|
+
uv run c4 publish architecture.dsl -o site/
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
Every view becomes its own page — not one page with a switcher, so a link
|
|
310
|
+
to a diagram survives being pasted into a ticket — with the `!docs` prose
|
|
311
|
+
and the ADRs beside them and navigation between. The result is
|
|
312
|
+
**self-contained**: diagrams are inlined SVG and theme icons are embedded
|
|
313
|
+
as `data:` URIs, so it works from a `file://` path, on an air-gapped
|
|
314
|
+
machine, or on any static host.
|
|
315
|
+
|
|
316
|
+
Published diagrams follow the layout you arranged in the Studio
|
|
317
|
+
(`--no-layout` for a fresh one), and `--perspective security` draws the
|
|
318
|
+
whole site through one perspective.
|
|
319
|
+
|
|
320
|
+
To publish on every merge, add the site to a Pages workflow (the
|
|
321
|
+
[complete workflow](https://geoffkoh.github.io/c4studio/ci.html#publish-the-model-to-github-pages),
|
|
322
|
+
with its permissions, is on the site):
|
|
323
|
+
|
|
324
|
+
```yaml
|
|
325
|
+
- uses: actions/checkout@v7
|
|
326
|
+
- uses: actions/setup-node@v7 # c4 publish draws SVG with Node
|
|
327
|
+
with:
|
|
328
|
+
node-version: 20
|
|
329
|
+
- uses: actions/setup-python@v7 # runners default to an older Python
|
|
330
|
+
with:
|
|
331
|
+
python-version: "3.13"
|
|
332
|
+
- run: pip install c4studio
|
|
333
|
+
- run: c4 publish architecture.dsl -o site/
|
|
334
|
+
- uses: actions/upload-pages-artifact@v5
|
|
335
|
+
with:
|
|
336
|
+
path: site/
|
|
337
|
+
- uses: actions/deploy-pages@v5
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
## What changed (`c4 diff`)
|
|
341
|
+
A pull request that changes the architecture should say what it changed:
|
|
342
|
+
|
|
343
|
+
```bash
|
|
344
|
+
uv run c4 diff architecture.dsl # working tree vs HEAD
|
|
345
|
+
uv run c4 diff architecture.dsl --from main --to HEAD --json
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
Elements and relationships added, removed and changed — and **the views a
|
|
349
|
+
reviewer has to look at again**. A comment-only edit produces nothing,
|
|
350
|
+
which is the signal worth having.
|
|
351
|
+
|
|
352
|
+
Renaming an element that has an alias is reported as a change. Renaming
|
|
353
|
+
one *without* an alias reads as a removal and an addition, because its id
|
|
354
|
+
comes from its name and nothing ties the two together; when a removal and
|
|
355
|
+
an addition share a name, the pair is flagged as a **possible** rename
|
|
356
|
+
rather than assumed. A diff that invents a rename hides a deletion.
|
|
357
|
+
|
|
358
|
+
### On every pull request
|
|
359
|
+
|
|
360
|
+
`c4 diff` needs no Node, so a short workflow can post the answer on each
|
|
361
|
+
pull request that touches the model, updating its own comment on every
|
|
362
|
+
push rather than adding one per push:
|
|
363
|
+
|
|
364
|
+
```yaml
|
|
365
|
+
name: Architecture diff
|
|
366
|
+
|
|
367
|
+
on:
|
|
368
|
+
pull_request:
|
|
369
|
+
paths:
|
|
370
|
+
- "architecture/**"
|
|
371
|
+
|
|
372
|
+
permissions:
|
|
373
|
+
contents: read
|
|
374
|
+
pull-requests: write # to comment
|
|
375
|
+
|
|
376
|
+
jobs:
|
|
377
|
+
diff:
|
|
378
|
+
runs-on: ubuntu-latest
|
|
379
|
+
steps:
|
|
380
|
+
- uses: actions/checkout@v7
|
|
381
|
+
with:
|
|
382
|
+
fetch-depth: 0 # c4 diff reads the base revision from git history
|
|
383
|
+
|
|
384
|
+
- uses: actions/setup-python@v7 # runners default to an older Python
|
|
385
|
+
with:
|
|
386
|
+
python-version: "3.13"
|
|
387
|
+
|
|
388
|
+
- run: pip install c4studio # no Node needed: diff compares models
|
|
389
|
+
|
|
390
|
+
- name: Diff the model against the target branch
|
|
391
|
+
env:
|
|
392
|
+
BASE: origin/${{ github.base_ref }}
|
|
393
|
+
run: |
|
|
394
|
+
{
|
|
395
|
+
echo "### Architecture changes"
|
|
396
|
+
echo
|
|
397
|
+
echo '```text'
|
|
398
|
+
# A failure is shown rather than failing the job: a workspace
|
|
399
|
+
# the base branch does not have yet cannot be compared.
|
|
400
|
+
c4 diff architecture/workspace.dsl --from "$BASE" --to HEAD 2>&1 \
|
|
401
|
+
|| echo "c4 diff could not compare these revisions (exit $?)"
|
|
402
|
+
echo '```'
|
|
403
|
+
} > architecture-diff.md
|
|
404
|
+
# The job summary works where a comment cannot: a pull request
|
|
405
|
+
# from a fork gets a read-only token.
|
|
406
|
+
cat architecture-diff.md >> "$GITHUB_STEP_SUMMARY"
|
|
407
|
+
|
|
408
|
+
- name: Comment on the pull request
|
|
409
|
+
env:
|
|
410
|
+
GH_TOKEN: ${{ github.token }}
|
|
411
|
+
PR: ${{ github.event.pull_request.number }}
|
|
412
|
+
run: gh pr comment "$PR" --body-file architecture-diff.md --edit-last --create-if-none
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
It reads the base branch from git history, hence `fetch-depth: 0`. A
|
|
416
|
+
workspace the base branch does not have yet cannot be compared, and the
|
|
417
|
+
comment says so instead of failing the job. `--edit-last` edits the
|
|
418
|
+
latest comment made with the workflow's token, so keep this the only
|
|
419
|
+
step that comments with it — or give it a token of its own. Diagrams are
|
|
420
|
+
the action's job (`mode: comment`); this posts the model change, which is
|
|
421
|
+
what a reviewer needs before looking at any of them.
|
|
422
|
+
|
|
423
|
+
## Impact analysis
|
|
424
|
+
What else is involved when one element changes — asked of the model
|
|
425
|
+
rather than of whoever remembers:
|
|
426
|
+
|
|
427
|
+
```bash
|
|
428
|
+
uv run c4 impact architecture.dsl paymentsApi
|
|
429
|
+
uv run c4 impact architecture.dsl paymentsApi --json --depth 2
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
Dependents (what reaches it, and so may break when it changes),
|
|
433
|
+
dependencies (what it reaches, and so may break it), each with how many
|
|
434
|
+
relationships away it is, plus **the views that draw it** — so a change
|
|
435
|
+
advisory board knows which diagrams to open.
|
|
436
|
+
|
|
437
|
+
Containment counts in both directions: a relationship declared against a
|
|
438
|
+
container is one its software system takes part in, which is the same
|
|
439
|
+
rule the views apply when they lift an edge to the nearest visible
|
|
440
|
+
ancestor. An answer that ignored the hierarchy would disagree with the
|
|
441
|
+
diagrams it is about.
|
|
442
|
+
|
|
443
|
+
The same answer is on the Diagrams page: select an element, open its
|
|
444
|
+
details (`i`), and choose **Show impact**. The view repaints — the element
|
|
445
|
+
and whatever contains it marked *Changed*, what depends on it and what it
|
|
446
|
+
depends on in their own colours, the rest faded — and the card gives the
|
|
447
|
+
model-wide counts and how many views draw it. It stays on as you move
|
|
448
|
+
between views; the chip in the toolbar clears it, and choosing a
|
|
449
|
+
perspective replaces it.
|
|
450
|
+
|
|
451
|
+
## Model standards (`c4 lint`)
|
|
452
|
+
Where `c4 check` asks whether a file parses, `c4 lint` asks whether it is
|
|
453
|
+
a good model — the review comments someone would otherwise have to make
|
|
454
|
+
every time:
|
|
455
|
+
|
|
456
|
+
```bash
|
|
457
|
+
uv run c4 lint architecture.dsl
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
Orphaned elements, missing descriptions and technologies, relationships
|
|
461
|
+
declared twice, and styles whose tag nothing carries (invisible
|
|
462
|
+
otherwise, because the legend only lists styles in use). Every finding is
|
|
463
|
+
a warning — a model that breaks a house style still parses and renders —
|
|
464
|
+
so the **exit code** is what gates CI: 1 on any finding, `--exit-zero` to
|
|
465
|
+
report without failing on a model nobody has linted before.
|
|
466
|
+
|
|
467
|
+
Configure it in `c4studio.lint.json` beside the workspace:
|
|
468
|
+
|
|
469
|
+
```json
|
|
470
|
+
{"ignore": ["missing-technology"], "naming": {"container": "^[A-Z]"}}
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
`--json` emits the same shape editors already read, so findings land in
|
|
474
|
+
the Studio's problems list and the VS Code Problems panel.
|
|
475
|
+
|
|
249
476
|
## Headless SVG Rendering
|
|
250
477
|
`c4 render` draws diagrams as standalone SVG with no browser
|
|
251
478
|
and no server — for CI, docs-as-code pipelines and static sites. Layout is
|
|
252
479
|
the same code the web app runs, so positions match what you see in the
|
|
253
|
-
viewer, including any layout you have saved for a view.
|
|
480
|
+
viewer, including any layout you have saved for a view. The Studio is the
|
|
481
|
+
reference for everything else too: box heights, shapes, lines, labels and
|
|
482
|
+
the legend are drawn as the canvas draws them, and a browser test holds
|
|
483
|
+
the two together on the samples built for it (`shapes_gallery.dsl`,
|
|
484
|
+
`line_styles.dsl`, `icons_and_groups.dsl`, `deployment_flow.dsl`).
|
|
254
485
|
|
|
255
486
|
```bash
|
|
256
487
|
uv run c4 render architecture.dsl -o diagrams/ # one .svg per view
|
|
@@ -295,7 +526,7 @@ jobs:
|
|
|
295
526
|
runs-on: ubuntu-latest
|
|
296
527
|
steps:
|
|
297
528
|
- uses: actions/checkout@v4
|
|
298
|
-
- uses: geoffkoh/c4studio@v0.
|
|
529
|
+
- uses: geoffkoh/c4studio@v0.5.0
|
|
299
530
|
id: diagrams
|
|
300
531
|
with:
|
|
301
532
|
workspace: docs/architecture.dsl
|
|
@@ -321,11 +552,10 @@ diff when the model has not changed.
|
|
|
321
552
|
|
|
322
553
|
## VS Code Extension
|
|
323
554
|
[`editors/vscode/`](./editors/vscode/) ships a VS Code extension with
|
|
324
|
-
Structurizr DSL syntax highlighting
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
thing the preview must not do. Build and install it locally:
|
|
555
|
+
Structurizr DSL syntax highlighting, problems as you type, and a preview
|
|
556
|
+
that draws one view as an SVG beside the editor (via `c4 render`, so no
|
|
557
|
+
server and no port), redrawn as you save. *Open in Studio (browser)*
|
|
558
|
+
starts the full Studio when you want it. Build and install it locally:
|
|
329
559
|
|
|
330
560
|
```bash
|
|
331
561
|
cd editors/vscode && npm install && npm run package
|
|
@@ -333,8 +563,8 @@ code --install-extension c4studio-vscode-*.vsix
|
|
|
333
563
|
```
|
|
334
564
|
|
|
335
565
|
## Documentation
|
|
566
|
+
- **[DSL Reference](./docs/dsl-reference.md)** - **How to write DSL for c4studio**: every construct, the `c4studio.*` extensions, and what is silently ignored. Examples are parsed by the test suite
|
|
336
567
|
- **[DSL Language Support](./docs/dsl-support.md)** - Every keyword in the Structurizr DSL and whether c4studio supports it
|
|
337
|
-
- **[Data Models Reference](./docs/data-models.md)** - Complete guide to all Structurizr models and their fields
|
|
338
568
|
- **[Getting Started](./docs/README.md)** - Workflow and common patterns
|
|
339
569
|
- **[Studio Editor Plan](./docs/studio-editor-plan.md)** - How the editor was designed and built, and the decisions behind it
|
|
340
570
|
- **[Migration Guide](./docs/MIGRATION.md)** - Breaking changes, including the 0.3.0 Studio-by-default flip
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
# project. C4 is the notation, not a vendor's product, so the name stays
|
|
5
5
|
# honest even if support broadens beyond Structurizr DSL.
|
|
6
6
|
name = "c4studio"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.5.0"
|
|
8
8
|
description = "Parse Structurizr DSL/JSON and generate C4 diagrams in Mermaid, with a CLI and a React web app"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -28,7 +28,11 @@ dependencies = [
|
|
|
28
28
|
]
|
|
29
29
|
|
|
30
30
|
[project.urls]
|
|
31
|
+
Homepage = "https://geoffkoh.github.io/c4studio/"
|
|
31
32
|
Repository = "https://github.com/geoffkoh/c4studio"
|
|
33
|
+
Documentation = "https://geoffkoh.github.io/c4studio/getting-started.html"
|
|
34
|
+
Issues = "https://github.com/geoffkoh/c4studio/issues"
|
|
35
|
+
"Migration guide" = "https://geoffkoh.github.io/c4studio/migration.html"
|
|
32
36
|
|
|
33
37
|
[project.optional-dependencies]
|
|
34
38
|
# The assistant is the one feature that leaves the machine, and the only
|