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

Commit 98bf924

Browse files
committed
Add new components: container-service, waf; new example; bottom top layout
1 parent f3e7535 commit 98bf924

31 files changed

+387
-74
lines changed

README.md

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,22 @@ Eventually you can describe...
6060

6161
Below is a list of all the components currently implemented.
6262

63-
| Component | Kind | YAML | Output |
64-
|:-------------------|:------------|:--------------------------------------------------------------|:---------------------------------:|
65-
| **Client** | `client` | 👉 [examples/client.yml](./examples/client.yml) | ![](./examples/client.png) |
66-
| **Microservice** | `service` | 👉 [examples/service.yml](./examples/service.yml) | ![](./examples/service.png) |
67-
| **Gateway** | `gateway` | 👉 [examples/gateway.yml](./examples/gateway.yml) | ![](./examples/gateway.png) |
68-
| **Message Broker** | `broker` | 👉 [examples/broker.yml](./examples/broker.yml) | ![](./examples/broker.png) |
69-
| **Queue Service** | `queue` | 👉 [examples/queue.yml](./examples/queue.yml) | ![](./examples/queue.png) |
70-
| **Object Storage** | `storage` | 👉 [examples/storage.yml](./examples/storage.yml) | ![](./examples/storage.png) |
71-
| **Function** | `function` | 👉 [examples/function.yml](./examples/function.yml) | ![](./examples/function.png) |
72-
| **Database** | `database` | 👉 [examples/database.yml](./examples/database.yml) | ![](./examples/database.png) |
73-
| **Load Balancer** | `balancer` | 👉 [examples/balancer.yml](./examples/balancer.yml) | ![](./examples/balancer.png) |
74-
| **CDN** | `cdn` | 👉 [examples/cdn.yml](./examples/cdn.yml) | ![](./examples/cdn.png) |
75-
| **DNS** | `dns` | 👉 [examples/dns.yml](./examples/dns.yml) | ![](./examples/dns.png) |
76-
| **Custom Html** | `html` | 👉 [examples/custom_image.yml](./examples/custom_image.yml) | ![](./examples/custom_image.png) |
63+
| Component | Kind | YAML | Output |
64+
|:----------------------|:------------|:--------------------------------------------------------------|:---------------------------------:|
65+
| **Client** | `client` | 👉 [examples/client.yml](./examples/client.yml) | ![](./examples/client.png) |
66+
| **Microservice** | `service` | 👉 [examples/service.yml](./examples/service.yml) | ![](./examples/service.png) |
67+
| **Gateway** | `gateway` | 👉 [examples/gateway.yml](./examples/gateway.yml) | ![](./examples/gateway.png) |
68+
| **Firewall** | `waf` | 👉 [examples/waf.yml](./examples/waf.yml) | ![](./examples/waf.png) |
69+
| **Container Service** | `cos` | 👉 [examples/waf.yml](./examples/cos.yml) | ![](./examples/cos.png) |
70+
| **Message Broker** | `broker` | 👉 [examples/broker.yml](./examples/broker.yml) | ![](./examples/broker.png) |
71+
| **Queue Service** | `queue` | 👉 [examples/queue.yml](./examples/queue.yml) | ![](./examples/queue.png) |
72+
| **Object Storage** | `storage` | 👉 [examples/storage.yml](./examples/storage.yml) | ![](./examples/storage.png) |
73+
| **Function** | `function` | 👉 [examples/function.yml](./examples/function.yml) | ![](./examples/function.png) |
74+
| **Database** | `database` | 👉 [examples/database.yml](./examples/database.yml) | ![](./examples/database.png) |
75+
| **Load Balancer** | `balancer` | 👉 [examples/balancer.yml](./examples/balancer.yml) | ![](./examples/balancer.png) |
76+
| **CDN** | `cdn` | 👉 [examples/cdn.yml](./examples/cdn.yml) | ![](./examples/cdn.png) |
77+
| **DNS** | `dns` | 👉 [examples/dns.yml](./examples/dns.yml) | ![](./examples/dns.png) |
78+
| **Custom Html** | `html` | 👉 [examples/custom_image.yml](./examples/custom_image.yml) | ![](./examples/custom_image.png) |
7779

