reladraw draws your diagram from where you say the boxes go

1 month ago

Reladraw drew this diagram from a text file with zero coordinates in it. Every box got its spot from a sentence, like above-left of the cloud sync hub. Reladraw is a free diagram language, and it sits between two tools you may know. In Mermaid, you type a list of boxes and arrows, and the tool places every box for you. In draw.io, you drag every box yourself.

Ask about this presentation

Chapters

  1. 0:00reladraw · a diagram language where you say where every box goes
  2. 0:20The same diagram, drawn by hand and written as text
  3. 0:47What you’ll learn, and the catch
  4. 1:13Between Mermaid and draw.io
  5. 2:04Five statements, three boxes, one arrow
  6. 2:38Every placement becomes one rule
  7. 3:14The longest chain sets the layout
  8. 3:54Add a box and its neighbours move apart
  9. 4:28When your rules fight
  10. 4:59Overlaps move only where your file points
  11. 5:55Thirteen preset themes
  12. 6:18The catch: a launch-day file fails on today’s build
  13. 6:54What the 44 statements hold
  14. 7:18The pushback: tikz, D2 and Graphviz
  15. 7:55Arrows stopped running through boxes
  16. 8:47Four ways to lay out a diagram
  17. 9:16Who should try reladraw
  18. 9:41Try reladraw
Show transcript
  1. Reladraw drew this diagram from a text file with zero coordinates in it. Every box got its spot from a sentence, like above-left of the cloud sync hub. Reladraw is a free diagram language, and it sits between two tools you may know. In Mermaid, you type a list of boxes and arrows, and the tool places every box for you. In draw.io, you drag every box yourself.

    Slide text
    from reladraw’s GitHub page
    above-left of cluster.hub

    reladraw

    A diagram language where you say where every box goes
    TypeScript Apache-2.0 command line + browser
    Mermaid the tool places every box
    reladraw you say where each box goes
    draw.io you drag every box
  2. You get a text language plus a command-line tool, a program you run by typing a command. You write lines like API below app, and the tool draws the picture. On the left is an architecture diagram that Joe Walsh, the one developer behind Reladraw, drew by hand in draw.io. On the right, Reladraw drew the same diagram from a text file of forty-four statements, with zero coordinates in it. I love this pair, because the right side came out of plain text you can edit like any other file.

    Slide text

    Joe Walsh drew this diagram by hand, then rewrote it as 44 statements with no coordinates

    drawn by hand in draw.io
    rendered from 44 statements
    from reladraw’s GitHub page
  3. By the end, you'll know how a word like below turns into arithmetic a computer solves without trial and error. You'll know what Reladraw does when two boxes land on top of each other and your file never said which one goes where. You'll also know the catch. Reladraw's syntax is still changing, and one of the project's own example files from launch day already fails on today's build. And I'll tell you who I think should try Reladraw this weekend.

    Slide text
    reladraw’s architecture diagram, dimmed behind the slide copy
    1
    How ‘below’ becomes arithmetic solved without trial and error
    2
    What reladraw does when two boxes land on top of each other
    3
    Why a file from launch day already fails on today’s build
    4
    Who should try it this weekend
  4. There are two ways to make a diagram today. The first is the Mermaid side. Mermaid, D2 and Graphviz are all text languages, and the tool decides where every box goes. This diagram labels that side auto-layout. That approach breaks once you want one module over on the right, because those languages have no way to say it. The second is the draw.io side. draw.io, Excalidraw and Figma are drawing apps. The diagram labels that side absolute, because every box sits at a fixed spot you set. You get total control, and every edit is hand work. For an AI agent, a program like Claude Code that edits your files for you, that hand work gets expensive. The agent has to work the picture out from raw coordinates before it knows which numbers to change. I think that agent problem is the real pitch. Reladraw aims at the middle. Every position in a Reladraw file is stated relative to another box.

    Slide text

    Mermaid decides where boxes go, draw.io makes you drag each one, and reladraw sits between

    drawn by reladraw, from the project’s own example file
  5. I'll read you the example from the README, the project's front page on GitHub. It's five statements. The first line makes a box called Web app. The next two put an Interface box and an API box inside it, with the API below the Interface. Then a Database box goes right of the app, and level with the app, so the two share a center line. The last line draws an arrow labelled queries, from the API to the Database. It leaves the API's right side and lands on the Database's left side. Your whole vocabulary is words like below, right of, above-left of and level with, and you never type a number for a position.

    Slide text

    Five statements make three boxes, place them, and draw one arrow

    node app "Web app" a box
    node app.ui "Interface" a box inside it
    node app.api "API" below app.ui inside, below Interface
    node store "Database" right of app level with app right of the app, same height
    edge app.api -> store "queries" from: right to: left an arrow, side to side
    above below left of right of above-left of level with
    drawn by reladraw
  6. And this is the part I find clever. Reladraw turns each placement into one rule on one axis, across or down. API below Interface becomes a single rule: the API sits at least one gap further down the page than the Interface. Right of becomes the same kind of rule on the horizontal axis. Reladraw works out the horizontal and the vertical as two separate problems. Level with is the one placement that pins an exact spot. Reladraw writes it as two rules pointing opposite ways, at least this far and at most this far, so only one answer fits. Every word in the language comes down to that same kind of rule.

    Slide text

    Every placement becomes one rule: this box sits at least so far from that one

    down Interface API at least one gap
    across Web app Database at least one gap
    across Web app Database at least one gap
    level with Web app Database at least 0 at most 0
    level with: two rules pointing opposite ways
  7. Now the solve. Every box starts at position zero. Reladraw walks through every rule, and whenever a rule says a box has to sit further along, the box moves up to that spot. Reladraw repeats that walk once for each box, and by then every box has settled. Follow a chain of rules and the distances add up. A box at the end of two chains lands at the end of the longer one, because that's the only spot that satisfies both. The code calls this longest paths. The result is the tightest layout that keeps every rule, and Reladraw places the boxes without ever trying a layout and throwing it away. So the same file gives you the same picture, every time. When a diagram lives in a repo next to your code, that's exactly what I want from it.

    Slide text

    The tightest layout comes from following the longest chain of rules

    0 E D C B A every box starts at 0
    0 A C B D E two hops three hops
    A C D E three hops
    “no search happens and no alternative is ever weighed”
    — a comment in reladraw’s code
  8. Because every gap is a minimum, adding or deleting a box moves the other boxes only as far as they have to go. Here's the two-sides diagram from a minute ago, with the Reladraw box in the middle deleted. The Mermaid side and the draw.io side sit right next to each other. Add one line back. That line puts the Reladraw box right of the Mermaid side, left of the draw.io side, and level with the Mermaid side. The draw.io side moves right by just enough room for that box and its gaps. Delete the line again and the two sides close back up. This is the demo that sold me, because one line of text moved the whole draw.io side, and deleting the line put it back.

    Slide text

    Add a box between two others and they move apart; delete it and they close up

    without the reladraw line
    with it
    right of auto left of manual level with auto
    drawn by reladraw, from the project’s own example file
  9. Your rules can also fight. Take a small file with three boxes, A, B and C. B sits right of A, and C sits right of B, so C has to end up right of A. The same file also says C sits left of A. In the solve, a loop like that never settles, and C's position keeps growing on every walk. Reladraw notices when positions are still moving after one walk per box. Then Reladraw traces the loop back and quotes your own words: right of B, left of A, and right of A cannot all hold, because they leave no room horizontally. The error hands you the three lines to fix.

    Slide text

    When your rules fight, reladraw quotes the fighting lines back to you

    the file
    node a "A" node b "B" right of a node c "C" right of b left of a level with a
    what reladraw prints
    "right of b" and "left of a" and "right of a" cannot all hold — they leave no room horizontally
  10. Reladraw keeps boxes from overlapping, and you never write that rule. When two boxes collide, Reladraw reads the chains of placements your file already wrote. If those chains let one box move away from the other in only one direction, Reladraw uses that direction. Reladraw adds one more minimum distance and solves the whole layout again from scratch. In this file, a wide box sits under the small box in the middle, and the wide box's top edge overlaps the bottom of the tall box on the left. Sliding the wide box sideways would clear the overlap in sixty-one and a half pixels. Pushing it down takes fourteen pixels, so Reladraw pushes it down. Reladraw's syntax guide, the project's manual for the language, calls picking the smaller move the one place the tool decides something you didn't write. In the next file, Queue and Worker both sit below Hub, Worker with a tighter gap, and the two boxes land on each other. The file never says which one goes where, so Reladraw stops and names both boxes. The syntax guide states the rule for that case. The tool refuses and names the pair rather than guessing.

    Slide text

    Colliding boxes move only in a direction your file already implies

    if overlap were allowed
    what reladraw draws
    how far each move would take
    sideways
    61.5 px
    down
    14 px
    the smaller move wins
    "queue" and "worker" overlap, and nothing says which side of the other either one sits on — place one against the other, or say overlap: allow
    “the tool refuses and names the pair rather than guessing”
    — reladraw’s syntax guide
  11. Same five statements, two new looks. On the left is Solarized Light, and on the right is Dracula, two of the preset themes Reladraw ships with. I like the backstory on the themes. On Hacker News, the tech forum where Joe Walsh launched Reladraw, one reader wrote that they wished it had different themes. Joe Walsh answered that preset themes would be a priority, and pushed them about an hour and a half after the request.

    Slide text

    Thirteen preset themes shipped about ninety minutes after a Hacker News reader asked for them

    solarized-light
    dracula
    drawn by reladraw, same file
    “I wish it had different themes…”
    — a Hacker News reader
  12. The catch I'd plan around is the syntax. Reladraw is changing fast. This line comes from one of the project's own example files, as it stood on launch day. The line gives one style a dimmer text colour with the word muted. Today's build refuses that whole file. The error points at the line and tells you the new word to write, theme muted. Joe Walsh rewrote that line the same way in his own copy of the file. The README warns that the language isn't stable yet, so expect the syntax to change. When a word does change, Reladraw stops at that line and quotes the replacement, so you know exactly what to edit.

    Slide text

    A diagram file from launch day already fails on today’s build

    the project’s own example file, launch day
    style dim text: (color: muted)
    what today’s build prints
    style "dim": `muted` is now `theme-muted` — every color that follows the theme begins `theme-`
    “The language isn’t stable yet, so expect the syntax to change.”
    — reladraw’s README
  13. Back to those forty-four statements with zero coordinates. The count holds up. That's twenty-seven boxes, twelve arrows, and five style lines that set colours and shapes. Eleven of the twelve arrows name the side they leave from and the side they land on. Ten of the box lines ask for a tight gap. Those hints do some of the steering that coordinates used to do. I don't count those hints against Reladraw. You still decide every relationship yourself, and Reladraw takes the arithmetic off your hands.

    Slide text

    The 44 statements hold zero coordinates, and many of them still steer the layout by hand

    27 boxes 12 arrows 5 style lines
    19 node cluster.desktop1 "Desktop 1 / Linux" above-left of cluster.hub gap: tight badge: desktop 25 node cluster.laptop1 "Laptop 1 / macOS" below-left of cluster.hub gap: tight badge: laptop 31 edge cluster.desktop1.files <-> cluster.hub style: synced from: right to: top 33 edge cluster.laptop1.files <-> cluster.hub style: synced from: right to: bottom 64 edge server.deploy -> server.docker "compose up" 66 edge server.docker.db1 -> dumps.db1 from: right to: left
    six of the 44 lines, from reladraw’s example file
    11 of 12 arrows name both sides 10 lines ask for a tight gap
  14. The sharpest pushback came from a Hacker News reader, who said Reladraw works a lot like tikz, a drawing package scientists use in their papers. The reader added: with tikz it was never the nodes that hurt me, it was the edges. Nodes and edges mean the boxes and the lines. Other readers brought up D2 and Graphviz, which already let you nudge a layout. D2 has a keyword called near, for one box near another, and D2's own docs call it a hint to the layout engine. Graphviz can pin a set of boxes to the same row. Reladraw treats a position as a fact. You decide where every box goes, and the engine only works out the distances.

    Slide text

    D2 treats a position as a hint, and reladraw treats it as a fact

    “With tikz it was never the nodes that hurt me, it was the edges.”
    — a Hacker News reader
    D2
    near another shape is a hint to the layout engine
    D2’s docs
    Graphviz
    pin boxes to the same row
    reladraw
    you place it, the engine only works out distances
  15. That same Hacker News reader asked whether Reladraw does any line routing, meaning steering an arrow around the boxes in its way. On launch day, Joe Walsh answered that it doesn't route around obstacles. Here's what that meant. The arrow from Client to Database ran straight through Gateway, and the arrow's label covered Gateway's name. About a day and a half later, Joe Walsh shipped a build that draws the same file like this. The arrow arcs over Gateway and lands on top of Database. I love that a launch-day question turned into a fix that fast. The changelog, the project's list of what changed in each release, says it in one line. A line never passes through a box. Every arrow now takes the shortest way around whatever sits in its path, and when two ways tie, the arrow goes over the top. I'd still steer my important arrows myself. You can name the sides an arrow leaves and lands on, or the boxes it passes above or below.

    Slide text

    About a day and a half after launch, arrows stopped running through boxes

    launch day
    drawn by reladraw
    “It doesn’t auto-route around obstacles.”
    — Joe Walsh on Hacker News, launch day
    today’s build, same file
    drawn by reladraw
    “A line never passes through a box.”
    — reladraw’s changelog
  16. Here's where I'd put Reladraw next to the others. In Mermaid and D2 you describe what's connected, and the tool decides the picture. Pikchr is an older diagram language with a cursor that drops a shape and steps along, so you steer every step. In draw.io you drag every box by hand. In Reladraw you say which side of what each box sits on, and the tool works out the distances. On Hacker News, Joe Walsh put the difference from pikchr this way. In Reladraw, adding or resizing one box adjusts the rest, without spelling the positions out again.

    Slide text

    Four ways to lay out a diagram, and where reladraw sits

    you write
    who decides where boxes go
    Mermaid, D2
    boxes and arrows
    the tool
    pikchr
    each step of a cursor
    you, one step at a time
    draw.io
    nothing, you drag
    you, by hand
    reladraw
    where each box sits, in words
    you decide sides, the tool works out distances
  17. Should you try it? If you keep architecture diagrams in a repo, and you're tired of re-dragging boxes, I'd try Reladraw this weekend. The browser playground needs no install, so your first half hour costs you nothing. I'd wait if you need the syntax to hold still. Reladraw is only a few weeks old, it comes from one developer, and I'd expect a few of my files to need an edit along the way. And if Mermaid's automatic layout already looks fine to you, you don't need Reladraw.

    Slide text

    Who should try reladraw this weekend, and who should wait

    try it this weekend
    architecture diagrams in a repo
    tired of re-dragging boxes
    wait
    you need the syntax to hold still
    skip
    Mermaid’s automatic layout already looks fine to you
  18. The fastest way in is the browser playground, with your text on the left and the diagram redrawing on the right. You can also install Reladraw from npm, the package installer that comes with Node, the program that runs JavaScript outside a browser. Reladraw is free under the Apache 2.0 licence, so you can use it, change it and ship it, even at work. Which diagram in your repo would you rewrite first, and which box would you place first? Tell me in the comments. It's Reladraw slash Reladraw, on GitHub. New repo tomorrow.

    Slide text

    Try reladraw in the browser, or install it from npm

    reladraw’s playground
    browser playground npm Apache-2.0 an early build
    Which diagram in your repo would you rewrite first, and which box would you place first?
    github.com/reladraw/reladraw

What happened in AI today, in your inbox

One short email each evening. Read it and you’re caught up.

Built with ❤️ in New York