One diagram instead of a dozen pages: a visual call flow editor built on React Flow
20 October 2026 · 15 min read
- React
- React Flow
- UX
- TypeScript
Call routing in a cloud phone system is made of small pieces. A phone number rings a phone menu. The menu sends key 1 to a ring team and key 2 to a waiting line. Outside opening hours, a message plays and the caller ends up in voicemail. Each piece is simple. The call is the sum of them.
The product I work on had one settings page per piece: phone numbers, phone menus, opening hours, extensions, ring teams, waiting lines, forwarding, voicemail, conference rooms, messages, and a few more. A dozen entries under Call Routing in the sidebar.
Where customers got lost
Every page was fine on its own. The trouble was in between them.
To set up “calls go to the menu during the day, to voicemail at night”, a customer had to create the voicemail first, then the closed-hours message pointing at it, then the menu, then the opening hours rule pointing at both, and finally point the phone number at the rule. Five pages, in that order, because each record can only point at something that already exists.
And once it was built, nobody could see it. The only place the routing existed as a whole was in the customer’s head. A question like “what happens if someone presses 2 at 7 pm?” meant opening four pages and following the Destination dropdowns by hand. Support tickets were full of exactly that: a call ending up somewhere unexpected because one pointer on one page pointed at the wrong thing.
People read a diagram faster than a list of settings. If someone draws a call on a whiteboard, they draw boxes and arrows, not five forms. So that is what we built: a Call Flow Studio where the whole call is one picture.
The Studio: the call as a picture
Every box is one routing record. Every outlet on a box is one of its exits: a menu has an outlet per key, opening hours has Open and Closed, a waiting line has Timeout, No agents and Queue full. Every line is one pointer: “this exit sends the call there”. The question “what happens if someone presses 2 at 7 pm?” now takes a glance: follow Closed Hours.
Building a flow is drag, drop and connect. A node comes from the palette on the right, and you pull a line from an exit to the next node:
Clicking a node opens the same form its own page would show, in the side panel. You can pick an existing record (“use the Sales team ring team”) or create a new one right there, without leaving the canvas.
One rule: the diagram is a view, not a second copy
The decision that shaped everything else: the Studio does not store its own routing. A flow is a projection of the same records the dozen pages edit. The old pages are still there, and they edit the same rows. Change a ring team’s exit on its page, and the line moves in the Studio. Draw a new line in the Studio, and the ring team’s page shows the new destination.
We could have stored the flow as a JSON document and compiled it into routing on save. That is easier to build, and it guarantees two truths that drift apart: the diagram says one thing and the call does another. Customers would trust neither.
So the mapping is direct:
- A node is a row, identified by a key like
ring_team:rt_8f2(kind plus id). - An edge is a pointer on the source row: a ring team’s “no answer” exit is its
exit_kind+exit_idcolumns. - A handle is the name of the exit:
default,timeout,matchandno_match,digit:1. - The only thing the flow owns is where the boxes sit: a map from node key to
{ x, y }.
That last point matters. Customers arrange their diagrams by hand, and they want the boxes to stay where they put them. Positions are layout, not routing, so they are the one thing stored on the flow itself.
React Flow does the canvas
The canvas is React Flow: panning, zooming, selection, handles and edge drawing come for free. What we wrote is the domain on top.
One custom node type for everything. Every kind of record renders through the same StudioNode component: an icon, a title, the record’s name, and a row per exit, each with its own source handle. A config table says what each kind looks like:
export const NODE_CONFIG: Record<NodeType, NodeConfig> = {
[NodeType.Menu]: {
label: "Phone Menu",
hasInput: true,
outputType: "multiple",
outputs: [
{ id: "default", label: "Default" },
{ id: "key-1", label: "Key 1" },
// … keys 0–9, * and #
],
},
[NodeType.Voicemail]: { label: "Voicemail", hasInput: true, outputType: "none" },
// …
}
Adding a new kind of record to the Studio is one entry here, one form, and one schema.
Drag and drop from the palette is the browser’s own drag API. The palette item puts the node type in the drag data, and the canvas turns the drop point into canvas coordinates with React Flow’s screenToFlowPosition, so it lands in the right place at any zoom level:
const handleDrop = (event: React.DragEvent) => {
event.preventDefault()
const type = event.dataTransfer.getData("application/reactflow")
if (!isNodeType(type)) return
const position = screenToFlowPosition({ x: event.clientX, y: event.clientY })
addNode(type, position)
}
State lives in a store, not in React Flow. Nodes, edges, the selected node and an undo history sit in a zustand store, and React Flow only renders them. That keeps the save logic, validation and undo out of components and testable on their own.
Auto-Arrange: ELK draws the boxes for you
A flow loaded for the first time has no positions yet: it came from records created on the old pages. And a flow you have been editing for an hour tends to look like a plate of spaghetti. Both need the same thing: a sensible layout, computed.
React Flow deliberately leaves layout to you. We use ELK (through elkjs) with its layered algorithm, left to right, the way people read a call:
const graph = {
id: "root",
children: nodes.map((node) => ({
id: node.id,
width: NODE_WIDTH,
height: heightOf(node), // a menu with 12 keys is taller than a voicemail
ports: portsOf(node), // one port per exit, in display order
layoutOptions: { "elk.portConstraints": "FIXED_ORDER" },
})),
edges,
layoutOptions: {
"elk.algorithm": "layered",
"elk.direction": "RIGHT",
"elk.layered.crossingMinimization.strategy": "LAYER_SWEEP",
"elk.layered.nodePlacement.strategy": "NETWORK_SIMPLEX",
"elk.spacing.nodeNode": "80",
"elk.layered.spacing.nodeNodeBetweenLayers": "100",
},
}
The detail that made the result readable: ports with a fixed order. Without them, ELK treats a node as a point and connects lines to wherever is shortest, so “Key 3” can end up drawn above “Key 1”. With one port per exit in display order, the lines leave each box in the same order the labels show, and ELK minimises crossings around that.
Layout runs automatically for nodes that have no saved position, and on demand from the Auto-Arrange Flow button. Positions you set by hand are saved with the flow, so a reopened flow looks exactly as you left it.
Validation: point at the box that is wrong
On the old pages, a form could not be saved until it was valid. On a canvas you build in any order, that would be maddening: you drop five boxes, then fill them in. So the Studio lets you draw freely and checks everything when you press Save.
Each node kind has a zod schema, the same one its form uses. Save runs every node through its schema; the invalid ones turn red, and a click on one opens its form with the field that needs attention:
export function validateNodeConfig(type: NodeType, config: unknown): ZodError | null {
const schema = FORM_SCHEMAS[type]?.schema(t)
if (!schema) return null
const result = schema.safeParse(config)
return result.success ? null : result.error
}
One rule kept this from getting in the way: only nodes created or edited in this session are checked. A record loaded with the flow, or picked as an existing one, is not written by the save, and it may hold values another screen allowed. Blocking a save on something the customer never touched would be a bug report waiting to happen.
Saving: records first, then the picture
Because the flow is a view over records, saving is two steps, in a fixed order:
- Write the records. A node dragged in from the palette has no row yet, and a line cannot point at something that does not exist. So new nodes are created and edited ones updated first, and every node ends up with a real id.
- Send the graph. Then one request sends the node keys, the edges as pointers, and the layout. The server applies the pointers to the rows in one go.
- Guard against the other tab. The graph request carries the flow’s version tag. If a colleague saved the same flow in the meantime, the save is refused instead of silently overwriting their change.
A small detail that followed from the order: after a successful save, the undo history is cleared. Undoing past a save would bring back nodes without the ids that were just created, and the next save would create those records a second time. Losing undo across a save is a much smaller surprise than a duplicate ring team.
What changed for customers
The pages are still there, and some people still prefer them for a quick edit. But setting up routing, and above all understanding it, moved to the diagram.
- The order problem is gone. You draw the call in the order you think about it, start to end, and the save works out the order the records must be created in.
- “Where does this call go?” is answered by looking, not by opening four pages.
- Mistakes are visible. A key that leads nowhere, or a voicemail no one can reach, shows up as a missing or dangling line instead of hiding in a dropdown.
The lesson I keep coming back to: we didn’t add any new routing features. Every capability in the Studio already existed on the dozen pages. What we changed was the shape of the interface, from a list of settings to a picture of the call, and that alone turned “I’m lost” into “oh, I see”.