7880
For custom HTML components (_kind: html_) only these tags are supported:
7981

@@ -96,6 +98,7 @@ An auto-generated component `id` has a prefix and a sequential number
9698
| `client` | cl | _cl1, cl2,..._ |
9799
| `service` | ms | _ms1, ms2,..._ |
98100
| `gateway` | gt | _gt1, gt2,..._ |
101+
| `gateway` | waf | _waf1, waf2,..._ |
99102
| `broker` | br | _br1, br2,..._ |
100103
| `queue` | qs | _qs1, qs2,..._ |
101104
| `storage` | st | _st1, st2,..._ |
@@ -105,6 +108,7 @@ An auto-generated component `id` has a prefix and a sequential number
105108
| `cdn` | cn | _cn1, cn2,..._ |
106109
| `dns` | dn | _dn1, dn2,..._ |
107110
| `html` | htm | _htm1, htm2,..._ |
111+
| `cos` | cos | _cos1, cos2,..._ |
108112

109113
## Connections
110114

@@ -172,6 +176,19 @@ draft s3-upload-presigned-url.yml | dot -Tpng > s3-upload-presigned-url.png
172176

173177
![](./examples/s3-upload-presigned-url.png)
174178

179+
## Example 4 - A system view
180+
181+
The `draft` architecture descriptor YAML file is here 👉 [./examples/system-view.yml](./examples/system-view.yml)
182+
183+
Running `draft` with this command:
184+
185+
```bash
186+
draft system-view.yml | dot -Tpng > system-view.png
187+
```
188+
189+
![](./examples/system-view.png)
190+
191+
175192
## Others examples
176193

177194
Check out the 👉 [./examples/](/examples/) folders for more `draft` architecture descriptor YAML examples.

balancer.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ func (rcv *balancer) nextID() string {
1818
return fmt.Sprintf("lb%d", rcv.seq)
1919
}
2020

