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

Commit

Permalink
Add new components: container-service, waf; new example; bottom top l…
Browse files Browse the repository at this point in the history
…ayout
  • Loading branch information
lucasepe committed Jun 11, 2020
1 parent f3e7535 commit 98bf924
Show file tree
Hide file tree
Showing 31 changed files with 387 additions and 74 deletions.
45 changes: 31 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 60,22 @@ Eventually you can describe...

Below is a list of all the components currently implemented.

| Component | Kind | YAML | Output |
|:-------------------|:------------|:--------------------------------------------------------------|:---------------------------------:|
| **Client** | `client` | 👉 [examples/client.yml](./examples/client.yml) | ![](./examples/client.png) |
| **Microservice** | `service` | 👉 [examples/service.yml](./examples/service.yml) | ![](./examples/service.png) |
| **Gateway** | `gateway` | 👉 [examples/gateway.yml](./examples/gateway.yml) | ![](./examples/gateway.png) |
| **Message Broker** | `broker` | 👉 [examples/broker.yml](./examples/broker.yml) | ![](./examples/broker.png) |
| **Queue Service** | `queue` | 👉 [examples/queue.yml](./examples/queue.yml) | ![](./examples/queue.png) |
| **Object Storage** | `storage` | 👉 [examples/storage.yml](./examples/storage.yml) | ![](./examples/storage.png) |
| **Function** | `function` | 👉 [examples/function.yml](./examples/function.yml) | ![](./examples/function.png) |
| **Database** | `database` | 👉 [examples/database.yml](./examples/database.yml) | ![](./examples/database.png) |
| **Load Balancer** | `balancer` | 👉 [examples/balancer.yml](./examples/balancer.yml) | ![](./examples/balancer.png) |
| **CDN** | `cdn` | 👉 [examples/cdn.yml](./examples/cdn.yml) | ![](./examples/cdn.png) |
| **DNS** | `dns` | 👉 [examples/dns.yml](./examples/dns.yml) | ![](./examples/dns.png) |
| **Custom Html** | `html` | 👉 [examples/custom_image.yml](./examples/custom_image.yml) | ![](./examples/custom_image.png) |
| Component | Kind | YAML | Output |
|:----------------------|:------------|:--------------------------------------------------------------|:---------------------------------:|
| **Client** | `client` | 👉 [examples/client.yml](./examples/client.yml) | ![](./examples/client.png) |
| **Microservice** | `service` | 👉 [examples/service.yml](./examples/service.yml) | ![](./examples/service.png) |
| **Gateway** | `gateway` | 👉 [examples/gateway.yml](./examples/gateway.yml) | ![](./examples/gateway.png) |
| **Firewall** | `waf` | 👉 [examples/waf.yml](./examples/waf.yml) | ![](./examples/waf.png) |
| **Container Service** | `cos` | 👉 [examples/waf.yml](./examples/cos.yml) | ![](./examples/cos.png) |
| **Message Broker** | `broker` | 👉 [examples/broker.yml](./examples/broker.yml) | ![](./examples/broker.png) |
| **Queue Service** | `queue` | 👉 [examples/queue.yml](./examples/queue.yml) | ![](./examples/queue.png) |
| **Object Storage** | `storage` | 👉 [examples/storage.yml](./examples/storage.yml) | ![](./examples/storage.png) |
| **Function** | `function` | 👉 [examples/function.yml](./examples/function.yml) | ![](./examples/function.png) |
| **Database** | `database` | 👉 [examples/database.yml](./examples/database.yml) | ![](./examples/database.png) |
| **Load Balancer** | `balancer` | 👉 [examples/balancer.yml](./examples/balancer.yml) | ![](./examples/balancer.png) |
| **CDN** | `cdn` | 👉 [examples/cdn.yml](./examples/cdn.yml) | ![](./examples/cdn.png) |
| **DNS** | `dns` | 👉 [examples/dns.yml](./examples/dns.yml) | ![](./examples/dns.png) |
| **Custom Html** | `html` | 👉 [examples/custom_image.yml](./examples/custom_image.yml) | ![](./examples/custom_image.png) |

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

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

## Connections

Expand Down Expand Up @@ -172,6 176,19 @@ draft s3-upload-presigned-url.yml | dot -Tpng > s3-upload-presigned-url.png

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

## Example 4 - A system view

The `draft` architecture descriptor YAML file is here 👉 [./examples/system-view.yml](./examples/system-view.yml)

Running `draft` with this command:

```bash
draft system-view.yml | dot -Tpng > system-view.png
```

![](./examples/system-view.png)


## Others examples

Check out the 👉 [./examples/](/examples/) folders for more `draft` architecture descriptor YAML examples.
Expand Down
5 changes: 3 additions & 2 deletions balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 18,13 @@ func (rcv *balancer) nextID() string {
return fmt.Sprintf("lb%d", rcv.seq)
}

