-
Notifications
You must be signed in to change notification settings - Fork 0
/
diagram.py
133 lines (102 loc) · 4.28 KB
/
diagram.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
from os import environ
from diagrams import Diagram, Cluster, Edge
from diagrams.saas.cdn import Cloudflare
from diagrams.onprem.client import User
from diagrams.aws.network import ELB
from diagrams.onprem.network import Nginx
from diagrams.onprem.aggregator import Fluentd
from diagrams.elastic.elasticsearch import Elasticsearch
from diagrams.programming.framework import React
from diagrams.onprem.database import Mongodb
from diagrams.aws.storage import SimpleStorageServiceS3BucketWithObjects
from diagrams.programming.language import Go as Golang, Javascript, Typescript
def create_cloud_infrastructure_diagram(company_name = ""):
"""
Creates a diagram of the cloud infrastructure for the web application.
"""
with Diagram(company_name + " Cloud Infrastructure",
filename="infrastructure_diagram",
show=False,
direction="LR",
outformat="png"
):
with Cluster("EKS Cluster", graph_attr={
# "pad": "6.0",
"center": "true"
}):
with Cluster("Controller",graph_attr = {
"bgcolor": "transparent",
}):
ingress_controller = Nginx("Ingress \nController")
with Cluster("Frontend App",graph_attr = {
"bgcolor": "transparent",
"fontcolor": "bold",
}):
frontend_service = React("Frontend App")
with Cluster("Backend \nAPI Services",graph_attr = {
"bgcolor": "transparent",
"fontcolor": "bold",
}):
api_gateway = Typescript("API \nGateway")
with Cluster(label="Microservices", graph_attr = {
"bgcolor": "transparent",
"style": "invis",
}):
microservices = [
Typescript("Auth API\nService"),
Golang("Company API\nService"),
Javascript("Notification API\nService")
]
with Cluster(label="Metrics \nCollection", graph_attr = {
"bgcolor": "transparent",
"fontcolor": "bold",
"comment": "Responsible for logging collection and parsing"
}):
aggregator = Fluentd("Fluentd\n(Logging)")
with Cluster("External", graph_attr = {
"bgcolor": "transparent",
"fontcolor": "invis",
}):
with Cluster("Database", graph_attr = {
"bgcolor": "transparent",
}):
mongo_db = Mongodb("MongoDB")
elasticsearch = Elasticsearch("Elasticsearch")
s3_bucket = SimpleStorageServiceS3BucketWithObjects("S3 Bucket")
# CONNECTIONS
__ingres_color__ = "darkgreen"
__api_gate_conn__ = "darkblue"
__metrics__ = "darkorange"
__database__ = "darkblue"
load_balancer = ELB("Load Balancer")
User("End User") >> Cloudflare("Cloudflare") >> load_balancer
load_balancer \
>> Edge(color=__ingres_color__, style="bold") \
>> ingress_controller
ingress_controller \
>> Edge(color=__ingres_color__, style="bold") \
>> frontend_service
frontend_service \
>> Edge(color=__metrics__,style="dashed") \
>> aggregator
ingress_controller \
>> Edge(color=__ingres_color__, style="bold") \
>> api_gateway
api_gateway \
>> Edge(color=__metrics__,style="dashed") \
>> aggregator
api_gateway \
>> Edge(color=__api_gate_conn__, label="REST") \
>> microservices
microservices \
>> Edge(color=__metrics__,style="dashed") \
>> aggregator
microservices \
>> Edge(color=__database__, style="dashed") \
>> mongo_db
aggregator \
>> elasticsearch
aggregator \
>> s3_bucket
company_name = environ.get("COMPANY_NAME")
create_cloud_infrastructure_diagram(company_name=company_name)