21-
func (rcv *balancer) sketch(graph *dot.Graph, comp Component) {
21+
func (rcv *balancer) sketch(graph *dot.Graph, comp Component, bottomTop bool) {
2222
id := comp.ID
2323
if strings.TrimSpace(comp.ID) == "" {
2424
id = rcv.nextID()
2525
}
2626

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

2929
el := node.New(cl, id,
3030
node.Label("LB", false),
@@ -33,5 +33,6 @@ func (rcv *balancer) sketch(graph *dot.Graph, comp Component) {
3333
node.FillColor(comp.FillColor, "#1a5276ff"),
3434
node.Shape("Mdiamond"),
3535
)
36+
el.Attr("width", "0.3")
3637
el.Attr("height", "0.3")
3738
}

broker.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ func (rcv *broker) nextID() string {
1818
return fmt.Sprintf("br%d", rcv.seq)
1919
}
2020

21-
func (rcv *broker) sketch(graph *dot.Graph, comp Component) {
21+
func (rcv *broker) sketch(graph *dot.Graph, comp Component, bottomTop bool) {
2222
id := comp.ID
2323
if strings.TrimSpace(comp.ID) == "" {
2424
id = rcv.nextID()
2525
}
2626

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

2929
el := node.New(cl, id,
3030
node.Label("Message Broker", false),

cdn.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ func (rcv *cdn) nextID() string {
1818
return fmt.Sprintf("cn%d", rcv.seq)
1919
}
2020

21-
func (rcv *cdn) sketch(graph *dot.Graph, comp Component) {
21+
func (rcv *cdn) sketch(graph *dot.Graph, comp Component, bottomTop bool) {
2222
id := comp.ID
2323
if strings.TrimSpace(comp.ID) == "" {
2424
id = rcv.nextID()
2525
}
2626

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

2929
el := node.New(cl, id,
3030
node.Label("CDN", false),

client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ func (rcv *client) nextID() string {
1818
return fmt.Sprintf("cl%d", rcv.seq)
1919
}
2020

21-
func (rcv *client) sketch(graph *dot.Graph, comp Component) {
21+
func (rcv *client) sketch(graph *dot.Graph, comp Component, bottomTop bool) {
2222
id := comp.ID
2323
if strings.TrimSpace(comp.ID) == "" {
2424
id = rcv.nextID()
2525
}
2626

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

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

cmd/draft-all.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ declare -a arr=("$SRC_DIR/client.yml"
1616
"$SRC_DIR/balancer.yml"
1717
"$SRC_DIR/cdn.yml"
1818
"$SRC_DIR/dns.yml"
19+
"$SRC_DIR/waf.yml"
20+
"$SRC_DIR/cos.yml"
1921
"$SRC_DIR/custom_image.yml"
22+
"$SRC_DIR/system-view.yml"
2023
"$SRC_DIR/message-bus-pattern.yml"
2124
"$SRC_DIR/aws-cognito-custom-auth-flow.yml"
2225
"$SRC_DIR/s3-upload-presigned-url.yml"

cmd/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ var (
2828
version = "dev"
2929
commit = "none"
3030
date = "unknown"
31+
32+
flagBottomTop bool
33+
flagOrtho bool
3134
)
3235

3336
func main() {
@@ -49,6 +52,9 @@ func main() {
4952
ark, err := draft.NewDraft(file)
5053
handleErr(err)
5154

55+
ark.BottomTop(flagBottomTop)
56+
ark.Ortho(flagOrtho)
57+
5258
str, err := ark.Sketch()
5359
handleErr(err)
5460

@@ -87,6 +93,9 @@ func configureFlags() {
8793
flag.CommandLine.SetOutput(ioutil.Discard) // hide flag errors
8894
flag.CommandLine.Init(os.Args[0], flag.ExitOnError)
8995

96+
flag.CommandLine.BoolVar(&flagBottomTop, "bottom-top", false, "if true sets layout dir as bottom top")
97+
flag.CommandLine.BoolVar(&flagOrtho, "ortho", false, "if true edges are drawn as line segments")
98+
9099
flag.CommandLine.Parse(os.Args[1:])
91100
}
92101

container_service.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package draft
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
"github.com/emicklei/dot"
8+
"github.com/lucasepe/draft/pkg/cluster"
9+
"github.com/lucasepe/draft/pkg/node"
10+
)
11+
12+
type containerService struct {
13+
seq int16
14+
}
15+
16+
func (rcv *containerService) nextID() string {
17+
rcv.seq++
18+
return fmt.Sprintf("cos%d", rcv.seq)
19+
}
20+
21+
func (rcv *containerService) sketch(graph *dot.Graph, comp Component, bottomTop bool) {
22+
id := comp.ID
23+
if strings.TrimSpace(comp.ID) == "" {
24+
id = rcv.nextID()
25+
}
26+
27+
fontColor := "#fafafaff"
28+
if strings.TrimSpace(comp.FontColor) != "" {
29+
fontColor = comp.FontColor
30+
}
31+
32+
cl := cluster.New(graph, id, cluster.BottomTop(bottomTop), cluster.Label(comp.Impl))
33+
34+
el := node.New(cl, id,
35+
node.Label("Container\nService", false),
36+
node.FontColor(fontColor),
37+
node.FillColor(comp.FillColor, "#64a365"),
38+
node.Shape("component"),
39+
)
40+
el.Attr("height", "0.3")
41+
}

database.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ func (rcv *database) nextID() string {
1818
return fmt.Sprintf("db%d", rcv.seq)
1919
}
2020

21-
func (rcv *database) sketch(graph *dot.Graph, comp Component) {
21+
func (rcv *database) sketch(graph *dot.Graph, comp Component, bottomTop bool) {
2222
id := comp.ID
2323
if strings.TrimSpace(comp.ID) == "" {
2424
id = rcv.nextID()
2525
}
2626

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

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

dns.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ func (rcv *dns) nextID() string {
1818
return fmt.Sprintf("dn%d", rcv.seq)
1919
}
2020

21-
func (rcv *dns) sketch(graph *dot.Graph, comp Component) {
21+
func (rcv *dns) sketch(graph *dot.Graph, comp Component, bottomTop bool) {
2222
id := comp.ID
2323
if strings.TrimSpace(comp.ID) == "" {
2424
id = rcv.nextID()
2525
}
2626

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

2929
el := node.New(cl, id,
3030
node.Label("DNS", false),

0 commit comments

Comments
 (0)