c4studio v0.5.0

Command line#

Everything c4studio does is available from the c4 command. Every command takes a .dsl or workspace .json file. The commands that report on a model exit non-zero on a problem, so any of them can gate a CI job.

c4 --help
c4 <command> --help
I want to…Command
Start a new workspacec4 new
Edit a model and see itc4 webapp
Know whether a file parsesc4 check
Hold a model to standardsc4 lint
See what a change did to the modelc4 diff
Know what a change to one element touchesc4 impact
Get SVG filesc4 render
Get a websitec4 publish
Get Mermaidc4 generate
Get Structurizr JSONc4 export
List views or perspectives, for scriptsc4 list-views, c4 list-perspectives

c4 render, c4 publish and the VS Code preview draw what the Studio draws: the same layout, box sizes, shapes, lines, labels and legend. Where the two ever differ, the Studio is right and the renderer is the bug.

Lint rules#

c4 lint asks whether a model is a good model, where c4 check only asks whether it parses. Every finding is a warning, because a model that breaks a house style still renders, so the exit code is what gates CI: 1 on any finding, or 0 with --exit-zero.

RuleWhat it reports
orphan-elementAn element with no relationships. A system whose containers have relationships is not an orphan, because a view lifts those relationships to it.
missing-descriptionAn element with no description.
missing-technologyA container or component with no technology. People and systems have none by design.
duplicate-relationshipThe same relationship declared twice.
unused-styleA style whose tag nothing carries. It is invisible otherwise, because the legend only lists the styles in use. Tags that come from a theme are not reported.
invalid-badge-colourA c4studio.badge value that is not a hex colour.
invalid-icon-tintA c4studio.iconTint value that is not true, false or a hex colour.
naming-conventionA name that does not match the pattern configured for its element type. Off until you configure a pattern.

Configure the rules in c4studio.lint.json beside the workspace, or pass --config:

{
  "ignore": ["missing-technology"],
  "naming": {"container": "^[A-Z]", "softwareSystem": "^[A-Z]"}
}

ignore skips rules and select runs only the rules listed. naming maps an element type to a regular expression its names must match. --json emits the same diagnostic shape the editors read, so findings land in the Studio's problems list and in the VS Code Problems panel.

Diffs between revisions#

c4 diff compares the model at two git revisions, and resolves !include fragments at the older revision too:

c4 diff architecture.dsl                          # working tree against HEAD
c4 diff architecture.dsl --from main --to HEAD    # two revisions
c4 diff architecture.dsl --from v1.0 --json       # for a script or PR comment

It reports elements and relationships added, removed and changed, and the views a reviewer has to look at again. A comment-only edit produces nothing. An element's identity comes from its DSL identifier, so renaming an element that has one is a change. Renaming an element without one reads as a removal plus an addition, and when the two share a name the pair is flagged as a possible rename rather than assumed: a diff that invents a rename can hide a deletion.

Environment#

VariableUsed byPurpose
C4STUDIO_NODErender, publishPath to a node binary when it is not on PATH, for example under nvm or conda.
ANTHROPIC_API_KEYwebapp --assistantThe key for the optional assistant. Read when it is used, never stored.

Reference#

Generated from the commands themselves, so it always matches the installed version.

c4 check#

c4 check [OPTIONS] INPUT_FILE

Report problems in INPUT_FILE without generating anything.

INPUT_FILE may be - to read DSL from stdin, which is how an editor checks a buffer that has not been saved. Pass --path with it so diagnostics name the real file and relative directives resolve.

Exits 1 when the file has errors (or, with --strict, warnings), so it can gate a CI job. Warnings cover DSL the parser understood but did not implement — those constructs are skipped, and this is where that becomes visible.

OptionWhat it does
--pathFile the source on stdin belongs to. Diagnostics are reported against it, and relative !include/!docs/!adrs targets resolve next to it.
--jsonEmit diagnostics as JSON, for editors and other tools.
--strictExit non-zero on warnings as well as errors.

c4 diff#

c4 diff [OPTIONS] INPUT_FILE

What changed in INPUT_FILE between two revisions.

Elements and relationships added, removed and changed, and the views a reviewer has to look at again. Compares the working tree against HEAD by default, which is the question you ask before opening a pull request.

A renamed element with no alias reads as a removal and an addition — its id comes from its name, and nothing ties the two together. Such a pair is flagged rather than guessed at: a diff that invents a rename hides a deletion.

OptionWhat it does
--fromRevision to compare from — a branch, a tag or a SHA. Default: HEAD.
--toRevision to compare to. Defaults to the working tree.
--jsonEmit the diff as JSON, for a PR comment or a script.

c4 export#

c4 export [OPTIONS] INPUT_FILE

Export INPUT_FILE (DSL or JSON) as Structurizr workspace JSON.

The output round-trips with structurizr.com, Structurizr Lite, and this package's own JSON parser.

OptionWhat it does
--output, -oOutput file (default: print to stdout).

c4 generate#

c4 generate [OPTIONS] INPUT_FILE

Generate diagrams from INPUT_FILE (DSL or JSON).

OptionWhat it does
--output, -oOutput directory (default: print to stdout).
--view, -vOnly generate for this view key.
--format, -fmermaid: Mermaid C4 syntax (C4Context/C4Container/C4Component). flowchart: Mermaid flowchart + subgraph — renders more reliably on GitHub and dense models, and covers dynamic, deployment and filtered views too. Default: mermaid.

c4 impact#

c4 impact [OPTIONS] INPUT_FILE IDENTIFIER

What else is involved when IDENTIFIER changes.

