Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Code Generated Architecture Diagram
Arindam Mitra
Arindam Mitra

Posted on • Edited on

     

Code Generated Architecture Diagram

Greetings to my fellow Technology Advocates and Specialists.

In this Session, I will demonstrateHow to Create Azure Solutions Architecture Diagram by Code.

I had the Privilege to talk on this topic inONE Azure Community:-

NAME OF THE AZURE COMMUNITYTYPE OF SPEAKER SESSION
Festive Tech Calendar - 2024Virtual
EVENT ANNOUNCEMENTS:-
Image description
VIRTUAL SESSION:-
LIVE DEMO was Recorded as part of my Presentation inFESTIVE TECH CALENDAR - 2024 Forum/Platform
Duration of My Demo =49 Mins 02 Secs
AUTOMATION OBJECTIVES:-
#TOPICS
1.Example #1: Create "Basic Azure App Service Architecture Diagram" by Code.
2.Example #2: Create "Gaming Architecture Diagram" by Code.
PRE-REQUISITES:-
1. Python 3.6 or higher.
2. Graphviz
3. pip
VALIDATE PRE-REQUISITES:-
Image description
COMMANDS TO VERIFY:-
python --versiondot -Vpip --version
Enter fullscreen modeExit fullscreen mode
INSTALL DIAGRAMS:-

Install "diagrams" using "pip":-

pip install diagrams

Image description
CODE REPOSITORY:-

CONCEPTS:-
I.) DIAGRAMS:-
1. Represents a global diagram context.
2. Diagram context can be created with Diagram class.
3. The first parameter of Diagram constructor will be used for output filename.
II.) NODES:-
1. Represents a single system component object.
2. A node object consists of three parts: i) Provider, ii) Resource type and iii) Name.
III.) CLUSTERS:-
1. Allows you group (or clustering) the nodes.
IV.) EDGES:-
1. Represents a connection between Nodes with some additional properties.

Now, we proceed inCreating Architecture Diagram using Diagrams and Python.

CONSTRUCT OF THE PYTHON CODE TO CREATE ARCHITECTURE DIAGRAM:-
1. Import Diagram, Cluster and Edge.
2. Import the Provider Icons for creating diagrams.
3. Creating the building blocks using Nodes and Cluster.
4. Connect the building blocks using Edges.
EXAMPLE #1:

Create "Basic Azure App Service Architecture Diagram" by Code.

Below follows the Python Code (Generate-Basic-Azure-App-service-Arch-Diagram.py):-

############################################################## Architecture Diagram: Basic Azure App Service:-## Components include:-# 1. User# 2. Azure Entra ID# 3. Azure Monitor# 4. Azure Application Insights# 5. Azure User Assigned Managed Identity# 6. Azure Key Vault # 7. Azure App Services# 8. Azure SQL Servers################################################################################################################### Import Diagram, Cluster and Edge.# Import the Provider Icons for creating diagrams.######################################################from diagrams import Cluster, Diagram, Edgefrom diagrams.azure.general import Helpsupport, Servicehealthfrom diagrams.azure.devops import ApplicationInsightsfrom diagrams.azure.security import KeyVaultsfrom diagrams.azure.identity import ManagedIdentities, ActiveDirectoryfrom diagrams.azure.compute import AppServicesfrom diagrams.azure.database import SQLServers########################################################## Creating the building blocks using Nodes and Cluster.#########################################################with Diagram("Basic Azure App Service Architecture", show=False, direction="TB"):    usr = Helpsupport("User")    with Cluster("Compute"):        components_webapp = [AppServices("AppServices"), KeyVaults("KV"), ManagedIdentities("UMID")]    with Cluster("Data"):        components_db = SQLServers("Azure SQL Database")    with Cluster("Identity"):        components_identity = [ActiveDirectory("Microsoft Entra ID")]    with Cluster("Monitoring"):        components_monitor = [ApplicationInsights("App Insights"), Servicehealth("Azure Monitor")]############################################# Connect the building blocks using Edges.############################################    usr >> Edge(color="darkorange") >> components_webapp    components_webapp >> Edge(color="darkgreen") >> components_db
Enter fullscreen modeExit fullscreen mode
EXECUTE THE PYTHON CODE:-

python.exe .\Generate-Basic-Azure-App-service-Arch-Diagram.py

OUTPUT OF EXAMPLE #1:-
Image description
EXAMPLE #2:

Create "Gaming Architecture Diagram" by Code.

Below follows the Python Code (Generate-Gaming-Arch-Diagrams.py):-

############################################################## Architecture Diagram: Gaming using Azure Cosmos DB:-## Components include:-# 1. User# 2. Azure Traffic Manager# 3. Azure Content Delivery Network# 4. Azure Storage# 5. Azure API Management # 6. Azure Cosmos DB# 7. Azure Databricks# 8. Azure Functions# 9. Azure Notification Hubs################################################################################################################### Import Diagram, Cluster and Edge.# Import the Provider Icons for creating diagrams.######################################################from diagrams import Cluster, Diagram, Edgefrom diagrams.azure.general import Helpsupportfrom diagrams.azure.network import TrafficManagerProfiles, CDNProfilesfrom diagrams.azure.storage import StorageAccountsfrom diagrams.azure.integration import APIManagementfrom diagrams.azure.database import CosmosDbfrom diagrams.azure.analytics import Databricksfrom diagrams.azure.compute import FunctionAppsfrom diagrams.azure.mobile import NotificationHubs########################################################## Creating the building blocks using Nodes and Cluster.########################################################## with Diagram("GAMING ARCHITECTURE", show=False, direction="TB"):with Diagram("GAMING ARCHITECTURE", show=False):    usr = Helpsupport("User")    # atm = TrafficManagerProfiles("Azure Traffic Manager")    apim = APIManagement("Azure API Apps")    cosmos = CosmosDb("Azure Cosmos DB")    dbks = Databricks("Azure Databricks")    # cdn = CDNProfiles ("Azure CDN")    # storage = StorageAccounts("Azure Storage (Media Files)")    functions = FunctionApps("Azure Functions")    notifyhub = NotificationHubs("Azure Notification Hubs")    with Cluster(""):         atm = TrafficManagerProfiles("Traffic Manager")    with Cluster(""):         cdn = CDNProfiles ("Azure CDN")    with Cluster(""):         storage = StorageAccounts("Azure Storage")############################################# Connect the building blocks using Edges.############################################    usr >> Edge(color="darkgreen") >> atm    cdn >> Edge(color="darkblue") >> atm    storage >> Edge(color="darkpurple") >> cdn    atm >> Edge(color="darkorange") >> apim    apim >> Edge(color="darkred") >> cosmos    cosmos >> Edge(color="darkred") >> apim    cosmos >> Edge(color="darkblue") >> dbks    cosmos >> Edge(color="darkblue") >> functions    functions >> Edge(color="darkbrown") >> notifyhub
Enter fullscreen modeExit fullscreen mode
EXECUTE THE PYTHON CODE:-

python.exe .\Generate-Gaming-Arch-Diagrams.py

OUTPUT OF EXAMPLE #2:-
Image description

Hope You Enjoyed the Session!!!

Stay Safe | Keep Learning | Spread Knowledge

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

2 x Microsoft MVP - IaC & Devops | 2 x Sessionize Active Speaker | Blogger ✍️ | Public Speaker 🔊 | Long Distance Runner🏃‍♂️ | Hiking 🥾 | Traveler 🧳 | Citizen of the 🌎
  • Location
    Ennetbaden, Switzerland
  • Education
    Bachelor in Computer Science Engineering (CSE)
  • Joined

More fromArindam Mitra

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp