Skip to main content
Creating diagrams programmatically offers significant advantages over manual drawing tools: version control, reproducibility, and consistency across documentation. This tutorial covers two approaches for creating diagrams as code.

Python Diagrams Package

The diagrams Python package allows you to draw cloud system architecture diagrams using Python code. It supports major cloud providers (AWS, Azure, GCP), on-premise infrastructure, and custom icons.

Installation

You also need Graphviz installed and available on your PATH.

AWS Architecture Example

Here’s how to create a clustered web services diagram:
Clustered Web Services

C4 Model Diagrams

The diagrams package supports the C4 model for visualizing software architecture:
C4 Container Diagram

Custom Icons

You can use custom icons for components not included in the standard providers:
Custom Icons

Mermaid Diagrams

For simpler diagrams that don’t require external dependencies, Mermaid provides a markdown-based syntax. Mermaid is supported natively in many documentation platforms including GitHub and Mintlify.

Neural Network Architecture Example

Here’s a Mermaid flowchart showing an upcycled MoE (Mixture of Experts) block:

Model Architecture Visualization

For visualizing trained model architectures (ONNX, TensorFlow, PyTorch, etc.), we recommend Netron - a viewer for neural network, deep learning, and machine learning models. Netron supports many formats including:
  • ONNX (.onnx)
  • TensorFlow Lite (.tflite)
  • TensorFlow (.pb, .meta, SavedModel)
  • Keras (.h5, .keras)
  • PyTorch (.pt, .pth)
  • Core ML (.mlmodel, .mlpackage)
You can use the web version or install it locally.

When to Use Each Tool

Resources