Have you heard of the diagrams as code DAC? 🤫

Aditya N
2 min readSep 24, 2022


This is the article where we will see how we can use DAC to build our tedious Infrastructure Diagram!!! after all who does not love code 😜

So we use N no of tools to build our complex infra diagrams in our TDD documents but when we can build everything with help of a piece of python code.

How to get started?

Need to have py 3.6 or higher and graphviz installed in your system and make sure you add graphviz to your system PATH.

you can install graphviz from here

Next, run the following command

pip install diagrams

All Set …

For starters there 4 basic components in Diagrams:

  1. Diagrams act as a primary object representing a diagram and which is where all our diagrams are stored in the file in our filesystem.

2. Nodes are the second layer of objects which represent the component or system of the node

from diagrams.gcp.network import LoadBalancing

here loadBalancing is node and network is resource GCP is the provider

3. Cluster is a local collection of resources to represent a logical grouping. A cluster can represent anything from a VPC to a Kubernetes cluster. This can help organize the elements of a diagram

4. Edge is an object representing a connection between Nodes with some additional properties.

You can also check out how to configure Network policies in your Kubernetes Cluster.

We will be setting one of the architecture diagrams using the diagrams library

So from the above code, we are trying to connect to GKE with help of LB with the protection of Cloud Armor so we can see below how it looks!!

You can also checkout how to provide elasticity to Hadoop using python

Conclusion so by now you would have understood the power of DAC and we can easily reuse the diagrams across similar kind of projects and kill it. for further exploration Diagrams documentation

Do follow for amazing content 🙏