Use Auto Layout for Architecture Diagrams
What you'll build
In this tutorial, you will take a cluttered, disorganized graph of services and databases, and use Rekhic's Dagre layout engine to automatically format it into a clean, hierarchical architecture diagram.
Before you start
- Open any diagram on the canvas, or create a quick set of 5-8 connected nodes in random positions to see the auto layout transformation in action.
Step 1: Examine the Raw Graph
- Place or import several nodes on the canvas.
- Connect them with directional connectors (e.g.
Client -> Gateway -> Service A, Service B -> Database). - Notice if edges cross over each other awkwardly or if node spacing is uneven.
Step 2: Trigger Top-to-Bottom Auto Layout
- Click the Auto Layout button in the canvas toolbar.
- Observe how the layout engine:
- Identifies root ingress nodes (nodes with only outgoing edges) and places them on Tier 1.
- Positions intermediate routing services on Tier 2.
- Arranges downstream persistence stores on Tier 3.
- Adjusts horizontal spacing between sibling services to prevent edge overlap.
Step 3: Experiment with Left-to-Right Layout
- For data pipelines, ETL workflows, or sequential event streaming architectures, a horizontal flow is often preferred.
- Change the layout direction setting from
TB(Top-to-Bottom) toLR(Left-to-Right). - The layout automatically realigns with sources on the far left, transforms in the middle, and sinks on the right.
Review the generated architecture
- Check that the logical flow of data follows the direction of the connectors.
- Verify that edge bends are clean 90-degree right angles.
- If the layout looks great, proceed to custom styling. If you prefer your original layout, simply press
Cmd/Ctrl + Zto undo.
Customize the diagram
- Now that the primary tiers are arranged, you can fine-tune individual nodes:
- Nudge a database node slightly to accommodate a larger bounding box.
- Add a container around the services on Tier 2.
- Adding a group container does not break auto layout; you can run auto layout again whenever you add new nodes.
Export your result
- Click Export to download a polished PNG image for your architecture review meeting.
- Click Export Markdown to generate the updated relationship tables.
Tips
- Disconnected nodes (nodes with no edges) are neatly aligned in a separate utility row by the layout engine.
- If your diagram contains cyclical dependencies (e.g. Service A calls Service B which calls Service A), Dagre gracefully handles the cycle by creating a feedback loop edge.
Limitations
- Auto layout calculates coordinates algorithmically based on topological sort and edge weight. It does not have semantic knowledge of physical data center geography. Use manual grouping for physical network topologies.