⏱️ Lectura: 9 min

Terrastruct just released the source code for TALA, the autolayout algorithm D2 uses to arrange architecture diagrams without anyone having to move boxes by hand. It now runs under the MPL-2.0 license, the same one D2 uses, and comes built in by default starting with version 0.9.0 of the language.

📑 En este artículo
  1. TL;DR
  2. Introduction
  3. What Happened
  4. Context and History
  5. Technical Details and Performance
  6. Getting Started
  7. Impact and Analysis
  8. What’s Next
  9. Frequently Asked Questions
    1. What does TALA stand for?
    2. Do I need to install TALA separately?
    3. Does TALA replace Dagre and ELK?
    4. Why does the same diagram look different every time I add a node?
    5. Is TALA useful for AI-generated diagrams?
    6. What license is TALA under now?
  10. References

Until now, TALA was the proprietary piece of an otherwise open project. With this announcement, D2 is now completely open source from end to end: from the parser to the final rendering.

TL;DR

  • TALA (Terrastruct’s AutoLayout Algorithm) is now open source under the MPL-2.0 license, the same one D2 uses.
  • It’s included in D2 starting with version 0.9.0 and is enabled with the –layout=tala flag.
  • It’s an orthogonal layout engine designed for whiteboard-style architecture diagrams, not for long DAG graphs.
  • It lets you fix top and left coordinates on specific nodes and leave the rest to the automatic engine (hybrid positioning).
  • It uses 3 random seeds by default and picks the layout with the best score: the same input and seeds produce the same diagram.
  • The playground at https://play.d2lang.com runs 100% in the browser and lets you try TALA without installing anything.
  • The performance benchmarks repository is published at github.com/d2lang/d2-benchmarks.
  • Gavin Nishizawa and Júlio César Batista led much of the development, according to Terrastruct’s official announcement.

Introduction

D2 is a text-based diagramming language: you write a few lines describing boxes and arrows, and D2 generates the SVG. Its direct competitor is Mermaid, but D2 set itself apart from the start with the visual quality of its automatic layouts.

Much of that quality came from TALA, an autolayout engine that Terrastruct developed in-house and kept closed while the rest of D2 was already MIT-licensed. That changed this week.

What Happened

Terrastruct published TALA’s code in the same D2 GitHub repository, under the Mozilla Public License 2.0. This follows up on a previous announcement where the company had already hinted this was coming.

The repository explains that TALA combines ideas from several graph drawing papers (cited directly in the source code) with its own techniques to produce more readable diagrams. The stated goal is to optimize several “aesthetic” metrics at once: symmetry, median distance between connected nodes, flow direction, and clustering of similar nodes.

Terrastruct explicitly thanks Gavin Nishizawa for extensive contributions to TALA and Júlio César Batista for his work on the hierarchy algorithms. The project now accepts external contributions from the D2 community.

Context and History

D2 already included two layout engines from the start: Dagre and ELK, both based on directed acyclic graphs (DAG). They work well for diagrams that grow in one direction: pipelines, data flows, dependency trees.

The problem is that a real software architecture diagram almost never grows in a single direction. It looks more like something you’d draw on a whiteboard: boxes everywhere, connections crossing in multiple directions. For that case, Terrastruct built TALA as an orthogonal layout engine, designed from scratch with software architecture diagrams in mind.

Comparison of diagrams generated with TALA, Dagre, and ELK in D2
TALA prioritizes symmetry and clustering; Dagre and ELK prioritize flow direction. Foto de Lakshmi Narasimha en Unsplash

Terrastruct tested TALA against public D2 files pulled from GitHub, without manual selection. The company clarifies that in some cases the Dagre or ELK layout may still be preferable: it’s not that TALA always wins, it’s that it tackles a different problem.

Technical Details and Performance

TALA doesn’t produce a single deterministic layout per diagram. By default it tries 3 random seeds, generates a candidate layout for each one, scores them according to the aesthetic metrics mentioned above, and keeps the best one. The same input and the same seeds always produce the same result.

Here’s the uncomfortable part: adding a single node can completely change the diagram’s layout, because the seeds explore the solution space again. Dagre and ELK, on the other hand, tend to keep the previous layout and just fit the new node into place.

⚠️ Heads up: if you need a large diagram to keep a stable shape as you add nodes to it over time (for example, documentation that gets updated frequently), Dagre or ELK are more predictable than TALA.

Another capability exclusive to TALA is fixing the position of individual nodes with the top and left keys, letting the engine solve the rest (including connection routing). Terrastruct points to a concrete use case: generative AI models can place boxes reasonably well on a 2D plane, but they fail at drawing the connecting lines without crossing them. TALA solves exactly that second part.

EngineWhen to Use ItAdvantageLimitation
DagrePipelines, CI/CD flows, graphs that grow in one directionStable layout when adding new nodesLittle aesthetic control in non-linear diagrams
ELKLarge hierarchies with many nested levelsGood handling of hierarchical subgraphsPrioritizes direction over whiteboard-style aesthetics
TALAArchitecture diagrams with crossing connectionsOptimizes symmetry and clustering, and allows fixing coordinatesRandomness between runs; slower on large diagrams

On performance, Terrastruct is upfront: TALA scales non-linearly and takes longer than Dagre or ELK on large diagrams. The reference benchmark is published at github.com/d2lang/d2-benchmarks, where anyone can run their own measurements against their hardware.

Getting Started

TALA doesn’t need to be installed separately: it comes bundled inside D2 starting with version 0.9.0. You just need to install D2 and pass the corresponding flag.

# macOS (Homebrew)
brew install d2

# Linux
curl -fsSL https://d2lang.com/install.sh | sh -s --

# Windows (with Scoop)
scoop install d2

With D2 installed, a minimal diagram looks like this. Save it as arquitectura.d2:

frontend -> api_gateway: HTTP request
api_gateway -> auth_service: validates token
api_gateway -> orders_service: creates order
orders_service -> database: INSERT
orders_service -> cache: invalidates key

And to render it using TALA instead of the default engine:

d2 --layout=tala arquitectura.d2 arquitectura.svg

This command generates arquitectura.svg with TALA’s orthogonal layout, instead of the default Dagre. For hybrid positioning (some nodes fixed, the rest automatic), D2 supports fixing coordinates directly on the node:

estacion_cyan: {
  top: 0
  left: 0
}
estacion_magenta: {
  top: 0
  left: 200
}
estacion_amarillo: {
  top: 0
  left: 400
}
estacion_negro: {
  top: 0
  left: 600
}
controlador_registro -> estacion_cyan
controlador_registro -> estacion_magenta
controlador_registro -> estacion_amarillo
controlador_registro -> estacion_negro
D2 diagram with nodes manually positioned using TALA
Fixing top and left on some nodes leaves the routing up to TALA. Foto de Syna Tiger Resort en Unsplash

Here the four top nodes stay pinned in their row, while TALA only calculates the routing of the connections toward the controller. This is exactly the pattern Terrastruct describes for diagrams generated by AI agents.

To confirm your installation is actually using TALA (and not falling back to Dagre due to an old version), check your D2 version before rendering:

d2 --version
# should report 0.9.0 or higher

If the binary reports a version earlier than 0.9.0, the --layout=tala flag doesn’t exist yet and you’ll need to update D2 first.

💡 Tip: if you want to try TALA without installing anything, the play.d2lang.com playground runs the full compiler in the browser, TALA included.

Impact and Analysis

The most significant change isn’t about licensing but about maintenance: until now, any bug fix or improvement to TALA depended exclusively on the Terrastruct team. With the code open, the D2 community can send pull requests directly against the layout engine, something that was previously impossible.

It also reduces the typical risk of tools with a proprietary core: if Terrastruct as a company changed direction, D2 would no longer depend on a closed piece for its most distinctive functionality. It’s the same argument behind the full migration of projects like open source tools in general: fewer single points of organizational failure.

The agentic use case Terrastruct mentions deserves separate attention. As more teams generate architecture diagrams with AI assistants from a text description, the hard part stops being “where to put each box” and becomes “how to route the connections without crossing them.” TALA tackles exactly that second problem, leaving coarse placement to the model and fine-grained routing to the algorithm.

What’s Next

Terrastruct says it’s looking forward to the improvements the community proposes now that the code is public, particularly around handling large diagrams, where TALA’s non-linear performance remains its weakest point compared to Dagre and ELK.

There’s no roadmap with public dates beyond that. The most direct way to follow development is the D2 GitHub repository itself, where TALA now lives alongside the rest of the compiler.

📖 Summary on Telegram: View summary

Try it yourself: install D2 with brew install d2 (or the Linux script) and run your first diagram with d2 --layout=tala to compare the result against Dagre.

Frequently Asked Questions

What does TALA stand for?

It stands for Terrastruct’s AutoLayout Algorithm, the orthogonal layout engine Terrastruct built for D2.

Do I need to install TALA separately?

No. It’s included inside D2 starting with version 0.9.0 and is enabled with the --layout=tala flag.

Does TALA replace Dagre and ELK?

No. D2 still supports all three engines. TALA works best for architecture diagrams with crossing connections; Dagre and ELK are still better for graphs that grow in a single direction.

Why does the same diagram look different every time I add a node?

Because TALA tries 3 random seeds by default and picks the one with the best score. Adding a node changes the search space and can produce a completely different layout.

Is TALA useful for AI-generated diagrams?

Yes, it’s one of the use cases Terrastruct highlights: a model can place nodes at 2D coordinates and let TALA handle the connection routing, a task models tend to struggle with.

What license is TALA under now?

MPL-2.0, the same license the rest of D2 already used.

References

📱 Enjoy this content? Follow @programacion on Telegram for daily tech content in Spanish: quick summaries, fresh content every day.

Imagen destacada: Foto de GuerrillaBuzz en Unsplash

Categories: Programación

Andrés Morales

Developer and AI researcher. Writes about language models, frameworks, developer tooling, and open source releases. Covers ML papers, the tech startup ecosystem, and programming trends.

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.