https://github.com/terrastruct/d2 Skip to content Toggle navigation Sign up * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code + Explore + All features + Documentation + GitHub Skills + Blog * Solutions + For + Enterprise + Teams + Startups + Compare all + By Solution + CI/CD & Automation + DevOps + DevSecOps + Case Studies + Customer Stories + Resources * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles + Repositories + Topics + Trending + Collections * Pricing [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this organization All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} terrastruct / d2 Public * Notifications * Fork 22 * Star 1.9k D2 is a modern diagram scripting language that turns text to diagrams. d2lang.com License MPL-2.0 license 1.9k stars 22 forks Star Notifications * Code * Issues 73 * Pull requests 4 * Discussions * Actions * Projects 1 * Security * Insights More * Code * Issues * Pull requests * Discussions * Actions * Projects * Security * Insights terrastruct/d2 This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. master Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags Name already in use A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch? Cancel Create 4 branches 2 tags Code * Local * Codespaces * Clone HTTPS GitHub CLI [https://github.com/t] Use Git or checkout with SVN using the web URL. [gh repo clone terras] Work fast with our official CLI. Learn more. * Open with GitHub Desktop * Download ZIP Sign In Required Please sign in to use Codespaces. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching Xcode If nothing happens, download Xcode and try again. Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @alixander alixander Merge pull request #144 from terrastruct/alixander/ lame-gif-again ... dc9cc25 Nov 22, 2022 Merge pull request #144 from terrastruct/alixander/lame-gif-again readme: update dc9cc25 Git stats * 282 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .github 2022-11-21 02:17:40PM Nov 21, 2022 ci v0.0.13 Nov 21, 2022 cmd PR comments Nov 21, 2022 d2ast [ci-base] cleanup Nov 15, 2022 d2chaos oss Nov 3, 2022 d2compiler Minor adjustment Nov 16, 2022 d2exporter oss Nov 3, 2022 d2format oss Nov 3, 2022 d2graph Rename From/To to Src/Dst Nov 16, 2022 d2layouts 2022-11-21 01:55:22PM Nov 21, 2022 d2oracle oss Nov 3, 2022 d2parser oss Nov 3, 2022 d2plugin 2022-11-16 04:48:46PM Nov 17, 2022 d2renderers 2022-11-21 04:32:58PM Nov 22, 2022 d2target oss Nov 3, 2022 d2themes [ci-base] cleanup Nov 15, 2022 docs 2022-11-22 09:41:43AM Nov 22, 2022 e2etests 2022-11-21 02:15:19PM Nov 21, 2022 lib PR comments Nov 21, 2022 testdata Rename From/To to Src/Dst Nov 16, 2022 .gitattributes [ci-base] linguist-vendor more Nov 15, 2022 .gitignore oss Nov 3, 2022 .gitmodules oss Nov 3, 2022 LICENSE.txt oss Nov 3, 2022 Makefile ci: Many more fixes Nov 20, 2022 README.md Update README.md Nov 22, 2022 c.go oss Nov 3, 2022 d2.go oss Nov 3, 2022 go.mod typecast, fix fmt Nov 21, 2022 go.sum Merge branch 'master' into bernie/export-png Nov 21, 2022 install.sh install.sh: --uninstall implies uninstall tala too Nov 21, 2022 make.sh oss Nov 3, 2022 View code [ ] A modern diagram scripting language that turns text to diagrams. Table of Contents What does D2 look like? Quickstart Install D2 as a library Themes Fonts Export file types Language tooling Plugins Comparison Contributing License Related VSCode extension Vim extension Language docs Misc FAQ README.md D2 A modern diagram scripting language that turns text to diagrams. Language docs | Cheat sheet ci release discord twitter license D2 CLI Table of Contents * What does D2 look like? * Quickstart * Install * D2 as a library * Themes * Fonts * Export file types * Language tooling * Plugins * Comparison * Contributing * License * Related + VSCode extension + Vim extension + Misc * FAQ What does D2 look like? # Actors hans: Hans Niemann defendants: { mc: Magnus Carlsen playmagnus: Play Magnus Group chesscom: Chess.com naka: Hikaru Nakamura mc -> playmagnus: Owns majority playmagnus <-> chesscom: Merger talks chesscom -> naka: Sponsoring } # Accusations hans -> defendants: 'sueing for $100M' # Offense defendants.naka -> hans: Accused of cheating on his stream defendants.mc -> hans: Lost then withdrew with accusations defendants.chesscom -> hans: 72 page report of cheating There is syntax highlighting with the editor plugins linked below. D2 render example Quickstart The most convenient way to use D2 is to just run it as a CLI executable to produce SVGs from .d2 files. # First, install D2 curl -fsSL https://d2lang.com/install.sh | sh -s -- echo 'x -> y -> z' > in.d2 d2 --watch in.d2 out.svg A browser window will open with out.svg and live-reload on changes to in.d2. Install The easiest way to install is with our install script: curl -fsSL https://d2lang.com/install.sh | sh -s -- To uninstall: curl -fsSL https://d2lang.com/install.sh | sh -s -- --uninstall For detailed installation docs, with alternative methods and examples for each OS, see ./docs/INSTALL.md. D2 as a library In addition to being a runnable CLI tool, D2 can also be used to produce diagrams from Go programs. import ( "github.com/terrastruct/d2/d2compiler" "github.com/terrastruct/d2/d2exporter" "github.com/terrastruct/d2/d2layouts/d2dagrelayout" "github.com/terrastruct/d2/d2renderers/textmeasure" "github.com/terrastruct/d2/d2themes/d2themescatalog" ) func main() { graph, err := d2compiler.Compile("", strings.NewReader("x -> y"), &d2compiler.CompileOptions{ UTF16: true }) ruler, err := textmeasure.NewRuler() err = graph.SetDimensions(nil, ruler) err = d2dagrelayout.Layout(ctx, graph) diagram, err := d2exporter.Export(ctx, graph, d2themescatalog.NeutralDefault) ioutil.WriteFile(filepath.Join("out.svg"), d2svg.Render(*diagram), 0600) } D2 is built to be hackable -- the language has an API built on top of it to make edits programmatically. import ( "github.com/terrastruct/d2/d2oracle" "github.com/terrastruct/d2/d2format" ) // ...modifying the diagram `x -> y` from above // Create a shape with the ID, "meow" graph, err = d2oracle.Create(graph, "meow") // Style the shape green graph, err = d2oracle.Set(graph, "meow.style.fill", "green") // Create a shape with the ID, "cat" graph, err = d2oracle.Create(graph, "cat") // Move the shape "meow" inside the container "cat" graph, err = d2oracle.Move(graph, "meow", "cat.meow") // Prints formatted D2 code println(d2format.Format(graph.AST)) This makes it easy to build functionality on top of D2. Terrastruct uses the above API to implement editing of D2 from mouse actions in a visual interface. Themes D2 includes a variety of official themes to style your diagrams beautifully right out of the box. See ./d2themes to browse the available themes and make or contribute your own creation. Fonts D2 ships with "Source Sans Pro" as the font in renders. If you wish to use a different one, please see ./d2renderers/d2fonts. Export file types D2 currently supports SVG exports. More coming soon. Language tooling D2 is designed with language tooling in mind. D2's parser can parse multiple errors from a broken program, has an autoformatter, syntax highlighting, and we have plans for LSP's and more. Good language tooling is necessary for creating and maintaining large diagrams. The extensions for VSCode and Vim can be found in the Related section. Plugins D2 is designed to be extensible and composable. The plugin system allows you to change out layout engines and customize the rendering pipeline. Plugins can either be bundled with the build or separately installed as a standalone binary. Layout engines: * dagre (default, bundled): A fast, directed graph layout engine that produces layered/hierarchical layouts. Based on Graphviz's DOT algorithm. * ELK (bundled): A directed graph layout engine particularly suited for node-link diagrams with an inherent direction and ports. * TALA (binary): Novel layout engine designed specifically for software architecture diagrams. Requires separate install, visit the Github page for more. D2 intends to integrate with a variety of layout engines, e.g. dot, as well as single-purpose layout types like sequence diagrams. You can choose whichever layout engine you like and works best for the diagram you're making. Comparison For a comparison against other popular text-to-diagram tools, see https://text-to-diagram.com. Contributing Contributions are welcome! See ./docs/CONTRIBUTING.md. License Open sourced under the Mozilla Public License 2.0. See ./LICENSE.txt. Related VSCode extension https://github.com/terrastruct/d2-vscode Vim extension https://github.com/terrastruct/d2-vim Language docs https://github.com/terrastruct/d2-docs Misc * https://github.com/terrastruct/text-to-diagram-site FAQ * Does D2 collect telemetry? + No, D2 does not use an internet connection after installation, except to check for version updates from Github periodically. * Does D2 need a browser to run? + No, D2 can run entirely server-side. * I have a question or need help. + The best way to get help is to ask on D2 Discord * I have a feature request, proposal, or bug report. + Please open up a Github Issue. * I have a private inquiry. + Please reach out at hi@d2lang.com. About D2 is a modern diagram scripting language that turns text to diagrams. d2lang.com Topics go golang diagrams software-architecture diagramming text-to-diagram Resources Readme License MPL-2.0 license Stars 1.9k stars Watchers 10 watching Forks 22 forks Releases 2 v0.0.13 Latest Nov 21, 2022 + 1 release Packages 0 No packages published Contributors 5 * @alixander * @nhooyr * @gavin-ts * @berniexie * @ejulio-ts Languages * Go 89.7% * Shell 9.4% * JavaScript 0.4% * Roff 0.2% * HTML 0.1% * Makefile 0.1% * Other 0.1% Footer (c) 2022 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.