Skip to content

Structurizr Views

Views are declared on workspace.views. Each factory returns the view, and every view gets its own block in the DSL. All views share the same keyword arguments:

Argument Meaning
title Title shown on the view.
key Stable view key. It is what --structurizr-view-key and Kroki select.
description View description.
include Selectors to include. A non-dynamic view with no include and no exclude gets include *.
exclude Selectors to exclude.
animation Ordered groups of elements revealed step by step.
auto_layout An AutoLayout, or None to use the render options.
tags View tags (list[str]).
properties View properties.

View types and their scope

Factory DSL view Scope
SystemLandscapeView() systemLandscape None.
SystemContextView(system) systemContext A SoftwareSystem. Required.
ContainerView(system) container A SoftwareSystem. Required.
ComponentView(container) component A Container. Required.
DynamicView(scope=None) dynamic Optional SoftwareSystem or Container.
DeploymentView(scope=None, environment=...) deployment Optional element. environment is required.

A scope must be a model object of the same workspace, never an alias string (that raises TypeError immediately). A missing or wrong scope is reported when the workspace is rendered, for example ContainerView requires a scope reference. or ComponentView has an invalid scope reference. A deployment view whose environment has no deployment nodes is rejected too. See Limitations.

Python call Generated DSL
workspace.views.SystemLandscapeView(key="landscape")
systemLandscape "landscape" {
  include *
  autoLayout lr
}
workspace.views.SystemContextView(shop, key="context")
systemContext shop "context" {
  include *
  autoLayout lr
}
workspace.views.ContainerView(shop, key="containers")
container shop "containers" {
workspace.views.ComponentView(api, key="components")
component api "components" {
workspace.views.DeploymentView(shop, environment="Live", key="live")
deployment shop "Live" "live" {
flow = workspace.views.DynamicView(shop, key="checkout")
flow.step(customer, api, "Pays", technology="HTTPS")
dynamic shop "checkout" {
  customer -> api "Pays" "HTTPS"
  autoLayout lr
}
workspace.views.SystemContextView(shop, key="context",
    include=["*", ViewTag("Critical")],
    exclude=[customer])
include *
include element.tag==Critical
exclude customer
workspace.views.ContainerView(shop, key="containers",
    exclude=RawSelector("relationship.tag==Async"))
exclude relationship.tag==Async
workspace.views.ContainerView(shop, key="containers",
    animation=[[customer], [api]])
animation {
  customer
  api
}
workspace.views.SystemLandscapeView(key="landscape",
    auto_layout=AutoLayout("TopBottom", rank_separation=100))
autoLayout tb 100
workspace.views.SystemLandscapeView(key="landscape",
    tags=["Overview"], properties={"audience": "all"})
tags "Overview"
properties {
  "audience" "all"
}
flow = workspace.views.DynamicView(shop, key="checkout")
flow.step(customer, api, "Pays", create_relationship=True)
customer -> api "Pays" {

Selectors

include, exclude and animation accept an element (written as its alias), a string, a selector object or an iterable of those:

A view can also be extended after creation with view.include(...) and view.exclude(...), which return the view.

Auto layout

AutoLayout(rank_direction="LeftRight", implementation=None, rank_separation=None, node_separation=None) becomes autoLayout lr (and the optional separations). Valid rank directions are listed in the Reference. A view without auto_layout uses the one from the render options, which is left to right by default.

Dynamic views

A dynamic view is an ordered list of interactions. Add them with view.step(source, destination, description, technology=...).

  • By default a step is view-local: it appears in the dynamic view and does not add a relationship to the model. This is what you want for sequences that reuse elements.
  • create_relationship=True also registers the interaction as a model relationship, so it shows up in other views.
  • relationship=rel binds the step to an existing model relationship. Passing both relationship= and create_relationship=True raises ValueError.
  • steps=[...] on the factory takes relationships or DynamicStep values.
from c4.contrib.structurizr import Rel, Workspace

workspace = Workspace("Checkout")

with workspace.model as model:
    customer = model.Person("Customer")
    shop = model.SoftwareSystem("Shop")
    web = model.Container("Web App", owner=shop)
    api = model.Container("API", owner=shop)
    customer >> Rel("Uses") >> web

flow = workspace.views.DynamicView(shop, key="checkout")
flow.step(customer, web, "Starts checkout")
flow.step(web, api, "Submits the order", technology="JSON/HTTPS")

Upstream: views, dynamic views, view expressions.