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 |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Selectors¶
include, exclude and animation accept an element (written as its alias),
a string, a selector object or an iterable of those:
- An element becomes its alias;
"*"and any other string are written as is. ViewTag("Critical")becomeselement.tag==Criticaland quotes the tag when needed.RawSelector("relationship.tag==Async")is written verbatim. The renderer cannot check it; the Structurizr CLI does.
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=Truealso registers the interaction as a model relationship, so it shows up in other views.relationship=relbinds the step to an existing model relationship. Passing bothrelationship=andcreate_relationship=TrueraisesValueError.steps=[...]on the factory takes relationships orDynamicStepvalues.
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.