|
| 1 | +import diagrams |
| 2 | +from diagrams.azure import ( |
| 3 | + compute, |
| 4 | + database, |
| 5 | + storage, |
| 6 | + network, |
| 7 | + security, |
| 8 | + devops, |
| 9 | + monitor, |
| 10 | +) |
| 11 | + |
| 12 | +with diagrams.Diagram( |
| 13 | + "CTK Terraform Infrastructure", |
| 14 | + filename="ctk_terraform_architecture", |
| 15 | + show=False, |
| 16 | + direction="TB", |
| 17 | + graph_attr={ |
| 18 | + "fontsize": "16", |
| 19 | + "bgcolor": "white", |
| 20 | + "pad": "0.5", |
| 21 | + }, |
| 22 | +): |
| 23 | + with diagrams.Cluster("Shared Infrastructure"): |
| 24 | + with diagrams.Cluster("rg-ctk-shared"): |
| 25 | + shared_acr = devops.Repos("Azure Container\nRegistry\nacrctkshared") |
| 26 | + |
| 27 | + environments = {} |
| 28 | + |
| 29 | + for env_name in ["Production", "Development"]: |
| 30 | + env_short = "prod" if env_name == "Production" else "dev" |
| 31 | + |
| 32 | + environments[env_short] = {} |
| 33 | + |
| 34 | + with diagrams.Cluster(f"{env_name} Environment"): |
| 35 | + with diagrams.Cluster(f"rg-ctk-{env_short}"): |
| 36 | + with diagrams.Cluster(f"Virtual Network (vnet-ctk-{env_short})"): |
| 37 | + environments[env_short]["vnet"] = network.VirtualNetworks( |
| 38 | + "VNet\n10.0.0.0/16" |
| 39 | + ) |
| 40 | + |
| 41 | + with diagrams.Cluster("Subnets"): |
| 42 | + environments[env_short]["subnet_apps"] = network.Subnets( |
| 43 | + "Container Apps\nSubnet" |
| 44 | + ) |
| 45 | + environments[env_short]["subnet_db"] = network.Subnets( |
| 46 | + "Database\nSubnet" |
| 47 | + ) |
| 48 | + environments[env_short]["subnet_storage"] = network.Subnets( |
| 49 | + "Storage\nSubnet" |
| 50 | + ) |
| 51 | + |
| 52 | + environments[env_short]["logs"] = monitor.Monitor( |
| 53 | + "Log Analytics\nWorkspace" |
| 54 | + ) |
| 55 | + environments[env_short]["kv"] = security.KeyVaults( |
| 56 | + "Key Vault\n(Secrets)" |
| 57 | + ) |
| 58 | + environments[env_short]["storage"] = storage.StorageAccounts( |
| 59 | + "Storage Account\n(Blob Storage)" |
| 60 | + ) |
| 61 | + |
| 62 | + with diagrams.Cluster("Database Infrastructure"): |
| 63 | + environments[env_short]["postgres"] = ( |
| 64 | + database.DatabaseForPostgresqlServers("Cosmos DB\nPostgreSQL") |
| 65 | + ) |
| 66 | + environments[env_short]["pe"] = network.PrivateEndpoint( |
| 67 | + "Private\nEndpoint" |
| 68 | + ) |
| 69 | + environments[env_short]["dns"] = network.DNSZones( |
| 70 | + "Private DNS Zone\npostgres.cosmos.azure.com" |
| 71 | + ) |
| 72 | + |
| 73 | + with diagrams.Cluster(f"Container App Environment (cae-ctk-{env_short})"): |
| 74 | + environments[env_short]["webapp"] = compute.ContainerInstances( |
| 75 | + "Web App\n(Public)" |
| 76 | + ) |
| 77 | + environments[env_short]["cloai"] = compute.ContainerInstances( |
| 78 | + "CLOAI Service\n(Internal)" |
| 79 | + ) |
| 80 | + environments[env_short]["functions"] = compute.ContainerInstances( |
| 81 | + "CTK Functions\n(Internal)" |
| 82 | + ) |
| 83 | + environments[env_short]["languagetool"] = ( |
| 84 | + compute.ContainerInstances("LanguageTool\n(Internal)") |
| 85 | + ) |
| 86 | + |
| 87 | + for env_short in ["prod", "dev"]: |
| 88 | + env = environments[env_short] |
| 89 | + |
| 90 | + shared_acr >> diagrams.Edge(label="pull images") >> env["webapp"] |
| 91 | + shared_acr >> diagrams.Edge(label="pull images") >> env["cloai"] |
| 92 | + shared_acr >> diagrams.Edge(label="pull images") >> env["functions"] |
| 93 | + |
| 94 | + env["logs"] >> diagrams.Edge(label="logs") >> env["webapp"] |
| 95 | + env["logs"] >> diagrams.Edge(label="logs") >> env["cloai"] |
| 96 | + env["logs"] >> diagrams.Edge(label="logs") >> env["functions"] |
| 97 | + env["logs"] >> diagrams.Edge(label="logs") >> env["languagetool"] |
| 98 | + |
| 99 | + env["kv"] >> diagrams.Edge(label="secrets") >> env["cloai"] |
| 100 | + env["kv"] >> diagrams.Edge(label="secrets") >> env["functions"] |
| 101 | + env["kv"] >> diagrams.Edge(label="DB password") >> env["postgres"] |
| 102 | + |
| 103 | + env["storage"] >> diagrams.Edge(label="blob storage") >> env["webapp"] |
| 104 | + |
| 105 | + env["postgres"] >> diagrams.Edge(label="private link") >> env["pe"] |
| 106 | + env["pe"] >> env["subnet_db"] |
| 107 | + env["dns"] >> diagrams.Edge(label="DNS resolution") >> env["vnet"] |
| 108 | + |
| 109 | + env["webapp"] >> diagrams.Edge(label="read/write") >> env["postgres"] |
| 110 | + env["functions"] >> diagrams.Edge(label="read/write") >> env["postgres"] |
| 111 | + |
| 112 | + env["webapp"] >> diagrams.Edge(label="grammar check") >> env["languagetool"] |
| 113 | + env["functions"] >> diagrams.Edge(label="AI requests") >> env["cloai"] |
| 114 | + env["functions"] >> diagrams.Edge(label="grammar check") >> env["languagetool"] |
| 115 | + |
| 116 | + env["subnet_apps"] >> env["webapp"] |
| 117 | + env["subnet_storage"] >> env["kv"] |
| 118 | + env["subnet_storage"] >> env["storage"] |
0 commit comments