c4studio v0.5.0

Beyond Structurizr#

c4studio reads the standard Structurizr DSL. This page covers what it adds on top, and the few places where it behaves differently from the Java Structurizr tools.

Nothing here changes the grammar. Every addition is either an ordinary Structurizr properties entry, which other tools ignore, or a file beside the workspace. A workspace that uses them still opens in structurizr.com, Structurizr Lite or the Structurizr CLI.

At a glance#

AdditionKindWhat it does
c4studio.autolayoutElement propertyLays out the children of a boundary in their own direction.
c4studio.autolayout.<group>View propertyThe same, for a group inside a view.
c4studio.legendStyle propertyReplaces the legend label for elements or relationships with that style.
c4studio.badgeElement style propertyColours the properties badge for elements with that tag.
c4studio.iconTintElement style propertyDraws a one-colour icon in the box's text colour, or a colour you name.
Theme filestheme with a pathInlined at parse time, so they work offline. Icons become data: URIs.
c4studio.lint.jsonFile beside the workspaceYour model standards, read by c4 lint.
<workspace>.layout.jsonFile beside the workspaceYour arrangement of each view: per-user, never committed.
Dynamic perspectivesBehaviourA perspective's url supplies its value live, when you allow it.

Layout direction per boundary: c4studio.autolayout#

A view's autoLayout sets one direction for the whole diagram. A software system or container drawn as a boundary can set its own direction for its children with this property: tb (top to bottom), bt, lr (left to right) or rl.

Groups have no properties of their own, so a group's direction goes in the view's properties, keyed by the group's name.

workspace "Layout hints" {
    model {
        user = person "User"
        shop = softwareSystem "Shop" {
            properties {
                "c4studio.autolayout" "lr"
            }
            web = container "Web" "Storefront" "React"
            group "Backend" {
                api = container "API" "Orders" "Python"
                worker = container "Worker" "Fulfilment" "Python"
                db = container "Database" "Orders and stock" "PostgreSQL"
            }
        }
        user -> web "Shops using"
        web -> api "Calls"
        api -> db "Reads and writes"
        worker -> db "Polls"
    }
    views {
        container shop Containers {
            include *
            autoLayout tb
            properties {
                "c4studio.autolayout.Backend" "tb"
            }
        }
    }
}

The diagram as a whole runs top to bottom, the Shop boundary arranges its children left to right, and the Backend group stacks its three containers vertically.

Legend labels: c4studio.legend#

Every diagram c4studio draws carries a legend of the styles it actually uses. By default a row is labelled with the style's tag. c4studio.legend replaces that label with a sentence, which helps when a tag such as Legacy or PCI means something specific to your organisation.

// in: views
styles {
    element "Container" {
        background #438dd5
        color #ffffff
        properties {
            "c4studio.legend" "Something we build and run"
        }
    }
    relationship "Relationship" {
        properties {
            "c4studio.legend" "Synchronous call"
        }
    }
}

Badge colour: c4studio.badge#

In the Studio, an element that has properties shows a small ⓘ badge in its corner. Click it to open the element's details. The badge takes the element's text colour by default. c4studio.badge on an element style sets it per tag, as #rgb or #rrggbb. The "i" is drawn black or white, whichever is readable on the colour you choose.

// in: views
styles {
    element "Database" {
        shape Cylinder
        properties {
            "c4studio.badge" "#ffcc00"
        }
    }
}

A value that is not a hex colour is ignored on the diagram, and c4 lint reports it as invalid-badge-colour.

Icon tint: c4studio.iconTint#

A one-colour glyph, the kind in Tabler or Font Awesome, is drawn black whatever the box, which disappears on a dark fill. c4studio.iconTint paints the icon in one colour and keeps its shape:

  • true uses the element's text colour, so the glyph matches the label;
  • a hex colour, such as a brand colour, uses that colour;
  • false turns off a tint a broader style set.
// in: views
styles {
    element "Message Bus" {
        icon "icons/outline/Queue.svg"
        properties {
            "c4studio.iconTint" "true"
        }
    }
}

It is opt-in because a multi-colour icon, such as a cloud vendor's, would flatten to a silhouette. The exception is an SVG that paints only in currentColor, as Tabler, Lucide and Feather icons do: that colour means "the colour around me", which an image cannot otherwise get, so such an icon is tinted to the text colour without being asked. false still turns it off. Exports, c4 render and the VS Code preview draw it the same way. Upstream Structurizr ignores the property and draws the icon as it is. Any other value is ignored on the diagram, and c4 lint reports it as invalid-icon-tint.

