Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit ba40918

Browse files
committed
[issue #1] common provider for one or more nodes
* groups components with the same `provider` attribute (see examples) * add the new attribute `impl` to all components (see examples) * change microservice shape to 'octagon' * layout README file
1 parent 9312030 commit ba40918

37 files changed

+104
-273
lines changed

README.md

Lines changed: 53 additions & 185 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,32 @@ To install GraphViz to your favorite OS, please, follow this link [https://graph
3131

3232
## Components
3333

34-
### A picture is worth a thousand words
34+
> a picture is worth a thousand words
3535
3636
... and this is particularly true in regard to complex IT architectures.
3737

3838
The basic unit of each _draft_ design is the `component`:
3939

4040
```go
4141
type Component struct {
42-
ID string `yaml:"id,omitempty"` // optional - autogenerated if omitted (read more for details...)
43-
Kind string `yaml:"kind"` // required (one of: service, gateway, queue, broker, function, storage, database)
44-
Label string `yaml:"label,omitempty"` // optional - the component description (or scope)
45-
Provider string `yaml:"provider,omitempty"` // optional - you can use this to specify the implementation
46-
FillColor string `yaml:"fillColor,omitempty"` // optional - the hex code for the background color
47-
FontColor string `yaml:"fontColor,omitempty"` // optional - the hex code for the foreground color
48-
Rounded bool `yaml:"rounded,omitempty"` // optional - set to true if you wants rounded shapes
42+
ID string `yaml:"id,omitempty"` // optional - autogenerated if omitted (read more for details...)
43+
Kind string `yaml:"kind"` // required (one of: service, gateway, queue, broker, function, storage, database)
44+
Label string `yaml:"label,omitempty"` // optional - the component description (or scope)
45+
Provider string `yaml:"provider,omitempty"` // optional - you can use this to specify the cloud provider
46+
Impl string `yaml:"impl,omitempty"` // optional - you can use this to specify the implementation
47+
FillColor string `yaml:"fillColor,omitempty"` // optional - the hex code for the background color
48+
FontColor string `yaml:"fontColor,omitempty"` // optional - the hex code for the foreground color
49+
Rounded bool `yaml:"rounded,omitempty"` // optional - set to true if you wants rounded shapes
4950
}
5051
```
5152

5253
Draft uses a set of symbols independent from the different providers (AWS, Microsoft Azure, GCP).
5354

54-
- you can eventually describe the implementation using the `provider` attribute.
55+
Eventually you can describe...
56+
57+
- the implementation using the `impl` attribute (ie: _impl: 'SQS'_)
58+
- the cloud provider using the `provider` attribute (ie: _provider: AWS_)
59+
- 💡 components with the same provider will be 'grouped'
5560

5661
Below is a list of all the components currently implemented.
5762

@@ -66,18 +71,14 @@ Below is a list of all the components currently implemented.
6671
| **Function** | `function` | ![](./examples/fn.jpg) | ![](./examples/function.png) |
6772
| **Database** | `database` | ![](./examples/db.jpg) | ![](./examples/database.png) |
6873

69-
## Connections
74+
### Notes about a component `id`
7075

71-
You can connect each component by arrows.
76+
- you can define your component `id` explicitly (i.e. _id: MY_SERVICE_A_)
77+
- or you can omit the component `id` attribute and it will be autogenerated
7278

73-
To be able to connect an _origin component_ with one or more _target component_ you need to specify each `componentId`.
79+
#### How is auto-generated a component `id`?
7480

75-
- you can define your component `id` explicitly
76-
- you can omit the component `id` attribute and it will be autogenerated
77-
78-
### Autogenerated `id`
79-
80-
An autogenerated `id` has a prefix and a sequential number
81+
An auto-generated component `id` has a prefix and a sequential number
8182

8283
- the prefix is related to the component `kind`
8384

@@ -92,6 +93,12 @@ An autogenerated `id` has a prefix and a sequential number
9293
| `function` | fn | _fn1, fn2,..._ |
9394
| `database` | db | _db1, db2,..._ |
9495

96+
## Connections
97+
98+
You can connect each component by arrows.
99+
100+
To be able to connect an _origin component_ with one or more _target component_ you need to specify each `componentId`.
101+
95102
A `connection` has the following properties:
96103

97104
```go
@@ -112,191 +119,52 @@ type Connection struct {
112119

113120
## Example 1 - Message Bus Pattern
114121

115-
Create the `draft` architecture descriptor YAML with your favorite editor:
116-
117-
```yaml
118-
title: message bus pattern
119-
backgroundColor: '#ffffff'
120-
components:
121-
-
122-
kind: service
123-
label: Producer
124-
provider: AWS EC2
125-
-
126-
kind: broker
127-
label: "Notification\nService"
128-
provider: AWS SNS
129-
-
130-
kind: queue
131-
label: "event queue @ topic 1"
132-
provider: AWS SQS
133-
-
134-
kind: queue
135-
label: "event queue @ topic 2"
136-
provider: AWS SQS
137-
-
138-
kind: service
139-
label: "Consumer\n@ topic 1"
140-
provider: AWS EC2
141-
-
142-
kind: service
143-
label: "Consumer\n@ topic 2"
144-
provider: AWS EC2
145-
connections:
146-
-
147-
origin:
148-
componentId: ms1
149-
targets:
150-
-
151-
componentId: br1
152-
-
153-
origin:
154-
componentId: br1
155-
targets:
156-
-
157-
componentId: qs1
158-
dashed: true
159-
-
160-
componentId: qs2
161-
dashed: true
162-
-
163-
origin:
164-
componentId: qs1
165-
targets:
166-
-
167-
componentId: ms2
168-
dir: back
169-
-
170-
origin:
171-
componentId: qs2
172-
targets:
173-
-
174-
componentId: ms3
175-
dir: back
176-
```
122+
The `draft` architecture descriptor YAML file is here 👉 [./examples/message-bus-pattern.yml](./examples/message-bus-pattern.yml)
177123

178-
Then run `draft`:
124+
Running `draft` with this command:
179125

180126
```bash
181127
draft message-bus-pattern.yml | dot -Tpng > message-bus-pattern.png
182128
```
183129

184-
Here the generated output:
130+
Will generate this output:
185131

186132
![](./examples/message-bus-pattern.png)
187133

188134

189135
## Example 2 - AWS Cognito Custom Authentication Flow
190136

191-
Create the draft architecture descriptor YAML with your favorite editor:
192-
193-
```yaml
194-
title: Amazon Cognito Custom Authentication Flow with external database
195-
backgroundColor: '#ffffff'
196-
components:
197-
-
198-
kind: client
199-
label: "Web App"
200-
-
201-
kind: client
202-
label: "Mobile App"
203-
-
204-
kind: service
205-
label: "Cognito"
206-
provider: "AWS Cognito"
207-
fillColor: '#991919'
208-
fontColor: '#fafafa'
209-
-
210-
kind: function
211-
label: "Define\nAuthChallange"
212-
provider: "AWS Lambda"
213-
-
214-
kind: function
215-
label: "Create\nAuthChallange"
216-
provider: "AWS Lambda"
217-
-
218-
kind: function
219-
label: "Verify\nAuthChallange"
220-
provider: "AWS Lambda"
221-
-
222-
kind: database
223-
label: "Users\nRepository"
224-
provider: "AWS RDS"
225-
connections:
226-
-
227-
origin:
228-
componentId: cl1
229-
targets:
230-
-
231-
componentId: ms1
232-
-
233-
origin:
234-
componentId: cl2
235-
targets:
236-
-
237-
componentId: ms1
238-
-
239-
origin:
240-
componentId: ms1
241-
targets:
242-
-
243-
componentId: fn1
244-
-
245-
componentId: fn2
246-
-
247-
componentId: fn3
248-
-
249-
origin:
250-
componentId: fn2
251-
targets:
252-
-
253-
componentId: db1
137+
The `draft` architecture descriptor YAML file is here 👉 [./examples/aws-cognito-custom-auth-flow.yml](./examples/aws-cognito-custom-auth-flow.yml)
138+
139+
Running `draft` with this command:
140+
141+
```bash
142+
draft aws-cognito-custom-auth-flow.yml | dot -Tpng > aws-cognito-custom-auth-flow.png
254143
```
255144

256-
Here the generated output:
145+
Will generate this output:
257146

258147
![](./examples/aws-cognito-custom-auth-flow.png)
259148

260149
## Example 3 - Getting the pre-signed URL to Upload a file to Amazon S3
261150

262-
```yaml
263-
title: Upload file to S3 using Lambda for pre-signed URL
264-
backgroundColor: '#ffffff'
265-
components:
266-
-
267-
kind: client
268-
label: "Web App"
269-
provider: SPA
270-
-
271-
kind: gateway
272-
provider: "AWS API Gateway"
273-
-
274-
kind: function
275-
label: "Get\nPre-Signed URL"
276-
provider: "AWS Lambda"
277-
-
278-
kind: storage
279-
label: "*.jpg\n*.png"
280-
provider: "AWS S3"
281-
connections:
282-
-
283-
origin:
284-
componentId: cl1
285-
targets:
286-
-
287-
componentId: gt1
288-
-
289-
origin:
290-
componentId: gt1
291-
targets:
292-
-
293-
componentId: fn1
294-
-
295-
origin:
296-
componentId: fn1
297-
targets:
298-
-
299-
componentId: st1
151+
152+
The `draft` architecture descriptor YAML file is here 👉 [./examples/s3-upload-presigned-url.yml](./examples/s3-upload-presigned-url.yml)
153+
154+
Running `draft` with this command:
155+
156+
```bash
157+
draft s3-upload-presigned-url.yml | dot -Tpng > s3-upload-presigned-url.png
300158
```
301159

302-
![](./examples/s3-upload-presigned-url.png)
160+
![](./examples/s3-upload-presigned-url.png)
161+
162+
## Others examples
163+
164+
Check out the 👉 [./examples/](/examples/) folders for more `draft` architecture descriptor YAML examples.
165+
166+
167+
168+
---
169+
170+
(c) 2020 Luca Sepe http://lucasepe.it. MIT License

broker.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ func (rcv *broker) sketch(graph *dot.Graph, comp Component) {
2626

2727
label := comp.Label
2828
if strings.TrimSpace(comp.Label) == "" {
29-
label = "Message Broker"
29+
label = "Message\nBroker"
3030
}
3131

32-
cl := cluster.New(graph, id, cluster.Label(comp.Provider))
32+
cl := cluster.New(graph, id, cluster.Label(comp.Impl))
3333

3434
el := node.New(cl, id,
3535
node.Label(label),
@@ -38,7 +38,8 @@ func (rcv *broker) sketch(graph *dot.Graph, comp Component) {
3838
node.FillColor(comp.FillColor, "#e0eeeeff"),
3939
node.Shape("cds"),
4040
)
41-
el.Attr("height", "0.8")
41+
el.Attr("height", "0.6")
42+
el.Attr("width", "1.2")
4243
}
4344

4445
/** Alternative

client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (rcv *client) sketch(graph *dot.Graph, comp Component) {
2424
id = rcv.nextID()
2525
}
2626

27-
cl := cluster.New(graph, id, cluster.Label(comp.Provider))
27+
cl := cluster.New(graph, id, cluster.Label(comp.Impl))
2828

2929
el := node.New(cl, id,
3030
node.Label(comp.Label),

database.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (rcv *database) sketch(graph *dot.Graph, comp Component) {
2424
id = rcv.nextID()
2525
}
2626

27-
cl := cluster.New(graph, id, cluster.Label(comp.Provider))
27+
cl := cluster.New(graph, id, cluster.Label(comp.Impl))
2828

2929
el := node.New(cl, id,
3030
node.Label(comp.Label),

draft.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package draft
33
import (
44
"fmt"
55
"io"
6+
"strings"
67

78
"github.com/emicklei/dot"
9+
"github.com/lucasepe/draft/pkg/cluster"
810
"github.com/lucasepe/draft/pkg/edge"
911
"github.com/lucasepe/draft/pkg/graph"
1012
"gopkg.in/yaml.v2"
@@ -41,6 +43,7 @@ type Component struct {
4143
ID string `yaml:"id,omitempty"`
4244
Kind string `yaml:"kind"`
4345
Label string `yaml:"label,omitempty"`
46+
Impl string `yaml:"impl,omitempty"`
4447
Provider string `yaml:"provider,omitempty"`
4548
FillColor string `yaml:"fillColor,omitempty"`
4649
FontColor string `yaml:"fontColor,omitempty"`
@@ -109,7 +112,16 @@ func sketchComponents(graph *dot.Graph, draft *Draft) error {
109112
return fmt.Errorf("render not found for component of kind '%s'", el.Kind)
110113
}
111114

112-
sketcher.sketch(graph, el)
115+
parent := graph
116+
if strings.TrimSpace(el.Provider) != "" {
117+
parent = cluster.New(graph, el.Provider,
118+
cluster.PenColor("#d9cc31"),
119+
cluster.FontName("Fira Mono"),
120+
cluster.FontSize(10),
121+
cluster.FontColor("#63625b"))
122+
}
123+
124+
sketcher.sketch(parent, el)
113125
}
114126

115127
return nil
-2.72 KB
Loading

0 commit comments

Comments
 (0)