Answers the change-advisory question of the model rather than of whoever remembers: what depends on this element, what it depends on, and which diagrams to look at.

Containment counts in both directions — changing a software system changes what is inside it, and a relationship declared against a container is one its system takes part in, which is the same rule the views apply when they lift an edge to the nearest visible ancestor.

OptionWhat it does
--jsonEmit the answer as JSON, for scripts and tickets.
--depthStop after this many relationships (default: the whole graph).

c4 lint#

c4 lint [OPTIONS] INPUT_FILE

Check INPUT_FILE against the model standards.

Where check asks whether the file parses, this asks whether it is a good model: elements nothing relates to, missing descriptions and technologies, relationships declared twice, styles that match nothing, badge colours that are not hex.

Every finding is a warning — a model that breaks a house style still parses and still renders — so the exit code is what makes CI care: 1 when anything is found, unless --exit-zero.

Rules are configured in JSON, by default c4studio.lint.json beside INPUT_FILE::

{"ignore": ["missing-technology"], "naming": {"container": "^[A-Z]"}}

OptionWhat it does
--jsonEmit findings as JSON, for editors and other tools.
--configRule configuration. Defaults to c4studio.lint.json beside INPUT_FILE when that exists.
--ignoreRule code to skip. Repeatable; adds to any configured ignores.
--selectRun only these rule codes. Repeatable.
--exit-zeroReport findings but exit 0, for a first run on an existing model.

c4 list-perspectives#

c4 list-perspectives [OPTIONS] INPUT_FILE

List the perspective names used anywhere in INPUT_FILE.

The same set the Studio's perspective picker offers and that c4 render --perspective accepts, from the same function, so a caller cannot be offered a name the renderer would refuse. Its own command rather than a field on list-views --json: perspectives belong to the model, not to a view, and that JSON is an array whose shape other tools already read.

OptionWhat it does
--jsonEmit the names as a JSON array, for tools rather than people.

c4 list-views#

c4 list-views [OPTIONS] INPUT_FILE

List all views defined in INPUT_FILE.

--json emits the same index the web app serves from GET /api/views — the same function, so the two cannot drift — including which views are renderable and which one the DSL marks default. The VS Code extension reads it to populate its view picker; the table above it is for reading.

OptionWhat it does
--jsonEmit the view index as JSON, for tools rather than people.

c4 new#

c4 new [OPTIONS] [OUTPUT]

Write a starter workspace to OUTPUT (default: workspace.dsl).

OptionWhat it does
--templateWhich starter workspace to write. Default: minimal.
--nameWorkspace name. Defaults to the template's own.
--listList the available templates and exit.
--forceOverwrite OUTPUT if it already exists.

c4 publish#

c4 publish [OPTIONS] INPUT_FILE

Write INPUT_FILE as a self-contained HTML site.

Every view becomes a page, with the !docs prose and the ADRs beside them and navigation between. One page per view rather than one page with a switcher, so a link to a diagram survives being pasted into a ticket.

The result has no external references — diagrams are inlined SVG and theme icons are embedded as data: URIs — so it works from a file:// path, on an air-gapped machine, or on any static host.

OptionWhat it does
--output, -oDirectory to write the site into. Default: site.
--perspectiveDraw every diagram with this perspective shown.
--no-layoutIgnore the layout sidecar and lay every diagram out afresh.
--cleanDelete the output directory first.

c4 render#

c4 render [OPTIONS] INPUT_FILE

Render diagrams from INPUT_FILE as standalone SVG.

No browser and no server: the diagrams are laid out and painted by the same code the web app runs, bundled for Node. The layout sidecar beside INPUT_FILE is honoured when there is one, so a rendered diagram matches the arrangement you made in the Studio; --no-layout ignores it. This is the only command that needs Node.js installed; set C4STUDIO_NODE if it is not on PATH. Views the renderer cannot draw (custom, image) are skipped.

OptionWhat it does
--output, -oOutput directory (default: print to stdout).
--view, -vOnly render this view key.
--paddingBlank margin around the diagram, in pixels. Default: 24.
--no-titleOmit the heading above the diagram (the SVG <title> stays).
--no-legendOmit the legend of element styles used by the view.
--no-layoutIgnore the layout sidecar and lay the diagram out afresh. The sidecar is per-user state, so this is what makes the output the same on any machine.
--perspectiveShow one perspective: fade what does not carry it, badge what does, and list its values in the legend.

c4 webapp#

c4 webapp [OPTIONS] PATH

Launch the React web application backend for PATH.

PATH may be a directory (browsed as the source root) or a single source file (loaded eagerly, with its parent directory as the root).

Serves the full Studio by default. --viewer serves Viewer instead: the DSL cannot be edited, though diagrams can still be arranged — layout is per-user UI state in a gitignored sidecar either way.

--assistant additionally enables the DSL assistant, which is the one feature that sends your workspace source to an external API. It is off unless you ask for it.

OptionWhat it does
--assistantEnable the DSL assistant. OFF BY DEFAULT: it is the one feature that sends your workspace source to an external API. Needs ANTHROPIC_API_KEY in the environment and the optional extra (pip install 'c4studio[assistant]').
--dynamic-perspectivesLet the server read a perspective's url for its live value. OFF BY DEFAULT: the addresses come from the workspace file, so opening someone else's model would otherwise make this machine call their hosts. Only http and https are followed.
--portPort to listen on. Default: 8090.
--hostDefault: 127.0.0.1.
--no-browserDo not open a browser window automatically.
--viewerServe read-only: the DSL cannot be edited in the browser.

Edit this page on GitHub