Theme files that work offline#

Structurizr themes are usually URLs. c4studio fetches and caches those, and also accepts a path to a theme file, resolved against the workspace file:

// in: views
theme "themes/corporate.json"

A theme file is inlined when the workspace is parsed, and every relative icon in it becomes a data: URI. Icon paths are relative to the theme file, so a theme folder can be copied around whole. Nothing is fetched, so a file theme works offline in the Studio, c4 render, c4 publish and the VS Code preview.

As with fetched themes, the workspace's own styles always win, whatever order the lines are in. A missing or malformed theme file is a warning (theme-not-found or invalid-theme) and the diagram renders without it. c4 lint does not report a theme's unused tags, because a theme is a library.

Model standards: c4studio.lint.json#

c4 lint reads this file from beside the workspace, if it is there:

{
  "ignore": ["missing-technology"],
  "select": [],
  "naming": {
    "softwareSystem": "^[A-Z]",
    "container": "^[A-Z][A-Za-z ]+$"
  }
}
KeyMeaning
ignoreRule codes to skip.
selectWhen not empty, run only these rules.
namingElement type to a regular expression its names must match. The naming-convention rule is off until this has an entry.

The rules are listed in Lint rules.

Layout files: <workspace>.layout.json#

The DSL describes the model. It does not describe where you dragged each box. When you arrange a view in the Studio, the positions go in a sidecar file beside the workspace, shop.layout.json for shop.dsl, together with the size of any box you resized, each view's line style, line routes, label offsets, collapsed and expanded elements, moved titles and legends, and named layouts.

  • The file is per-user UI state, so add *.layout.json to .gitignore.
  • c4 render, c4 publish and the VS Code preview honour it, so your exports match what you arranged. --no-layout ignores it, which gives the same output on any machine.
  • It is keyed by view key, so give every view an explicit key.

Structurizr keeps layout inside workspace JSON instead. c4studio keeps your DSL free of coordinates, which keeps diffs readable.

A workspace .json file that Structurizr has laid out is drawn the way Structurizr drew it, in the Studio, c4 render and c4 publish. That covers element positions, line bend points, and box sizes, which are 450×300 unless an element style sets width or height. Text in those boxes is Structurizr's size too: 24px descriptions unless a style sets fontSize, with the name larger and the metadata smaller, centred in the box. Boundaries are fitted around their contents, because Structurizr stores no position for them. A view with automaticLayout, or with every element at 0,0, which is what Structurizr writes for a view nobody arranged, is laid out afresh, as Structurizr itself does. A sidecar beside the JSON still wins over the layout inside it. c4 export writes element positions and bend points back out.

Dynamic perspectives#

A perspective can carry a url. In c4studio, a perspective with a url has its value read from that URL, so a badge can show live data such as an on-call team or a security rating.

// in: model
api = softwareSystem "Payments API" {
    perspectives {
        perspective "On call" {
            description "The team paged for this service"
            url "https://status.example.com/oncall/payments"
        }
    }
}

This is off by default. Start the Studio with c4 webapp <path> --dynamic-perspectives to allow it. Only http and https are followed, at most 50 distinct URLs per refresh, with a 10-second timeout, refreshed every 60 seconds. A failed request shows its HTTP status, so a badge reads 503 rather than going stale. c4 render and c4 publish never fetch.

Where c4studio differs from Structurizr#

ConstructStructurizrc4studio
!script, !plugin, !componentsExecutedNever executed. Skipped whole and reported as unsupported-directive.
Unknown blocks and directivesA parse errorSkipped, brace-balanced, and reported, so the rest of the file still loads.
workspace extendsLocal file or URL; an argument left out resets the valueLocal DSL file only. An argument left out keeps the base's value.
!identifiers hierarchicalHierarchical identifiersAccepted, but identifiers always resolve flat.
archetypes { … }SupportedSkipped with unsupported-block.
!decisionsAn alias for !adrsNot supported; use !adrs.
branding, terminologyApplied to diagramsParsed and exported, but not drawn.
routing OrthogonalOrthogonal linesDrawn with c4studio's own step router. Direct and Curved are not painted.
LayoutStored in workspace JSONStored in a per-user .layout.json sidecar. A layout inside workspace JSON is drawn too.

Every skipped construct is recorded as a diagnostic with a file, line and column. c4 check prints them, the Studio and VS Code show them as problems, and the rest of the model still renders. The full list of codes is in Diagnostic codes, and Keyword coverage maps every keyword in the Structurizr language reference to what c4studio does with it.

Edit this page on GitHub