Layered architecture diagram with a side panel, from Python
If you explain a product as a stack of layers, this page shows one drawn from 32 lines of Python. The example is an invented web product, from the people at the top to the data at the bottom, with a side panel for sign-in.
Updated
A web product, top to bottom. Drawn by open-diagram 0.6.2 from examples/layers.py: 0 layout problems. Source
The picture as text
A web product, top to bottom
States shown: Live, Being built, In trial, Planned, Retiring. Solid lines: data flows today. Dotted lines: connection to build.
Blocks, left to right:
- People: Shoppers; Store staff; Partners
- Apps: Website; Mobile app; Staff tablets (retiring)
- Services: Search; Orders; Payments; Notifications (being built)
- Data: Main database; Search index; Event log (planned)
- Sign-in and access: Single sign-on; Passkeys (in trial); Audit log. Owner: Security team
Lines:
- People -> Apps
- Apps -> Services
- Services -> Data
- Sign-in and access -> Apps (connection to build)
- Sign-in and access -> Services (connection to build)What does this layered diagram show?
Four layers, each one wide panel, joined top to bottom by lines. The dotted lines from the Sign-in and access panel to Apps and Services are connections still to build.
When is a layered diagram useful?
When the question is what sits on what. Anything that serves several layers at once, such as sign-in, goes beside the stack, so the stack stays one column.
Which building blocks draw it?
"""Stacked layers with a side panel: a web product from the people who use it down to its data.
Run: python3 examples/layers.py"""
import os
from open_diagram import Diagram, Panel, Tile, Tiles
HERE = os.path.dirname(os.path.abspath(__file__))
LAYERS = [
("People", ["Shoppers", "Store staff", "Partners"], "accent"),
("Apps", ["Website", "Mobile app", Tile("Staff tablets", status="retiring")], "default"),
("Services", ["Search", "Orders", "Payments", Tile("Notifications", status="building")], "default"),
("Data", ["Main database", "Search index", Tile("Event log", status="planned")], "neutral"),
]
def build() -> Diagram:
d = Diagram("A web product, top to bottom", tag="EXAMPLE")
layers = d.stack([Panel(name, Tiles(items, cols=len(items)), tone=tone) for name, items, tone in LAYERS], gap=36)
for upper, lower in zip(layers, layers[1:]):
d.link(upper, lower, start="bottom", end="top")
side = Panel("Sign-in and access", Tiles(["Single sign-on", Tile("Passkeys", status="trial"), "Audit log"],
cols=1), footer="Owner: Security team")
middle = (layers[1].y + layers[2].bottom) / 2
access = d.add(side, layers[0].right + 96, middle - side.measure(d.theme)[1] / 2)
d.link(access, layers[1], start="left", end="right", kind="planned")
d.link(access, layers[2], start="left", end="right", kind="planned")
return d
if __name__ == "__main__":
build().save(os.path.join(HERE, "..", "docs", "images", "layers"))d.stack()places the layers top to bottom, all as wide as the widest.Tiles(items, cols=len(items))puts each layer's tiles in one row.tone="accent"gives People its soft yellow header.start="bottom", end="top"joins the bottom of one layer to the top of the next.d.add(side, x, y)places the side panel 96 px right of the stack, centred between Apps and Services.side.measure(d.theme)gives its size before it goes on the page.kind="planned"makes the two side lines dotted.
To add a layer, add one line to LAYERS. The loop that joins the layers includes it.
How do I write it as JSON?
JSON has no stack, but one column of panels draws the same way. Put the side panel in a second column, and it is centred on the whole stack.
{
"title": "A web product, top to bottom",
"columns": [
[{"id": "people", "title": "People", "tone": "accent", "tiles": ["Shoppers", "Store staff", "Partners"], "cols": 3},
{"id": "apps", "title": "Apps", "tiles": ["Website", "Mobile app"], "cols": 3},
{"id": "services", "title": "Services", "tiles": ["Search", "Orders", "Payments"], "cols": 3},
{"id": "data", "title": "Data", "tiles": ["Main database", {"label": "Event log", "status": "planned"}], "cols": 3}],
[{"id": "access", "title": "Sign-in and access", "tiles": ["Single sign-on", "Audit log"], "cols": 1}]
],
"row_gap": 36,
"gap": 96,
"links": [
{"from": "people", "to": "apps", "start": "bottom", "end": "top"},
{"from": "apps", "to": "services", "start": "bottom", "end": "top"},
{"from": "services", "to": "data", "start": "bottom", "end": "top"},
{"from": "access", "to": "services", "start": "left", "end": "right", "kind": "planned"}
]
}
The check: 0 layout problems
How do I make my own?
After pip install open-diagram, copy examples/layers.py and change the names, tiles and tones in the LAYERS list. Then run open-diagram check layers.py and open-diagram draw layers.py. The Python reference lists every block.