github.com/terrastruct/d2
This package has a good security score with no known vulnerabilities.
Community Reviews
Powerful diagram-as-code tool with gentle learning curve
The official documentation includes practical examples covering common diagram patterns (flowcharts, sequence diagrams, network diagrams). The playground on their website is invaluable for testing syntax before integrating into your code. GitHub issues get responses within days, and the maintainers are receptive to bug reports.
One gotcha: layout engine selection matters significantly for output quality, and the defaults don't always produce ideal results for complex diagrams. You'll need to experiment with dagre, elk, or tala engines. Also, programmatic manipulation of D2 AST is possible but underdocumented - most examples focus on string templating, which works but feels primitive for dynamic diagram generation.
Best for: Projects needing programmatically generated diagrams from code with human-readable/editable output
Avoid if: You need pixel-perfect layout control or complex interactive diagrams with runtime behavior
Powerful diagram generation with operational rough edges
Error handling is straightforward but errors from the layout engines can be cryptic. The library doesn't provide built-in retry mechanisms or circuit breakers, so you'll need to wrap calls yourself. Timeouts must be managed at the context level since diagram compilation can take 5-30 seconds for complex layouts. No connection pooling is needed, but you should rate-limit diagram generation to avoid resource exhaustion.
Configuration is flexible through compile options, but breaking changes between minor versions have caught me twice—diagram output changed subtly after updates. Logging is minimal; you'll want to add your own instrumentation around compilation calls. For high-throughput scenarios, consider pre-generating diagrams or aggressive caching.
Best for: Low-to-medium volume diagram generation in dev tools, documentation pipelines, or admin dashboards where 5-30s latency is acceptable.
Avoid if: You need real-time diagram generation, strict memory constraints, or high-throughput production APIs serving user requests.
Powerful diagramming DSL but operational concerns need attention
Error handling is reasonable for parsing errors but less predictable when layout engines fail or hang. There's no built-in connection pooling for layout engines, so you're responsible for implementing worker pools to prevent resource exhaustion. Logging hooks are minimal - you'll want to wrap calls with your own instrumentation to track render times and failures. The API surface has seen breaking changes between minor versions, particularly around layout configuration.
For batch processing or low-throughput services it works well, but high-concurrency scenarios require significant wrapping infrastructure. Memory profiles show layout engines can spike unpredictably with nested structures or large graphs.
Best for: CLI tools, batch diagram generation, or low-throughput services where you can afford subprocess overhead and have control over diagram complexity.
Avoid if: You need high-concurrency diagram rendering, predictable p99 latencies, or are building a multi-tenant service without resources for extensive operational wrapping.
Sign in to write a review
Sign In