### Start Website Development Server Source: https://github.com/mingrammer/diagrams/blob/master/CONTRIBUTING.md Install dependencies and start the Docusaurus development server for the project's documentation website. The website will be accessible at http://localhost:3000. ```bash cd website/ npm i npm run start ``` -------------------------------- ### Install diagrams using uv Source: https://github.com/mingrammer/diagrams/blob/master/docs/getting-started/installation.md Use this command to install the diagrams library with uv. ```shell uv tool install diagrams ``` -------------------------------- ### Install diagrams using pip Source: https://github.com/mingrammer/diagrams/blob/master/docs/getting-started/installation.md Use this command to install the diagrams library with pip. ```shell pip install diagrams ``` -------------------------------- ### On-Premise Merged Edges Example Source: https://github.com/mingrammer/diagrams/blob/master/docs/guides/edge.md Demonstrates how to configure and use merged edges with 'concentrate' and 'splines' graph attributes in a Diagrams setup. Ensure 'splines' is set to 'spline' and the layout engine is 'dot' for this to work. ```python from diagrams import Cluster, Diagram, Edge, Node from diagrams.onprem.analytics import Spark from diagrams.onprem.compute import Server from diagrams.onprem.database import PostgreSQL from diagrams.onprem.inmemory import Redis from diagrams.onprem.aggregator import Fluentd from diagrams.onprem.monitoring import Grafana, Prometheus from diagrams.onprem.network import Nginx from diagrams.onprem.queue import Kafka graph_attr = { "concentrate": "true", "splines": "spline", } edge_attr = { "minlen":"3", } with Diagram("\n\nAdvanced Web Service with On-Premise Merged edges", show=False, graph_attr=graph_attr, edge_attr=edge_attr) as diag: ingress = Nginx("ingress") metrics = Prometheus("metric") metrics << Edge(minlen="0") << Grafana("monitoring") with Cluster("Service Cluster"): grpsrv = [ Server("grpc1"), Server("grpc2"), Server("grpc3")] blank = Node("", shape="plaintext", height="0.0", width="0.0") with Cluster("Sessions HA"): sess = Redis("session") sess - Redis("replica") << metrics with Cluster("Database HA"): db = PostgreSQL("users") db - PostgreSQL("replica") << metrics aggregator = Fluentd("logging") aggregator >> Kafka("stream") >> Spark("analytics") ingress >> [grpsrv[0], grpsrv[1], grpsrv[2],] [grpsrv[0], grpsrv[1], grpsrv[2],] - Edge(headport="w", minlen="1") - blank blank >> Edge(headport="w", minlen="2") >> [sess, db, aggregator] diag ``` -------------------------------- ### Install diagrams using pipenv Source: https://github.com/mingrammer/diagrams/blob/master/docs/getting-started/installation.md Use this command to install the diagrams library with pipenv. ```shell pipenv install diagrams ``` -------------------------------- ### Install Python Dependencies with Poetry Source: https://github.com/mingrammer/diagrams/blob/master/DEVELOPMENT.md Installs all the necessary Python dependencies for the diagrams project using Poetry. This command should be run after installing Poetry itself. ```shell poetry install ``` -------------------------------- ### Install diagrams using poetry Source: https://github.com/mingrammer/diagrams/blob/master/docs/getting-started/installation.md Use this command to add the diagrams library as a dependency with poetry. ```shell poetry add diagrams ``` -------------------------------- ### Install Poetry for Python Dependency Management Source: https://github.com/mingrammer/diagrams/blob/master/DEVELOPMENT.md Installs Poetry, the Python project management package used by diagrams. This is a prerequisite for installing project dependencies locally on macOS. ```shell pip install poetry ``` -------------------------------- ### Install Diagrams Binary Dependencies on macOS Source: https://github.com/mingrammer/diagrams/blob/master/DEVELOPMENT.md Installs essential binary dependencies for diagrams development on macOS using Homebrew and Go. This includes ImageMagick, Inkscape, black, and the 'round' tool. ```shell brew install imagemagick inkscape black go install github.com/mingrammer/round@latest ``` -------------------------------- ### Generate a Web Service Diagram Source: https://github.com/mingrammer/diagrams/blob/master/docs/getting-started/installation.md A basic Python script to create a web service diagram using AWS components. Ensure Graphviz is installed and accessible. ```python from diagrams import Diagram from diagrams.aws.compute import EC2 from diagrams.aws.database import RDS from diagrams.aws.network import ELB with Diagram("Web Service", show=False): ELB("lb") >> EC2("web") >> RDS("userdb") ``` -------------------------------- ### Run Unit Tests Locally on macOS Source: https://github.com/mingrammer/diagrams/blob/master/DEVELOPMENT.md Executes the project's unit tests locally on a macOS development environment. This verifies the local setup is working correctly. ```shell python -m unittest tests/*.py -v ``` -------------------------------- ### Message Collecting System on GCP Source: https://github.com/mingrammer/diagrams/blob/master/docs/getting-started/examples.md Demonstrates a message collection system on GCP, starting with IoT devices feeding into Pub/Sub, then processed by Dataflow into various targets like BigQuery, GCS, App Engine, and Cloud Functions. ```python from diagrams import Cluster, Diagram from diagrams.gcp.analytics import BigQuery, Dataflow, PubSub from diagrams.gcp.compute import AppEngine, Functions from diagrams.gcp.database import BigTable from diagrams.gcp.iot import IotCore from diagrams.gcp.storage import GCS with Diagram("Message Collecting", show=False): pubsub = PubSub("pubsub") with Cluster("Source of Data"): [IotCore("core1"), IotCore("core2"), IotCore("core3")] >> pubsub with Cluster("Targets"): with Cluster("Data Flow"): flow = Dataflow("data flow") with Cluster("Data Lake"): flow >> [BigQuery("bq"), GCS("storage")] with Cluster("Event Driven"): with Cluster("Processing"): flow >> AppEngine("engine") >> BigTable("bigtable") with Cluster("Serverless"): flow >> Functions("func") >> AppEngine("appengine") pubsub >> flow ``` -------------------------------- ### Basic Cluster Usage Source: https://github.com/mingrammer/diagrams/blob/master/docs/guides/cluster.md Demonstrates creating a simple web service with a database cluster. Use this to group related database nodes. ```python from diagrams import Cluster, Diagram from diagrams.aws.compute import ECS from diagrams.aws.database import RDS from diagrams.aws.network import Route53 with Diagram("Simple Web Service with DB Cluster", show=False): dns = Route53("dns") web = ECS("service") with Cluster("DB Cluster"): db_primary = RDS("primary") db_primary - [RDS("replica1"), RDS("replica2")] dns >> web >> db_primary ``` -------------------------------- ### Advanced Web Service with On-Premises Components (Colored and Labeled) Source: https://github.com/mingrammer/diagrams/blob/master/docs/getting-started/examples.md Demonstrates the same on-premises web service architecture as above, but with custom edge colors and labels for enhanced visualization. ```python from diagrams import Cluster, Diagram, Edge from diagrams.onprem.analytics import Spark from diagrams.onprem.compute import Server from diagrams.onprem.database import PostgreSQL from diagrams.onprem.inmemory import Redis from diagrams.onprem.aggregator import Fluentd from diagrams.onprem.monitoring import Grafana, Prometheus from diagrams.onprem.network import Nginx from diagrams.onprem.queue import Kafka with Diagram(name="Advanced Web Service with On-Premises (colored)", show=False): ingress = Nginx("ingress") metrics = Prometheus("metric") metrics << Edge(color="firebrick", style="dashed") << Grafana("monitoring") with Cluster("Service Cluster"): grpcsvc = [ Server("grpc1"), Server("grpc2"), Server("grpc3")] with Cluster("Sessions HA"): primary = Redis("session") primary - Edge(color="brown", style="dashed") - Redis("replica") << Edge(label="collect") << metrics grpcsvc >> Edge(color="brown") >> primary with Cluster("Database HA"): primary = PostgreSQL("users") primary - Edge(color="brown", style="dotted") - PostgreSQL("replica") << Edge(label="collect") << metrics grpcsvc >> Edge(color="black") >> primary aggregator = Fluentd("logging") aggregator >> Edge(label="parse") >> Kafka("stream") >> Edge(color="black", style="bold") >> Spark("analytics") ingress >> Edge(color="darkgreen") << grpcsvc >> Edge(color="darkorange") >> aggregator ``` -------------------------------- ### Importing Various Cloud Nodes Source: https://github.com/mingrammer/diagrams/blob/master/docs/guides/node.md Demonstrates importing node objects from different cloud providers like AWS, Azure, Alibaba Cloud, GCP, Kubernetes, and Oracle Cloud. ```python # aws resources from diagrams.aws.compute import ECS, Lambda from diagrams.aws.database import RDS, ElastiCache from diagrams.aws.network import ELB, Route53, VPC ... # azure resources from diagrams.azure.compute import FunctionApps from diagrams.azure.storage import BlobStorage ... # alibaba cloud resources from diagrams.alibabacloud.compute import ECS from diagrams.alibabacloud.storage import ObjectTableStore ... # gcp resources from diagrams.gcp.compute import AppEngine, GKE from diagrams.gcp.ml import AutoML ... # k8s resources from diagrams.k8s.compute import Pod, StatefulSet from diagrams.k8s.network import Service from diagrams.k8s.storage import PV, PVC, StorageClass ... # oracle resources from diagrams.oci.compute import VirtualMachine, Container from diagrams.oci.network import Firewall from diagrams.oci.storage import FileStorage, StorageGateway ``` -------------------------------- ### RabbitMQ Consumers with Custom Nodes Source: https://github.com/mingrammer/diagrams/blob/master/docs/getting-started/examples.md Demonstrates setting up RabbitMQ consumers and connecting them to a database, utilizing a custom node icon for the message queue. ```python from urllib.request import urlretrieve from diagrams import Cluster, Diagram from diagrams.aws.database import Aurora from diagrams.custom import Custom from diagrams.k8s.compute import Pod # Download an image to be used into a Custom Node class rabbitmq_url = "https://jpadilla.github.io/rabbitmqapp/assets/img/icon.png" rabbitmq_icon = "rabbitmq.png" urlretrieve(rabbitmq_url, rabbitmq_icon) with Diagram("Broker Consumers", show=False): with Cluster("Consumers"): consumers = [ Pod("worker"), Pod("worker"), Pod("worker")] queue = Custom("Message queue", rabbitmq_icon) queue >> consumers >> Aurora("Database") ``` -------------------------------- ### Build Docker Image for Diagrams Source: https://github.com/mingrammer/diagrams/blob/master/DEVELOPMENT.md Builds the Docker image for local development. Ensure you are in the diagrams root directory before running. ```shell docker build --tag diagrams:1.0 -f ./docker/dev/Dockerfile . ``` -------------------------------- ### Advanced Web Service with On-Premises Components Source: https://github.com/mingrammer/diagrams/blob/master/docs/getting-started/examples.md Illustrates a complex on-premises web service architecture including ingress, service clusters, session and database HA, logging, and analytics. ```python from diagrams import Cluster, Diagram from diagrams.onprem.analytics import Spark from diagrams.onprem.compute import Server from diagrams.onprem.database import PostgreSQL from diagrams.onprem.inmemory import Redis from diagrams.onprem.aggregator import Fluentd from diagrams.onprem.monitoring import Grafana, Prometheus from diagrams.onprem.network import Nginx from diagrams.onprem.queue import Kafka with Diagram("Advanced Web Service with On-Premises", show=False): ingress = Nginx("ingress") metrics = Prometheus("metric") metrics << Grafana("monitoring") with Cluster("Service Cluster"): grpcsvc = [ Server("grpc1"), Server("grpc2"), Server("grpc3")] with Cluster("Sessions HA"): primary = Redis("session") primary - Redis("replica") << metrics grpcsvc >> primary with Cluster("Database HA"): primary = PostgreSQL("users") primary - PostgreSQL("replica") << metrics grpcsvc >> primary aggregator = Fluentd("logging") aggregator >> Kafka("stream") >> Spark("analytics") ingress >> grpcsvc >> aggregator ``` -------------------------------- ### Stateful Architecture on Kubernetes Source: https://github.com/mingrammer/diagrams/blob/master/docs/getting-started/examples.md Illustrates a stateful application architecture on Kubernetes, featuring a Service, StatefulSet, Pods, PersistentVolumeClaims (PVCs), PersistentVolumes (PVs), and StorageClasses. ```python from diagrams import Cluster, Diagram from diagrams.k8s.compute import Pod, StatefulSet from diagrams.k8s.network import Service from diagrams.k8s.storage import PV, PVC, StorageClass with Diagram("Stateful Architecture", show=False): with Cluster("Apps"): svc = Service("svc") sts = StatefulSet("sts") apps = [] for _ in range(3): pod = Pod("pod") pvc = PVC("pvc") pod - sts - pvc apps.append(svc >> pod >> pvc) apps << PV("pv") << StorageClass("sc") ``` -------------------------------- ### Basic Edge Customization Source: https://github.com/mingrammer/diagrams/blob/master/docs/guides/edge.md Demonstrates how to define edges with custom colors and styles, and how to label them. This is useful for visually distinguishing different types of connections. ```python from diagrams import Cluster, Diagram, Edge from diagrams.onprem.analytics import Spark from diagrams.onprem.compute import Server from diagrams.onprem.database import PostgreSQL from diagrams.onprem.inmemory import Redis from diagrams.onprem.aggregator import Fluentd from diagrams.onprem.monitoring import Grafana, Prometheus from diagrams.onprem.network import Nginx from diagrams.onprem.queue import Kafka with Diagram(name="Advanced Web Service with On-Premises (colored)", show=False): ingress = Nginx("ingress") metrics = Prometheus("metric") metrics << Edge(color="firebrick", style="dashed") << Grafana("monitoring") with Cluster("Service Cluster"): grpcsvc = [ Server("grpc1"), Server("grpc2"), Server("grpc3")] with Cluster("Sessions HA"): primary = Redis("session") primary \ - Edge(color="brown", style="dashed") \ - Redis("replica") \ << Edge(label="collect") \ << metrics grpcsvc >> Edge(color="brown") >> primary with Cluster("Database HA"): primary = PostgreSQL("users") primary \ - Edge(color="brown", style="dotted") \ - PostgreSQL("replica") \ << Edge(label="collect") \ << metrics grpcsvc >> Edge(color="black") >> primary aggregator = Fluentd("logging") aggregator \ >> Edge(label="parse") \ >> Kafka("stream") \ >> Edge(color="black", style="bold") \ >> Spark("analytics") ingress \ >> Edge(color="darkgreen") \ << grpcsvc \ >> Edge(color="darkorange") \ >> aggregator ``` -------------------------------- ### Create and Run Diagrams Docker Container Source: https://github.com/mingrammer/diagrams/blob/master/DEVELOPMENT.md Creates a Docker container named 'diagrams', runs it in the background, and mounts the project source code. This container is used for running tests and scripts. ```shell docker run -d \ -it \ --name diagrams \ --mount type=bind,source="$(pwd)",target=/usr/src/diagrams \ diagrams:1.0 ``` -------------------------------- ### Run Python Diagram Script Source: https://github.com/mingrammer/diagrams/blob/master/docs/getting-started/installation.md Execute the Python script to generate the diagram file. ```shell python diagram.py ``` -------------------------------- ### Managing Edge Complexity with Blank Nodes Source: https://github.com/mingrammer/diagrams/blob/master/docs/guides/edge.md Illustrates a technique to reduce edge noise in complex diagrams by using blank placeholder nodes. This approach helps in organizing connections without cluttering the visual representation. ```python from diagrams import Cluster, Diagram, Node from diagrams.onprem.analytics import Spark from diagrams.onprem.compute import Server from diagrams.onprem.database import PostgreSQL from diagrams.onprem.inmemory import Redis from diagrams.onprem.aggregator import Fluentd from diagrams.onprem.monitoring import Grafana, Prometheus from diagrams.onprem.network import Nginx from diagrams.onprem.queue import Kafka with Diagram("\nAdvanced Web Service with On-Premise Less edges", show=False) as diag: ingress = Nginx("ingress") with Cluster("Service Cluster"): serv1 = Server("grpc1") serv2 = Server("grpc2") serv3 = Server("grpc3") with Cluster(""): blankHA = Node("", shape="plaintext", width="0", height="0") metrics = Prometheus("metric") metrics << Grafana("monitoring") aggregator = Fluentd("logging") blankHA >> aggregator >> Kafka("stream") >> Spark("analytics") with Cluster("Database HA"): db = PostgreSQL("users") db - PostgreSQL("replica") << metrics blankHA >> db with Cluster("Sessions HA"): sess = Redis("session") sess - Redis("replica") << metrics blankHA >> sess ingress >> serv2 >> blankHA diag ``` -------------------------------- ### Output Multiple File Formats Source: https://github.com/mingrammer/diagrams/blob/master/docs/guides/diagram.md Generate diagrams in multiple formats simultaneously by passing a list of formats to the 'outformat' parameter. ```python from diagrams import Diagram from diagrams.aws.compute import EC2 with Diagram("Simple Diagram Multi Output", outformat=["jpg", "png", "dot"]): EC2("web") ``` -------------------------------- ### Resize Image with FFmpeg Source: https://github.com/mingrammer/diagrams/blob/master/CONTRIBUTING.md Use FFmpeg to resize an image, ensuring it fits within a 256x256 pixel bounding box while maintaining aspect ratio. This is an alternative to ImageMagick for image preparation. ```shell ffmpeg -i my_big_image.jpg -vf scale=w=256:h=256:force_original_aspect_ratio=decrease my_image.png ``` -------------------------------- ### Exposed Pod with 3 Replicas on Kubernetes Source: https://github.com/mingrammer/diagrams/blob/master/docs/getting-started/examples.md Shows a Kubernetes deployment with an Ingress exposing a Service, which directs traffic to a ReplicaSet managing three Pods, with Horizontal Pod Autoscaler configured. ```python from diagrams import Diagram from diagrams.k8s.clusterconfig import HPA from diagrams.k8s.compute import Deployment, Pod, ReplicaSet from diagrams.k8s.network import Ingress, Service with Diagram("Exposed Pod with 3 Replicas", show=False): net = Ingress("domain.com") >> Service("svc") net >> [Pod("pod1"), Pod("pod2"), Pod("pod3")] << ReplicaSet("rs") << Deployment("dp") << HPA("hpa") ``` -------------------------------- ### Specify Output File Format Source: https://github.com/mingrammer/diagrams/blob/master/docs/guides/diagram.md Set the output file format for the diagram using the 'outformat' parameter. Allowed formats include png, jpg, svg, pdf, and dot. ```python from diagrams import Diagram from diagrams.aws.compute import EC2 with Diagram("Simple Diagram", outformat="jpg"): EC2("web") ``` -------------------------------- ### Process multiple diagram files with CLI Source: https://github.com/mingrammer/diagrams/blob/master/docs/getting-started/installation.md Use the diagrams CLI to process multiple Python diagram definition files simultaneously. ```shell diagrams diagram1.py diagram2.py ``` -------------------------------- ### Run Unit Tests in Docker Container Source: https://github.com/mingrammer/diagrams/blob/master/DEVELOPMENT.md Executes unit tests within the running 'diagrams' Docker container. This confirms the containerized environment is functioning correctly. ```shell docker exec diagrams python -m unittest tests/*.py -v ``` -------------------------------- ### Custom Node with Local Icons Source: https://github.com/mingrammer/diagrams/blob/master/docs/nodes/custom.md Use this snippet to define custom nodes using local image files. Ensure the image paths are correct relative to your script. ```python from diagrams import Diagram, Cluster from diagrams.custom import Custom with Diagram("Custom with local icons\n Can be downloaded here: \nhttps://creativecommons.org/about/downloads/", show=False, filename="custom_local", direction="LR"): cc_heart = Custom("Creative Commons", "./my_resources/cc_heart.black.png") cc_attribution = Custom("Credit must be given to the creator", "./my_resources/cc_attribution.png") cc_sa = Custom("Adaptations must be shared\n under the same terms", "./my_resources/cc_sa.png") cc_nd = Custom("No derivatives or adaptations\n of the work are permitted", "./my_resources/cc_nd.png") cc_zero = Custom("Public Domain Dedication", "./my_resources/cc_zero.png") with Cluster("Non Commercial"): non_commercial = [Custom("Y", "./my_resources/cc_nc-jp.png") - Custom("E", "./my_resources/cc_nc-eu.png") - Custom("S", "./my_resources/cc_nc.png")] cc_heart >> cc_attribution cc_heart >> non_commercial cc_heart >> cc_sa cc_heart >> cc_nd cc_heart >> cc_zero ``` -------------------------------- ### Grouped Data Flow Source: https://github.com/mingrammer/diagrams/blob/master/docs/guides/node.md Demonstrates grouping multiple nodes into a list to connect them to other nodes simultaneously, simplifying complex flow diagrams. Direct connection between two lists is not supported. ```python from diagrams import Diagram from diagrams.aws.compute import EC2 from diagrams.aws.database import RDS from diagrams.aws.network import ELB with Diagram("Grouped Workers", show=False, direction="TB"): ELB("lb") >> [EC2("worker1"), EC2("worker2"), EC2("worker3"), EC2("worker4"), EC2("worker5")] >> RDS("events") ``` -------------------------------- ### Custom Node with Remote Icons Source: https://github.com/mingrammer/diagrams/blob/master/docs/nodes/custom.md This snippet demonstrates using custom nodes with icons fetched from remote URLs. The `urlretrieve` function is used to download the icon before creating the node. ```python from diagrams import Diagram, Cluster from diagrams.custom import Custom from urllib.request import urlretrieve with Diagram("Custom with remote icons", show=False, filename="custom_remote", direction="LR"): # download the icon image file diagrams_url = "https://github.com/mingrammer/diagrams/raw/master/assets/img/diagrams.png" diagrams_icon = "diagrams.png" urlretrieve(diagrams_url, diagrams_icon) diagrams = Custom("Diagrams", diagrams_icon) with Cluster("Some Providers"): openstack_url = "https://github.com/mingrammer/diagrams/raw/master/resources/openstack/openstack.png" openstack_icon = "openstack.png" urlretrieve(openstack_url, openstack_icon) openstack = Custom("OpenStack", openstack_icon) elastic_url = "https://github.com/mingrammer/diagrams/raw/master/resources/elastic/saas/elastic.png" elastic_icon = "elastic.png" urlretrieve(elastic_url, elastic_icon) elastic = Custom("Elastic", elastic_icon) diagrams >> openstack diagrams >> elastic ``` -------------------------------- ### Representing Data Flow Between Nodes Source: https://github.com/mingrammer/diagrams/blob/master/docs/guides/node.md Illustrates how to connect nodes using shift operators (>>, <<, -) to represent data flow. Parentheses may be needed due to Python's operator precedence. ```python from diagrams import Diagram from diagrams.aws.compute import EC2 from diagrams.aws.database import RDS from diagrams.aws.network import ELB from diagrams.aws.storage import S3 with Diagram("Web Services", show=False): ELB("lb") >> EC2("web") >> RDS("userdb") >> S3("store") ELB("lb") >> EC2("web") >> RDS("userdb") << EC2("stat") (ELB("lb") >> EC2("web")) - EC2("web") >> RDS("userdb") ``` -------------------------------- ### Data Flow with Direction Parameter Source: https://github.com/mingrammer/diagrams/blob/master/docs/guides/node.md Shows how to set the data flow direction for a diagram. The default direction is Left-to-Right (LR). ```python from diagrams import Diagram from diagrams.aws.compute import EC2 from diagrams.aws.database import RDS from diagrams.aws.network import ELB with Diagram("Workers", show=False, direction="TB"): lb = ELB("lb") db = RDS("events") lb >> EC2("worker1") >> db lb >> EC2("worker2") >> db lb >> EC2("worker3") >> db lb >> EC2("worker4") >> db lb >> EC2("worker5") >> db ``` -------------------------------- ### Specify Output Filename Source: https://github.com/mingrammer/diagrams/blob/master/docs/guides/diagram.md Define a custom filename for the output diagram using the 'filename' parameter. The file extension is automatically determined by the 'outformat'. ```python from diagrams import Diagram from diagrams.aws.compute import EC2 with Diagram("Simple Diagram", filename="my_diagram"): EC2("web") ``` -------------------------------- ### Run Autogen Script Locally on macOS Source: https://github.com/mingrammer/diagrams/blob/master/DEVELOPMENT.md Executes the 'autogen.sh' bash script directly on the macOS development machine. This is a final check to ensure the local environment is ready for development. ```shell ./autogen.sh ``` -------------------------------- ### Clustered Web Services on AWS Source: https://github.com/mingrammer/diagrams/blob/master/docs/getting-started/examples.md Depicts a clustered web service architecture on AWS, including DNS, load balancing, containerized services (ECS), a database cluster (RDS), and a memcached layer. ```python from diagrams import Cluster, Diagram from diagrams.aws.compute import ECS from diagrams.aws.database import ElastiCache, RDS from diagrams.aws.network import ELB from diagrams.aws.network import Route53 with Diagram("Clustered Web Services", show=False): dns = Route53("dns") lb = ELB("lb") with Cluster("Services"): svc_group = [ECS("web1"), ECS("web2"), ECS("web3")] with Cluster("DB Cluster"): db_primary = RDS("userdb") db_primary - [RDS("userdb ro")] memcached = ElastiCache("memcached") dns >> lb >> svc_group svc_group >> db_primary svc_group >> memcached ``` -------------------------------- ### Apply Custom Graphviz Attributes Source: https://github.com/mingrammer/diagrams/blob/master/docs/guides/diagram.md Customize the diagram's appearance by applying Graphviz attributes like 'fontsize' and 'bgcolor' through the 'graph_attr' parameter. ```python from diagrams import Diagram from diagrams.aws.compute import EC2 graph_attr = { "fontsize": "45", "bgcolor": "transparent" } with Diagram("Simple Diagram", show=False, graph_attr=graph_attr): EC2("web") ``` -------------------------------- ### Resize Image with ImageMagick Source: https://github.com/mingrammer/diagrams/blob/master/CONTRIBUTING.md Use ImageMagick to resize an image to a maximum of 256 pixels wide or high. This is useful for preparing resource images for node generation. ```shell convert -resize 256 my_big_image.jpg my_image.jpg ```