Layout and positions
skemo places the cards; you choose a direction, and pin only what you care about.
Direction
dir="down" (default)
dir="right"
diagram(dir="…") sets the main direction of the arrows: down (default), right,
up or left. right suits pipelines and processes, down hierarchies and networks.
Cards are arranged in layers along that direction and aligned in columns inside zones. Cards of the same row keep the
order you wrote them in, inside zones too; an arrow written after its target still points in the main direction.
Tidy layers (preview)
A card sits centred over the cards it leads to when it is their only parent, or over the card in its column. Arrows leave and enter in the direction of the diagram, rows inside a zone are as far apart as outside, and two arrows never share a line where they meet a card.
Rows in a zone (preview)
card#lb Load balancer
to(p1)
zone#ns(wrap="3") Namespace
card#p1 pod-1
card#p2 pod-2
card#p3 pod-3
card#p4 pod-4
card#p5 pod-5
card#p6 pod-6wrap="N" on a zone puts at most N children per row (per column with dir="right"), on a grid, in
writing order. Useful when a zone of many unconnected cards would otherwise make one very long row; (preview) a
zone of four cards or more that have no arrow at all (an inventory) is laid as such a grid by itself, about as many
columns as rows. When a card ends up behind
another as seen from the card it is linked to, a warning says so; not with wrap="1", a single file of cards (a server
and its stack) whose arrows come in by the free sides. When an arrow from outside reaches a card beyond the first row, the
zone's rows (and those of the zones beside it) are spread to leave a corridor between them, which other arrows may cross,
so that the line does not go round the zone.
Stacks (preview)
diagram(dir="down")
card#kubectl kubectl
to(api)
zone#cluster Cluster
zone#cp(wrap="1") Control plane
card#api Kubernetes API server
card#k0 Kubelet
card#d0 Docker
zone#w1(wrap="1") Worker
card#a1 Application
card#k1 Kubelet
card#d1 DockerWith wrap="1", a zone is a stack: its cards share one width, the widest one's, on a common left edge. Sibling zones
side by side start on the same line.
Layers of the same width (preview)
diagram(dir="up" zones="stretch")
zone#pods Pods
card#f1 frontend-1
card#f2 frontend-2
card#b1 backend-1
card#b2 backend-2
zone#svcs Services
card#sf Frontend
to(f1 f2 join="trunk")
card#sb Backend
to(b1 b2 join="trunk")Zones stacked one under the other take the width of the widest one, like layers drawn by hand. Only the frames grow: no
card moves, no number is written in the file. diagram(zones="fit") keeps each frame fitted to its content;
diagram(zones="stretch") evens them in every direction (with dir="right", the same height).
Groups in order: stack (preview)
//- Kubernetes application architecture
diagram(dir="down" look="classic" zones="stretch")
title Kubernetes application architecture
|.pill namespace mon_namespace
stack
zone#pods.podz(tag="172.30.0.0/16") Pods
card#fe1.pod.fe.col-w1 frontend-…-cjxbl
| 172.30.0.1
|.pill 8080 · http
to(svc-be join="http" constraint="false").dep HTTP → :9000
card#fe2.pod.fe.col-w1 frontend-…-jkn87
| 172.30.0.2
|.pill 8080 · http
to(svc-be join="http" constraint="false").dep
card#be1.pod.be.col-w2 backend-…-ac789
| 172.30.0.6
|.pill 9000 · back
to(svc-db join="sql" constraint="false").dep SQL → :5432
card#be2.pod.be.col-w2 backend-…-p78f2
| 172.30.0.7
|.pill 9000 · back
to(svc-db join="sql" constraint="false").dep
card#pg.pod.db.col-w3 postgresql-0
| 172.30.0.5
|.pill 5432 · pgsql
zone#svcs.svcz(tag="172.21.0.0/16") Services
card#svc-fe.svc.fe.col-w1 Frontend
| selector: app=myapp-frontend
to(fe1 fe2)
card#svc-be.svc.be.col-w2 Backend
| selector: app=myapp-backend
to(be1 be2)
card#svc-db.svc.db.col-w3 Database
| selector: app=myapp-database
to(pg)
zone#nodes.bare.wide
card#w0.k8snode.col-w1(icon="server") Worker 1
| Worker node
card#w1.k8snode.col-w2(icon="server") Worker 2
| Worker node
card#w2.k8snode.col-w3(icon="server") Worker 3
| Worker node
card#net.wide.network Cluster network
to(w0 w1 w2)/* zones */
.podz { --c: #10B981; }
.svcz { --c: #F59E0B; }
zone.podz, zone.svcz { border-width: 1.5px; }
zone.svcz > .title { top: auto; bottom: 12px; }
zone > .title { letter-spacing: .14em; }
/* pods: a thick band on top, centred text, the port as a pill */
.fe { --c: #2563EB; }
.be { --c: #7C3AED; }
.db { --c: #DB2777; }
card.pod { min-width: 0; padding: 12px 14px 12px; text-align: center; border-top-width: 6px; }
card.pod .title { font-size: 13.5px; font-weight: 700; }
card.pod li { font-size: 12.5px; color: #64748B; }
card.pod li .mono { color: #64748B; }
card.pod li.pill { color: var(--c); }
/* services: a full coloured border, a light badge */
.svc { --label: "SERVICE"; }
card.svc { border: 1.5px solid var(--c); border-radius: 12px; padding: 12px 18px; }
card.svc .title::before { background: color-mix(in srgb, var(--c) 12%, #FFFFFF); color: var(--c);
font-size: 10px; letter-spacing: .1em; padding: 1px 6px; border-radius: 6px; }
card.svc li { color: #64748B; }
/* arrows: forks in the service's colour, dependencies dashed with a dark label */
.edge.from-fe { color: #2563EB; }
.edge.from-be { color: #7C3AED; }
.edge.from-db { color: #DB2777; }
.edge.dep { color: #475569; }
.edge.dep .line { stroke-dasharray: 5 4; }
.edge.dep .edge-label { background: #334155; color: #F8FAFC; font-family: var(--mono); font-size: 11px; }
/* nodes and the cluster network */
.k8snode { --c: #1E293B; --icon-color: #94A3B8; }
card.k8snode { background: #1E293B; border: 1px solid #334155; border-radius: 12px; padding: 16px 22px; --icon-size: 20px; }
card.k8snode .title { color: #F8FAFC; font-size: 17px; }
card.k8snode li { color: #94A3B8; }
card.network { --c: #0F172A; background: #1E293B; border-color: #334155; }
card.network .title { color: #94A3B8; text-align: left; }
.edge.from-network { color: #475569; }A stack draws nothing: it lays its children, zones or cards, one after the other in writing order along the
direction (here pods, services, nodes, then the network), whatever the arrows between them. Arrows still align what they
link (each service sits under its pods); one going back up the stack leaves by the top and enters by the bottom. A
.bare zone without a title groups cards without drawing anything (the three nodes). A card belongs to one group
only: zones and stacks form a tree. The zones of a stack share one width, like layers. A card of a zone whose arrows all
leave the zone, with none coming in, sits on the zone's first row. Cards standing on a stretched card split its width evenly, each centred in its share. Classes .col-w1, .col-w2… line up each service and its pods over
the worker that hosts them, across zones; the workers' .wide zone spreads them over the full width and gives the
columns their place: each worker is as wide as the widest group of its column, so two pods never straddle two workers.
Target box (preview)
diagram(fit="16:9") states where the diagram will be shown (a slide; 8:9 for half a slide), or
its size in pixels: fit="1280x720". What matters is how large the text ends up once the diagram is fitted in that
box, not only its proportions: a layout with the right ratio but twice as big shows smaller text. skemo never changes the layout
by itself for it, so the drawing stays stable while you edit: when a setting such as zone#ns(wrap="3") or
diagram(dir="right") would show the text at least 15 % larger, it warns and names it (with a box in pixels, the
text size before and after). skemo lint f.skemo --fit lists the candidates, each one laid out for real, with the gain in
text size, and --fix puts the best one in the file. When the proportions are more than 15 % off the target and
no setting helps, the warning says so: the layout itself has to change.
Pinned positions
diagram(dir="down")
card#internet.cloud(at="180,0") Internet
to(fw).wan WAN
card#fw.t0(at="180,110") Firewall
to(web side="left-top")
to(db side="right-top" via="440,200")
card#web.t1(at="0,260") Web
card#db.t2(at="420,260") Databaseat="x,y" pins the top-left corner of a card or zone, in pixels. Cards without at keep their automatic
place; every arrow is routed either way. The graphical editor writes at= for you when you drag a card.
Adjusting an arrow
side="start-end" forces the sides an arrow leaves and enters by; via="x,y" makes it pass through
waypoints. In the example above, fw → web leaves by the left side and fw → db passes through
440,200.
Stability
Editing one card only moves the arrows attached to it: positions do not shift around when you add a line or rename a title. Pinning a card exactly where the layout put it changes nothing in the drawing. This is what makes text and drag-and-drop editing safe to mix.
Overlaps
A card pinned on top of another is never moved: the file shows exactly what you wrote. skemo emits a warning that names both cards instead, and the editor offers to separate them.
In timeline, frieze and mind map modes, positions come from the dates or from the tree: at= has
no effect there (warning).
