Step: Subgraphs & clusters
Subgraphs & clusters
A subgraph groups nodes together. Name it starting with cluster_ and Graphviz's dot layout engine draws it as a visible box around its nodes — handy for grouping related parts of a system (frontend vs. backend, a microservice boundary, a request's lifecycle).
rankdir controls the overall layout direction: TB (top-to-bottom, the default), LR (left-to-right), BT, or RL. Set it once at the top of the graph body.
Why it matters: as diagrams grow past a handful of nodes, clusters and layout direction are what keep them readable — without them everything is one flat, tangled blob.
Pitfall: the cluster_ prefix is required — a subgraph named anything else (e.g. subgraph frontend { ... }) is a valid grouping for attribute inheritance, but dot will not draw a box around it.
Your turn: put "client" and "server" in a cluster labeled "Frontend", put "database" in its own cluster labeled "Backend", and switch the overall layout to left-to-right with rankdir=LR.