DEV Community

Diagrams as code

Simon Brown on October 28, 2020

The technique of "diagrams as code" just appeared on the ThoughtWorks Tech Radar (as "Trial"), with the Structurizr DSL also getting a mention. ...
Collapse
 
christophe profile image
Christophe T

Interesting! The term “diagram as code” seems indeed extremely misleading: it could as well refer to the opposite, i.e. the old dream of visual programming with ultra-detailed UML diagrams and OCL annotations to replace the code (which of course never really materialised but made UML so heavy). What about “diagramming from code” ?

Collapse
 
simonbrown profile image
Simon Brown

I think we're stuck with the term to be honest! 😀

Collapse
 
mikestaub profile image
Mike Staub

I personally love ilograph.com

Collapse
 
orefalo profile image
Olivier Refalo • Edited

It's neat, but it lacks many many features.

you can't do hierarchies, element MUST be connected
you can't do block layouts for the same reason

it's also not possible to do the diagram they advertise on the front page...
Image description

note how elements substitute to provide more details as you drill down....
when you read the doc you will realize it can't be achieved.

it's only good for, basic component diagram and sequences.

Collapse
 
simonbrown profile image
Simon Brown

I think the visualisation is great, although I'm not a fan of using YAML for defining the model ... that's why I added Ilograph as an export format for the Structurizr CLI. 👍

Collapse
 
ryanycoleman profile image
Ryan Coleman

Interesting post Simon! I'm a big proponent of codifying anything teams want to repeat, collaborate on, or standardize around. I like the concept of diagrams as code for workflow diagrams or even abstract white-boarding, especially now that we're all remote.

For application infrastructure, Stackery takes this idea a bit further with diagrams as code that can be deployed into a public cloud provider, like AWS. I've embedded a simple example that's bidirectional between the code and the diagram, though the technique really shines as architectures (and code) scale.

What do you think? Have you seen teams turn their architectural diagrams as code into deployable artifacts?

Collapse
 
simonbrown profile image
Simon Brown

I have yes ... here's an example of creating Azure resources with Structurizr for .NET ... github.com/ChristianEder/Structuri...

Collapse
 
v6 profile image
🦄N B🛡

Don't forget mermaidjs.

I use it on every project, even in one or two of my blog posts.

Collapse
 
simonbrown profile image
Simon Brown

Yes, Mermaid is great too ... it's actually a supported output format for the Structurizr CLI -> github.com/structurizr/cli/blob/ma...

Collapse
 
aliya_sultana_ profile image
Aliya Sultana

Try code2diagram.com and select any diagram you need. No setup or installation is required, just use a simple code to generate the best diagram.