func (rcv *balancer) sketch(graph *dot.Graph, comp Component) {
func (rcv *balancer) sketch(graph *dot.Graph, comp Component, bottomTop bool) {
id := comp.ID
if strings.TrimSpace(comp.ID) == "" {
id = rcv.nextID()
}

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

el := node.New(cl, id,
node.Label("LB", false),
Expand All @@ -33,5 33,6 @@ func (rcv *balancer) sketch(graph *dot.Graph, comp Component) {
node.FillColor(comp.FillColor, "#1a5276ff"),
node.Shape("Mdiamond"),
)
el.Attr("width", "0.3")
el.Attr("height", "0.3")
}
4 changes: 2 additions & 2 deletions broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 18,13 @@ func (rcv *broker) nextID() string {
return fmt.Sprintf("br%d", rcv.seq)
}

func (rcv *broker) sketch(graph *dot.Graph, comp Component) {
func (rcv *broker) sketch(graph *dot.Graph, comp Component, bottomTop bool) {
id := comp.ID
if strings.TrimSpace(comp.ID) == "" {
id = rcv.nextID()
}

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

el := node.New(cl, id,
node.Label("Message Broker", false),
Expand Down
4 changes: 2 additions & 2 deletions cdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 18,13 @@ func (rcv *cdn) nextID() string {
return fmt.Sprintf("cn%d", rcv.seq)
}

func (rcv *cdn) sketch(graph *dot.Graph, comp Component) {
func (rcv *cdn) sketch(graph *dot.Graph, comp Component, bottomTop bool) {
id := comp.ID
if strings.TrimSpace(comp.ID) == "" {
id = rcv.nextID()
}

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

el := node.New(cl, id,
node.Label("CDN", false),
Expand Down
4 changes: 2 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 18,13 @@ func (rcv *client) nextID() string {
return fmt.Sprintf("cl%d", rcv.seq)
}

func (rcv *client) sketch(graph *dot.Graph, comp Component) {
func (rcv *client) sketch(graph *dot.Graph, comp Component, bottomTop bool) {
id := comp.ID
if strings.TrimSpace(comp.ID) == "" {
id = rcv.nextID()
}

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

el := node.New(cl, id,
node.Label(comp.Label, false),
Expand Down
3 changes: 3 additions & 0 deletions cmd/draft-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 16,10 @@ declare -a arr=("$SRC_DIR/client.yml"
"$SRC_DIR/balancer.yml"
"$SRC_DIR/cdn.yml"
"$SRC_DIR/dns.yml"
"$SRC_DIR/waf.yml"
"$SRC_DIR/cos.yml"
"$SRC_DIR/custom_image.yml"
"$SRC_DIR/system-view.yml"
"$SRC_DIR/message-bus-pattern.yml"
"$SRC_DIR/aws-cognito-custom-auth-flow.yml"
"$SRC_DIR/s3-upload-presigned-url.yml"
Expand Down
9 changes: 9 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 28,9 @@ var (
version = "dev"
commit = "none"
date = "unknown"

flagBottomTop bool
flagOrtho bool
)

func main() {
Expand All @@ -49,6 52,9 @@ func main() {
ark, err := draft.NewDraft(file)
handleErr(err)

ark.BottomTop(flagBottomTop)
ark.Ortho(flagOrtho)

str, err := ark.Sketch()
handleErr(err)

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

flag.CommandLine.BoolVar(&flagBottomTop, "bottom-top", false, "if true sets layout dir as bottom top")
flag.CommandLine.BoolVar(&flagOrtho, "ortho", false, "if true edges are drawn as line segments")

flag.CommandLine.Parse(os.Args[1:])
}

Expand Down
41 changes: 41 additions & 0 deletions container_service.go
Original file line number Diff line number Diff line change
@@ -0,0 1,41 @@
package draft

import (
"fmt"
"strings"

"github.com/emicklei/dot"
"github.com/lucasepe/draft/pkg/cluster"
"github.com/lucasepe/draft/pkg/node"
)

type containerService struct {
seq int16
}

func (rcv *containerService) nextID() string {
rcv.seq
return fmt.Sprintf("cos%d", rcv.seq)
}

func (rcv *containerService) sketch(graph *dot.Graph, comp Component, bottomTop bool) {
id := comp.ID
if strings.TrimSpace(comp.ID) == "" {
id = rcv.nextID()
}

fontColor := "#fafafaff"
if strings.TrimSpace(comp.FontColor) != "" {
fontColor = comp.FontColor
}

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

el := node.New(cl, id,
node.Label("Container\nService", false),
node.FontColor(fontColor),
node.FillColor(comp.FillColor, "#64a365"),
node.Shape("component"),
)
el.Attr("height", "0.3")
}
4 changes: 2 additions & 2 deletions database.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 18,13 @@ func (rcv *database) nextID() string {
return fmt.Sprintf("db%d", rcv.seq)
}

func (rcv *database) sketch(graph *dot.Graph, comp Component) {
func (rcv *database) sketch(graph *dot.Graph, comp Component, bottomTop bool) {
id := comp.ID
if strings.TrimSpace(comp.ID) == "" {
id = rcv.nextID()
}

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

el := node.New(cl, id,
node.Label(comp.Label, false),
Expand Down
4 changes: 2 additions & 2 deletions dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 18,13 @@ func (rcv *dns) nextID() string {
return fmt.Sprintf("dn%d", rcv.seq)
}

func (rcv *dns) sketch(graph *dot.Graph, comp Component) {
func (rcv *dns) sketch(graph *dot.Graph, comp Component, bottomTop bool) {
id := comp.ID
if strings.TrimSpace(comp.ID) == "" {
id = rcv.nextID()
}

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

el := node.New(cl, id,
node.Label("DNS", false),
Expand Down
Loading

0 comments on commit 98bf924

Please sign in to comment.