LikeC4 Views¶
Views are created on project.views. LikeC4 has no fixed C4 view types: an
element view shows any part of the model, a deployment view shows the
deployment, and a dynamic view shows an ordered sequence of interactions. Keys
are unique across all view types.
| Factory | Source | Takes |
|---|---|---|
element_view(key, title=None, of=None, ...) |
view key of scope |
include, exclude, style, auto_layout |
deployment_view(key, title=None, ...) |
deployment view key |
include, exclude, style, auto_layout |
dynamic_view(key, title=None, variant=, ...) |
dynamic view key |
step, back, auto_layout |
All three also take description, tags and links. Rules are written in the
order they are added.
| Python call | Generated DSL |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Predicates¶
include, exclude and style take elements (or deployment nodes and
instances) and these predicate objects:
| Object | Written as | Meaning |
|---|---|---|
Wildcard() |
* |
The view scope, or all top-level elements. |
Children(x) |
x.* |
Direct children of x. |
Descendants(x) |
x.** |
All nested elements of x. |
[Between(a, b)][c4.contrib.likec4.Between] |
a -> b |
Relationships from a to b; both=True writes <->. |
[Incoming(x)][c4.contrib.likec4.Incoming] |
-> x |
Relationships that enter x. |
[Outgoing(x)][c4.contrib.likec4.Outgoing] |
x -> |
Relationships that leave x. |
[InOut(x)][c4.contrib.likec4.InOut] |
-> x -> |
Relationships that enter or leave x. |
Where(x, tag=, kind=) |
x where tag is #t ... |
A filter over another item. |
RawPredicate(text) |
text as is | Anything else; checked only by likec4 validate. |
Rel is not a view predicate
Rel is the relationship expression
(a >> Rel("title") >> b) used in the model. In a view, a relationship
predicate is Between, Incoming, Outgoing or InOut.
include(..., navigate_to="view-key") writes with { navigateTo ... }. A style
rule needs at least one property and cannot target a relationship predicate.
Where cannot wrap a Where or a RawPredicate, and the relationship
predicates cannot connect them either; write a RawPredicate instead.
An element view of X may only include elements inside X. The renderer cannot
check this statically.
Auto layout¶
view.auto_layout(direction="TopBottom", rank_sep=None, node_sep=None) adds an
autoLayout rule. The directions are listed in the
Reference. node_sep needs rank_sep.
Deployment views¶
deployment_view works over deployment nodes and instances. Its include
takes no navigate_to: with { ... } overrides are not generated in
deployment views.
Dynamic views¶
dynamic_view(key, title, variant="diagram") takes a flat list of steps.
variant is "diagram" or "sequence".
view.step(source, target, title, **properties)writessource -> target.view.back(receiver, sender, title, **properties)writesreceiver <- sender.- Step properties are
description,technology,notes,navigate_to(a dynamic view key) andcolor.
Steps connect model elements. Parallel and alternative blocks are not supported.
from c4.contrib.likec4 import Project
project = Project("Checkout")
project.specification.element("actor").element("system")
customer = project.model.element("actor", "Customer", alias="customer")
shop = project.model.element("system", "Shop", alias="shop")
flow = project.views.dynamic_view("checkout", "Checkout", variant="sequence")
flow.step(customer, shop, "pays", technology="HTTPS")
flow.back(customer, shop, "receives a receipt")
print(project.render())
Upstream: views, dynamic views, predicates.