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

Commit

Permalink
[issue #1] common provider for one or more nodes
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
lucasepe committed Jun 8, 2020
1 parent 9312030 commit ba40918
Show file tree
Hide file tree
Showing 37 changed files with 104 additions and 273 deletions.
238 changes: 53 additions & 185 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,32 @@ To install GraphViz to your favorite OS, please, follow this link [https://graph

## Components

### A picture is worth a thousand words
> a picture is worth a thousand words
... and this is particularly true in regard to complex IT architectures.

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

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

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

- you can eventually describe the implementation using the `provider` attribute.
Eventually you can describe...

- the implementation using the `impl` attribute (ie: _impl: 'SQS'_)
- the cloud provider using the `provider` attribute (ie: _provider: AWS_)
- 💡 components with the same provider will be 'grouped'

Below is a list of all the components currently implemented.

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

## Connections
### Notes about a component `id`

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

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

- you can define your component `id` explicitly
- you can omit the component `id` attribute and it will be autogenerated

### Autogenerated `id`

An autogenerated `id` has a prefix and a sequential number
An auto-generated component `id` has a prefix and a sequential number

- the prefix is related to the component `kind`

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

## Connections

You can connect each component by arrows.

To be able to connect an _origin component_ with one or more _target component_ you need to specify each `componentId`.

A `connection` has the following properties:

```go
Expand All @@ -112,191 +119,52 @@ type Connection struct {

## Example 1 - Message Bus Pattern

Create the `draft` architecture descriptor YAML with your favorite editor:

```yaml
title: message bus pattern
backgroundColor: '#ffffff'
components:
-
kind: service
label: Producer
provider: AWS EC2
-
kind: broker
label: "Notification\nService"
provider: AWS SNS
-
kind: queue
label: "event queue @ topic 1"
provider: AWS SQS
-
kind: queue
label: "event queue @ topic 2"
provider: AWS SQS
-
kind: service
label: "Consumer\n@ topic 1"
provider: AWS EC2
-
kind: service
label: "Consumer\n@ topic 2"
provider: AWS EC2
connections:
-
origin:
componentId: ms1
targets:
-
componentId: br1
-
origin:
componentId: br1
targets:
-
componentId: qs1
dashed: true
-
componentId: qs2
dashed: true
-
origin:
componentId: qs1
targets:
-
componentId: ms2
dir: back
-
origin:
componentId: qs2
targets:
-
componentId: ms3
dir: back
```
The `draft` architecture descriptor YAML file is here 👉 [./examples/message-bus-pattern.yml](./examples/message-bus-pattern.yml)

Then run `draft`:
Running `draft` with this command:

```bash
draft message-bus-pattern.yml | dot -Tpng > message-bus-pattern.png
```

Here the generated output:
Will generate this output:

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


## Example 2 - AWS Cognito Custom Authentication Flow

Create the draft architecture descriptor YAML with your favorite editor:

```yaml
title: Amazon Cognito Custom Authentication Flow with external database
backgroundColor: '#ffffff'
components:
-
kind: client
label: "Web App"
-
kind: client
label: "Mobile App"
-
kind: service
label: "Cognito"
provider: "AWS Cognito"
fillColor: '#991919'
fontColor: '#fafafa'
-
kind: function
label: "Define\nAuthChallange"
provider: "AWS Lambda"
-
kind: function
label: "Create\nAuthChallange"
provider: "AWS Lambda"
-
kind: function
label: "Verify\nAuthChallange"
provider: "AWS Lambda"
-
kind: database
label: "Users\nRepository"
provider: "AWS RDS"
connections:
-
origin:
componentId: cl1
targets:
-
componentId: ms1
-
origin:
componentId: cl2
targets:
-
componentId: ms1
-
origin:
componentId: ms1
targets:
-
componentId: fn1
-
componentId: fn2
-
componentId: fn3
-
origin:
componentId: fn2
targets:
-
componentId: db1
The `draft` architecture descriptor YAML file is here 👉 [./examples/aws-cognito-custom-auth-flow.yml](./examples/aws-cognito-custom-auth-flow.yml)

Running `draft` with this command:

```bash
draft aws-cognito-custom-auth-flow.yml | dot -Tpng > aws-cognito-custom-auth-flow.png
```

Here the generated output:
Will generate this output:

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

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

```yaml
title: Upload file to S3 using Lambda for pre-signed URL
backgroundColor: '#ffffff'
components:
-
kind: client
label: "Web App"
provider: SPA
-
kind: gateway
provider: "AWS API Gateway"
-
kind: function
label: "Get\nPre-Signed URL"
provider: "AWS Lambda"
-
kind: storage
label: "*.jpg\n*.png"
provider: "AWS S3"
connections:
-
origin:
componentId: cl1
targets:
-
componentId: gt1
-
origin:
componentId: gt1
targets:
-
componentId: fn1
-
origin:
componentId: fn1
targets:
-
componentId: st1

The `draft` architecture descriptor YAML file is here 👉 [./examples/s3-upload-presigned-url.yml](./examples/s3-upload-presigned-url.yml)

Running `draft` with this command:

```bash
draft s3-upload-presigned-url.yml | dot -Tpng > s3-upload-presigned-url.png
```

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

## Others examples

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



---

(c) 2020 Luca Sepe http://lucasepe.it. MIT License
7 changes: 4 additions & 3 deletions broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ func (rcv *broker) sketch(graph *dot.Graph, comp Component) {

label := comp.Label
if strings.TrimSpace(comp.Label) == "" {
label = "Message Broker"
label = "Message\nBroker"
}

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

el := node.New(cl, id,
node.Label(label),
Expand All @@ -38,7 +38,8 @@ func (rcv *broker) sketch(graph *dot.Graph, comp Component) {
node.FillColor(comp.FillColor, "#e0eeeeff"),
node.Shape("cds"),
)
el.Attr("height", "0.8")
el.Attr("height", "0.6")
el.Attr("width", "1.2")
}

/** Alternative
Expand Down
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (rcv *client) sketch(graph *dot.Graph, comp Component) {
id = rcv.nextID()
}

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

el := node.New(cl, id,
node.Label(comp.Label),
Expand Down
2 changes: 1 addition & 1 deletion database.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (rcv *database) sketch(graph *dot.Graph, comp Component) {
id = rcv.nextID()
}

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

el := node.New(cl, id,
node.Label(comp.Label),
Expand Down
14 changes: 13 additions & 1 deletion draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package draft
import (
"fmt"
"io"
"strings"

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

sketcher.sketch(graph, el)
parent := graph
if strings.TrimSpace(el.Provider) != "" {
parent = cluster.New(graph, el.Provider,
cluster.PenColor("#d9cc31"),
cluster.FontName("Fira Mono"),
cluster.FontSize(10),
cluster.FontColor("#63625b"))
}

sketcher.sketch(parent, el)
}

return nil
Expand Down
Binary file modified examples/aws-cognito-custom-auth-flow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit ba40918

Please sign in to comment.