#software-engineering #documentation ## What is D2? **D2** is a diagram scripting language that turns text to diagrams. It stands for **Declarative Diagramming**. Declarative, as in, you describe what you want diagrammed, it generates the image. For example, download the CLI, create a file named `input.d2`, copy paste the following, run this command, and you get the image below. ``` 1d2 --theme=300 --dark-theme=200 -l elk --pad 0 ./input.d2 ``` ```d2 network: { cell tower: { satellites: { shape: stored_data style.multiple: true } transmitter satellites -> transmitter: send satellites -> transmitter: send satellites -> transmitter: send } online portal: { ui: {shape: hexagon} } data processor: { storage: { shape: cylinder style.multiple: true } } cell tower.transmitter -> data processor.storage: phone logs } user: { shape: person width: 130 } user -> network.cell tower: make call user -> network.online portal.ui: access { style.stroke-dash: 3 } api server -> network.online portal.ui: display api server -> logs: persist logs: {shape: page; style.multiple: true} network.data processor -> api server ``` ## Using the CLI watch mode[](https://d2lang.com/tour/intro#using-the-cli-watch-mode "Direct link to Using the CLI watch mode") ![D2 CLI](https://d2lang.com/assets/images/cli-d53efad8a27f22b9520d9cd7dc9658d1.gif) You can finish this tour in about 5-10 minutes, and at the end, there's a cheat sheet you can download and refer to. If you want just the bare essentials, [Getting Started](https://d2lang.com/tour/hello-world) takes ~2 mins. ## Any alternatives and comparison? [Frequently asked questions (FAQ) | D2 Documentation (d2lang.com)](https://d2lang.com/tour/faq/#how-does-this-compare-to-mermaid-graphviz-plantuml)