Skip to content

Commit b349918

Browse files
feat: Add architecture diagram
1 parent 88c5500 commit b349918

8 files changed

Lines changed: 355 additions & 1 deletion

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.env
22
.terraform
33
*.plan
4-
*.png
54
**/plan.json

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ The infrastructure is organized into three main components:
1010
- **`dev/`**: Development environment
1111
- **`prod/`**: Production environment
1212

13+
![Architecture Diagram](./visualize/ctk_terraform_architecture.png)
14+
1315
## Deployment Order
1416

1517
**IMPORTANT**: You must deploy the shared infrastructure first, then the environment-specific infrastructure.

visualize/.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.png filter=lfs diff=lfs merge=lfs -text

visualize/.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13
Lines changed: 3 additions & 0 deletions
Loading

visualize/main.py

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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"]

visualize/pyproject.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[project]
2+
name = "visualize"
3+
version = "0.1.0"
4+
description = "Add your description here"
5+
readme = "README.md"
6+
requires-python = ">=3.13"
7+
dependencies = [
8+
"diagrams==0.24.4",
9+
]

0 commit comments

Comments
 (0)