2022-11-03 13:54:49 +00:00
|
|
|
<div align="center">
|
2022-11-22 00:49:00 +00:00
|
|
|
<img src="./docs/assets/banner.png" alt="D2" />
|
|
|
|
|
<h2>
|
2022-11-22 00:48:22 +00:00
|
|
|
A modern diagram scripting language that turns text to diagrams.
|
2022-11-22 00:49:00 +00:00
|
|
|
</h2>
|
2022-11-03 13:54:49 +00:00
|
|
|
|
2022-12-17 03:38:26 +00:00
|
|
|
|
|
|
|
|
[Docs](https://d2lang.com) | [Cheat sheet](./docs/assets/cheat_sheet.pdf) | [Comparisons](https://text-to-diagram.com) | [Playground](https://play.d2lang.com)
|
2022-11-03 13:54:49 +00:00
|
|
|
|
|
|
|
|
[](https://github.com/terrastruct/d2/actions/workflows/ci.yml)
|
2022-12-08 07:56:43 +00:00
|
|
|
[](https://github.com/terrastruct/d2/actions/workflows/daily.yml)
|
2022-11-03 13:54:49 +00:00
|
|
|
[](https://github.com/terrastruct/d2/releases)
|
2022-11-09 21:59:00 +00:00
|
|
|
[](https://discord.gg/NF6X8K4eDq)
|
|
|
|
|
[](https://twitter.com/terrastruct)
|
2022-11-03 13:54:49 +00:00
|
|
|
[](./LICENSE.txt)
|
|
|
|
|
|
2022-12-17 03:38:26 +00:00
|
|
|
<a href="https://play.d2lang.com">
|
|
|
|
|
<img src="./docs/assets/playground_button.png" alt="D2 Playground button" width="200" />
|
|
|
|
|
</a>
|
|
|
|
|
|
2022-12-07 08:17:03 +00:00
|
|
|
https://user-images.githubusercontent.com/3120367/206125010-bd1fea8e-248a-43e7-8f85-0bbfca0c6e2a.mp4
|
2022-11-03 13:54:49 +00:00
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
# Table of Contents
|
|
|
|
|
|
|
|
|
|
<!-- toc -->
|
2022-12-01 16:25:05 +00:00
|
|
|
- <a href="#what-does-d2-look-like" id="toc-what-does-d2-look-like">What does D2 look like?</a>
|
|
|
|
|
- <a href="#quickstart" id="toc-quickstart">Quickstart</a>
|
|
|
|
|
- <a href="#install" id="toc-install">Install</a>
|
|
|
|
|
- <a href="#d2-as-a-library" id="toc-d2-as-a-library">D2 as a library</a>
|
|
|
|
|
- <a href="#themes" id="toc-themes">Themes</a>
|
|
|
|
|
- <a href="#fonts" id="toc-fonts">Fonts</a>
|
|
|
|
|
- <a href="#export-file-types" id="toc-export-file-types">Export file types</a>
|
|
|
|
|
- <a href="#language-tooling" id="toc-language-tooling">Language tooling</a>
|
|
|
|
|
- <a href="#plugins" id="toc-plugins">Plugins</a>
|
|
|
|
|
- <a href="#comparison" id="toc-comparison">Comparison</a>
|
|
|
|
|
- <a href="#contributing" id="toc-contributing">Contributing</a>
|
|
|
|
|
- <a href="#license" id="toc-license">License</a>
|
|
|
|
|
- <a href="#related" id="toc-related">Related</a>
|
2022-12-17 03:50:12 +00:00
|
|
|
- <a href="#official-plugins" id="toc-official-plugins">Official plugins</a>
|
|
|
|
|
- <a href="#community-plugins" id="toc-community-plugins">Community plugins</a>
|
2022-12-01 16:25:05 +00:00
|
|
|
- <a href="#misc" id="toc-misc">Misc</a>
|
|
|
|
|
- <a href="#faq" id="toc-faq">FAQ</a>
|
2023-01-15 08:37:12 +00:00
|
|
|
- <a href="#open-source-projects-documenting-with-d2" id="toc-open-source-projects-documenting-with-d2">Open-source projects documenting with D2</a>
|
2022-11-03 13:54:49 +00:00
|
|
|
|
2022-12-01 05:53:01 +00:00
|
|
|
## What does D2 look like?
|
2022-11-22 17:20:03 +00:00
|
|
|
|
|
|
|
|
```d2
|
|
|
|
|
# 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
|
|
|
|
|
```
|
|
|
|
|
|
2022-11-22 17:31:24 +00:00
|
|
|
> There is syntax highlighting with the editor plugins linked below.
|
2022-11-22 17:28:45 +00:00
|
|
|
|
2022-11-23 18:48:55 +00:00
|
|
|
<img src="./docs/assets/syntax.png" alt="D2 render example" />
|
2022-11-22 17:20:03 +00:00
|
|
|
|
2022-11-24 16:06:06 +00:00
|
|
|
> Rendered with the TALA layout engine.
|
|
|
|
|
|
2022-12-07 08:40:30 +00:00
|
|
|
> For more examples, see [./docs/examples](./docs/examples).
|
2022-11-23 21:04:26 +00:00
|
|
|
|
2022-11-15 01:05:05 +00:00
|
|
|
## Quickstart
|
2022-11-09 22:46:19 +00:00
|
|
|
|
2022-11-03 13:54:49 +00:00
|
|
|
The most convenient way to use D2 is to just run it as a CLI executable to
|
|
|
|
|
produce SVGs from `.d2` files.
|
|
|
|
|
|
|
|
|
|
```sh
|
2022-11-14 23:23:16 +00:00
|
|
|
# First, install D2
|
|
|
|
|
curl -fsSL https://d2lang.com/install.sh | sh -s --
|
|
|
|
|
|
2022-11-03 13:54:49 +00:00
|
|
|
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`.
|
|
|
|
|
|
2022-11-15 01:05:05 +00:00
|
|
|
## Install
|
2022-11-03 13:54:49 +00:00
|
|
|
|
2022-11-21 17:32:59 +00:00
|
|
|
The easiest way to install is with our install script:
|
2022-11-20 13:19:39 +00:00
|
|
|
|
2022-11-14 06:47:32 +00:00
|
|
|
```sh
|
|
|
|
|
curl -fsSL https://d2lang.com/install.sh | sh -s --
|
|
|
|
|
```
|
|
|
|
|
|
2022-12-01 11:51:06 +00:00
|
|
|
You can run the install script with `--dry-run` to see the commands that will be used
|
|
|
|
|
to install without executing them.
|
|
|
|
|
|
2022-12-01 20:59:53 +00:00
|
|
|
Or if you have Go installed you can install from source though you won't get the manpage:
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
go install oss.terrastruct.com/d2@latest
|
|
|
|
|
```
|
|
|
|
|
|
2022-12-06 08:31:36 +00:00
|
|
|
You can also install a release from source which will include manpages.
|
|
|
|
|
See [./docs/INSTALL.md#source-release](./docs/INSTALL.md#source-release).
|
|
|
|
|
|
2022-12-01 20:59:53 +00:00
|
|
|
To uninstall with the install script:
|
2022-11-14 06:47:32 +00:00
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
curl -fsSL https://d2lang.com/install.sh | sh -s -- --uninstall
|
|
|
|
|
```
|
|
|
|
|
|
2022-12-01 20:59:53 +00:00
|
|
|
For detailed installation docs, see [./docs/INSTALL.md](./docs/INSTALL.md).
|
|
|
|
|
We demonstrate alternative methods and examples for each OS.
|
|
|
|
|
|
|
|
|
|
As well, the functioning of the install script is described in detail to alleviate any
|
|
|
|
|
concern of its use. We recommend using your OS's package manager directly instead for
|
|
|
|
|
improved security but the install script is by no means insecure.
|
2022-11-21 17:33:20 +00:00
|
|
|
|
2022-11-15 01:05:05 +00:00
|
|
|
## D2 as a library
|
2022-11-09 22:46:19 +00:00
|
|
|
|
2022-11-03 13:54:49 +00:00
|
|
|
In addition to being a runnable CLI tool, D2 can also be used to produce diagrams from
|
|
|
|
|
Go programs.
|
|
|
|
|
|
2023-01-20 04:56:57 +00:00
|
|
|
For examples, see [./docs/examples/lib](./docs/examples/lib). This [blog
|
2023-01-20 05:01:28 +00:00
|
|
|
post](https://terrastruct.com/blog/post/generate-diagrams-programmatically/) also demos a
|
|
|
|
|
complete, runnable example of using D2 as a library for a real-world use case.
|
2022-11-03 13:54:49 +00:00
|
|
|
|
|
|
|
|
## Themes
|
|
|
|
|
|
|
|
|
|
D2 includes a variety of official themes to style your diagrams beautifully right out of
|
|
|
|
|
the box. See [./d2themes](./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](./d2renderers/d2fonts).
|
|
|
|
|
|
|
|
|
|
## Export file types
|
|
|
|
|
|
2022-12-19 04:33:33 +00:00
|
|
|
D2 currently supports SVG and PNG exports. More coming soon.
|
2022-11-03 13:54:49 +00:00
|
|
|
|
|
|
|
|
## 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](#related) section.
|
|
|
|
|
|
2022-11-12 18:03:32 +00:00
|
|
|
## Plugins
|
2022-11-03 13:54:49 +00:00
|
|
|
|
2022-11-12 18:03:32 +00:00
|
|
|
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.
|
2022-11-03 13:54:49 +00:00
|
|
|
|
2022-11-12 18:03:32 +00:00
|
|
|
**Layout engines**:
|
2022-11-03 13:54:49 +00:00
|
|
|
|
2022-11-12 18:03:32 +00:00
|
|
|
- [dagre](https://github.com/dagrejs/dagre) (default, bundled): A fast, directed graph
|
|
|
|
|
layout engine that produces layered/hierarchical layouts. Based on Graphviz's DOT
|
|
|
|
|
algorithm.
|
|
|
|
|
- [ELK](https://github.com/kieler/elkjs) (bundled): A directed graph layout engine
|
|
|
|
|
particularly suited for node-link diagrams with an inherent direction and ports.
|
|
|
|
|
- [TALA](https://github.com/terrastruct/TALA) (binary): Novel layout engine designed
|
2022-11-14 23:23:16 +00:00
|
|
|
specifically for software architecture diagrams. Requires separate install, visit the
|
|
|
|
|
Github page for more.
|
2022-11-12 18:03:32 +00:00
|
|
|
|
|
|
|
|
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.
|
2022-11-03 13:54:49 +00:00
|
|
|
|
|
|
|
|
## Comparison
|
|
|
|
|
|
|
|
|
|
For a comparison against other popular text-to-diagram tools, see
|
|
|
|
|
[https://text-to-diagram.com](https://text-to-diagram.com).
|
|
|
|
|
|
|
|
|
|
## Contributing
|
|
|
|
|
|
|
|
|
|
Contributions are welcome! See [./docs/CONTRIBUTING.md](./docs/CONTRIBUTING.md).
|
|
|
|
|
|
|
|
|
|
## License
|
|
|
|
|
|
2022-11-22 00:32:58 +00:00
|
|
|
Open sourced under the Mozilla Public License 2.0. See [./LICENSE.txt](./LICENSE.txt).
|
2022-11-03 13:54:49 +00:00
|
|
|
|
|
|
|
|
## Related
|
|
|
|
|
|
2022-12-10 01:26:12 +00:00
|
|
|
We are constantly working on new plugins, integrations, extensions. Contributions are
|
|
|
|
|
welcome in any official or community plugins. If you have somewhere in your workflow that
|
|
|
|
|
you want to use D2, feel free to open a discussion. We have limited bandwidth and usually
|
2022-12-10 01:28:11 +00:00
|
|
|
choose the most high-demand ones to work on. If you make something cool with D2 yourself,
|
|
|
|
|
let us know and we'll be happy to include it here!
|
2022-12-10 01:26:12 +00:00
|
|
|
|
2022-12-10 01:21:05 +00:00
|
|
|
### Official plugins
|
2022-11-03 13:54:49 +00:00
|
|
|
|
2022-12-10 01:21:05 +00:00
|
|
|
- **VSCode extension**: [https://github.com/terrastruct/d2-vscode](https://github.com/terrastruct/d2-vscode)
|
|
|
|
|
- **Vim extension**: [https://github.com/terrastruct/d2-vim](https://github.com/terrastruct/d2-vim)
|
|
|
|
|
- **Obsidian plugin**: [https://github.com/terrastruct/d2-obsidian](https://github.com/terrastruct/d2-obsidian)
|
2022-12-24 17:52:20 +00:00
|
|
|
- **Slack app**: [https://d2lang.com/tour/slack](https://d2lang.com/tour/slack)
|
2022-12-29 04:35:28 +00:00
|
|
|
- **Discord plugin**: [https://d2lang.com/tour/discord](https://d2lang.com/tour/discord)
|
2022-11-03 13:54:49 +00:00
|
|
|
|
2022-12-10 01:21:05 +00:00
|
|
|
### Community plugins
|
2022-11-03 13:54:49 +00:00
|
|
|
|
2022-12-10 01:21:05 +00:00
|
|
|
- **Tree-sitter grammar**: [https://github.com/pleshevskiy/tree-sitter-d2](https://github.com/pleshevskiy/tree-sitter-d2)
|
2022-12-19 05:21:25 +00:00
|
|
|
- **Emacs major mode**: [https://github.com/andorsk/d2-mode](https://github.com/andorsk/d2-mode)
|
2022-12-24 17:58:07 +00:00
|
|
|
- **Goldmark extension**: [https://github.com/FurqanSoftware/goldmark-d2](https://github.com/FurqanSoftware/goldmark-d2)
|
2022-12-10 01:21:05 +00:00
|
|
|
- **Telegram bot**: [https://github.com/meinside/telegram-d2-bot](https://github.com/meinside/telegram-d2-bot)
|
|
|
|
|
- **Postgres importer**: [https://github.com/zekenie/d2-erd-from-postgres](https://github.com/zekenie/d2-erd-from-postgres)
|
2022-12-19 04:33:33 +00:00
|
|
|
- **Structurizr to D2 exporter**: [https://github.com/goto1134/structurizr-d2-exporter](https://github.com/goto1134/structurizr-d2-exporter)
|
2022-12-26 10:35:26 +00:00
|
|
|
- **MdBook preprocessor**: [https://github.com/danieleades/mdbook-d2](https://github.com/danieleades/mdbook-d2)
|
2022-12-30 03:22:57 +00:00
|
|
|
- **ROS2 D2 Exporter**: [https://github.com/Greenroom-Robotics/ros-d2](https://github.com/Greenroom-Robotics/ros-d2)
|
2022-12-27 01:49:05 +00:00
|
|
|
- **D2 org-mode support**: [https://github.com/xcapaldi/ob-d2](https://github.com/xcapaldi/ob-d2)
|
2022-12-30 01:29:50 +00:00
|
|
|
- **Python D2 diagram builder**: [https://github.com/MrBlenny/py-d2](https://github.com/MrBlenny/py-d2)
|
2023-01-03 07:33:09 +00:00
|
|
|
- **Clojure D2 transpiler**: [https://github.com/judepayne/dictim](https://github.com/judepayne/dictim)
|
2023-01-17 21:16:54 +00:00
|
|
|
- **JavaScript D2 diagram builder**: [https://github.com/Kreshnik/d2lang-js](https://github.com/Kreshnik/d2lang-js)
|
2023-02-02 07:29:18 +00:00
|
|
|
- **Maven plugin**: [https://github.com/andrinmeier/unofficial-d2lang-maven-plugin](https://github.com/andrinmeier/unofficial-d2lang-maven-plugin)
|
2023-02-01 23:12:15 +00:00
|
|
|
- **Confluence plugin**: [https://github.com/andrinmeier/unofficial-d2lang-confluence-plugin](https://github.com/andrinmeier/unofficial-d2lang-confluence-plugin)
|
|
|
|
|
- **CIL (C#, Visual Basic, F#, C++ CLR) to D2**: [https://github.com/HugoVG/AppDiagram](https://github.com/HugoVG/AppDiagram)
|
2023-02-04 06:37:29 +00:00
|
|
|
- **D2 Snippets (for text editors)**: [https://github.com/Paracelsus-Rose/D2-Language-Code-Snippets](https://github.com/Paracelsus-Rose/D2-Language-Code-Snippets)
|
2023-02-14 00:28:54 +00:00
|
|
|
- **Mongo to D2**: [https://github.com/novuhq/mongo-to-D2](https://github.com/novuhq/mongo-to-D2)
|
2022-11-03 13:54:49 +00:00
|
|
|
|
|
|
|
|
### Misc
|
|
|
|
|
|
2022-12-17 03:38:26 +00:00
|
|
|
- **Comparison site**: [https://github.com/terrastruct/text-to-diagram-site](https://github.com/terrastruct/text-to-diagram-site)
|
|
|
|
|
- **Playground**: [https://github.com/terrastruct/d2-playground](https://github.com/terrastruct/d2-playground)
|
|
|
|
|
- **Language docs**: [https://github.com/terrastruct/d2-docs](https://github.com/terrastruct/d2-docs)
|
2023-01-29 20:19:48 +00:00
|
|
|
- **Hosted icons**: [https://icons.terrastruct.com](https://icons.terrastruct.com)
|
2022-11-09 21:55:33 +00:00
|
|
|
|
|
|
|
|
## FAQ
|
|
|
|
|
|
|
|
|
|
- Does D2 collect telemetry?
|
|
|
|
|
- No, D2 does not use an internet connection after installation, except to check for
|
|
|
|
|
version updates from Github periodically.
|
2022-11-12 18:03:32 +00:00
|
|
|
- Does D2 need a browser to run?
|
|
|
|
|
- No, D2 can run entirely server-side.
|
2022-11-24 07:16:23 +00:00
|
|
|
- What's coming in the next release?
|
|
|
|
|
- See [./ci/release/changelogs/next.md](./ci/release/changelogs/next.md).
|
2022-11-09 21:55:33 +00:00
|
|
|
- I have a question or need help.
|
2022-11-15 00:50:21 +00:00
|
|
|
- The best way to get help is to ask on [D2 Discord](https://discord.gg/NF6X8K4eDq)
|
|
|
|
|
- I have a feature request, proposal, or bug report.
|
|
|
|
|
- Please open up a Github Issue.
|
2022-11-09 22:00:12 +00:00
|
|
|
- I have a private inquiry.
|
2022-11-09 22:44:48 +00:00
|
|
|
- Please reach out at [hi@d2lang.com](hi@d2lang.com).
|
2023-01-15 08:33:10 +00:00
|
|
|
|
2023-01-15 21:49:48 +00:00
|
|
|
## Open-source projects documenting with D2
|
2023-01-15 08:33:10 +00:00
|
|
|
|
2023-01-15 08:36:27 +00:00
|
|
|
Do you have or see an open-source project with `.d2` files? Please submit a PR adding to
|
|
|
|
|
this list (ordered by star count, desc).
|
2023-01-15 08:33:10 +00:00
|
|
|
|
|
|
|
|
- [Block Protocol](https://github.com/blockprotocol/blockprotocol) - The Block Protocol is
|
|
|
|
|
an open standard for building and using data-driven blocks.
|
2023-01-15 08:36:27 +00:00
|
|
|
- [Ivy Wallet](https://github.com/Ivy-Apps/ivy-wallet) - Ivy Wallet is an open-source
|
|
|
|
|
money manager app for Android.
|
2023-01-15 08:33:10 +00:00
|
|
|
- [Learn EVM Attacks](https://github.com/coinspect/learn-evm-attacks) - Learn & Contribute
|
|
|
|
|
on previously exploited vulnerabilities across several EVM projects.
|
2023-01-15 08:36:27 +00:00
|
|
|
- [BYCEPS](https://github.com/byceps/byceps) - BYCEPS is a self-hosted web platform to run
|
|
|
|
|
LAN parties.
|
2023-01-15 08:33:10 +00:00
|
|
|
- [Re:Earth](https://github.com/reearth/reearth-web) - A free, open and highly extensible
|
|
|
|
|
WebGIS platform.
|
2023-01-15 08:36:27 +00:00
|
|
|
- [Terraform OCI VSCode Server](https://github.com/timoa/terraform-oci-vscode-server) -
|
|
|
|
|
Terraform project that deploys VSCode Server on Oracle Cloud Infrastructure.
|