[Tip] Lay out a DBML schema with the fewest line crossings (open-source tool, I'm the author)

Disclosure: I’m the author of this tool, so this is a share-and-feedback post, not a review.

I built erlayout, a free open-source tool that arranges a schema’s tables so foreign-key lines cross as little as possible. It reads DBML as written in dbdiagram.io (aliases, schema-qualified names, short, long and composite refs, TablePartial), plus SQL DDL and JSON. If your schema already lives in DBML, you can paste it in and compare the result with auto arrange.

The difference is that it uses an exact solver (OR-Tools CP-SAT) and tells you what it can prove. On the Sakila sample, a standard layered layout has 8 crossings; erlayout finds 2 and proves no layout in that style can do better. Every result says whether it’s proven minimal or best found with a lower bound, and two independent verifiers re-check each drawing.

Exports: SVG, draw.io, Excalidraw, Mermaid.

Demo: https://erlayout.app
Code: GitHub - ore-codes/erlayout: Lay out ER diagrams from SQL, DBML or JSON with the fewest possible line crossings, and a proof of optimality (OR-Tools CP-SAT). · GitHub
Install: pip install erlayout

Limits: proving optimality is practical up to a few dozen tables. On larger or very dense schemas it returns its best layout plus a lower bound. It doesn’t write back to dbdiagram.io, so it’s for getting a cleaner picture, not a replacement for the editor.

If you have DBML that parses badly or lays out badly, I’d like to see it.

1 Like