draft

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 10, 2020 License: MIT Imports: 9 Imported by: 0

README ΒΆ

Draft

A commandline tool that generate High Level microservice & serverless Architecture diagrams using a declarative syntax defined in a YAML file.

How draft works?

draft takes in input a declarative YAML file and generates a dot script for Graphviz

draft backend-for-frontend.yml | dot -Tpng -Gdpi=200 > backend-for-frontend.png 

Piping the draft output to GraphViz dot you can generate the following output formats:

format command
GIF draft input.yml | dot -Tgif > output.gif
JPEG draft input.yml | dot -Tjpg > output.jpg
PostScript draft input.yml | dot -Tps > output.ps
PSD draft input.yml | dot -Tpsd > output.psd
SVG draft input.yml | dot -Tsvg > output.svg
WebP draft input.yml | dot -Twebp > output.webp

To install GraphViz to your favorite OS, please, follow this link https://graphviz.gitlab.io/download/.

Components

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:

type Component struct {
  ID        string `yaml:"id,omitempty"`        // optional - autogenerated if omitted (read more for details...)
  Kind      string `yaml:"kind"`                // required - see the table below
  Label     string `yaml:"label,omitempty"`     // optional - works only for: 'queue', 'service', 'storage', 'function', 'database', 'client'  
  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).

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.

Component Kind YAML Output
Client client πŸ‘‰ examples/client.yml
Microservice service πŸ‘‰ examples/service.yml
Gateway gateway πŸ‘‰ examples/gateway.yml
Message Broker broker πŸ‘‰ examples/broker.yml
Queue Service queue πŸ‘‰ examples/queue.yml
Object Storage storage πŸ‘‰ examples/storage.yml
Function function πŸ‘‰ examples/function.yml
Database database πŸ‘‰ examples/database.yml
Load Balancer balancer πŸ‘‰ examples/balancer.yml
CDN cdn πŸ‘‰ examples/cdn.yml
DNS dns πŸ‘‰ examples/dns.yml
Custom Html html πŸ‘‰ examples/custom_image.yml

For custom HTML components (kind: html) only these tags are supported:

  • <b>, <br/>, <font>, <hr>, <i>, <img> (in <td>…</td> only)
  • <o>, <s>, <sub>, <sup>, <table>, <tr>, <u>
Notes about a component id
  • 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
How is auto-generated a component id?

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

  • the prefix is related to the component kind
a kind of... will generate an id prefix with... example
client cl cl1, cl2,...
service ms ms1, ms2,...
gateway gt gt1, gt2,...
broker br br1, br2,...
queue qs qs1, qs2,...
storage st st1, st2,...
function fn fn1, fn2,...
database db db1, db2,...
balancer lb lb1, lb2,...
cdn cn cn1, cn2,...
dns dn dn1, dn2,...
html htm htm1, htm2,...

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:

type Connection struct {
  Origin struct {
    ComponentID string `yaml:"componentId"`
  } `yaml:"origin"`
  Targets []struct {
    ComponentID string `yaml:"componentId"`
    Label       string `yaml:"label,omitempty"`
    Color       string `yaml:"color,omitempty"`
    Dashed      bool   `yaml:"dashed,omitempty"`
    Dir         string `yaml:"dir,omitempty"`
    Highlight   bool   `yaml:"highlight,omitempty"`
  } `yaml:"targets"`
}

Example 1 - Message Bus Pattern

The draft architecture descriptor YAML file is here πŸ‘‰ ./examples/message-bus-pattern.yml

Running draft with this command:

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

Will generate this output:

Example 2 - AWS Cognito Custom Authentication Flow

The draft architecture descriptor YAML file is here πŸ‘‰ ./examples/aws-cognito-custom-auth-flow.yml

Running draft with this command:

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

Will generate this output:

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

The draft architecture descriptor YAML file is here πŸ‘‰ ./examples/s3-upload-presigned-url.yml

Running draft with this command:

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

Others examples

Check out the πŸ‘‰ ./examples/ folders for more draft architecture descriptor YAML examples.


(c) 2020 Luca Sepe http://lucasepe.it. MIT License

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

This section is empty.

Functions ΒΆ

This section is empty.

Types ΒΆ

type Component ΒΆ

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"`
	Rounded   bool   `yaml:"rounded,omitempty"`
}

Component is a basic architecture unit.

type Connection ΒΆ

type Connection struct {
	Origin struct {
		ComponentID string `yaml:"componentId"`
	} `yaml:"origin"`
	Targets []struct {
		ComponentID string `yaml:"componentId"`
		Label       string `yaml:"label,omitempty"`
		Color       string `yaml:"color,omitempty"`
		Dashed      bool   `yaml:"dashed,omitempty"`
		Dir         string `yaml:"dir,omitempty"`
		Highlight   bool   `yaml:"highlight,omitempty"`
	} `yaml:"targets"`
}

Connection is a link between two components.

type Draft ΒΆ

type Draft struct {
	Title           string       `yaml:"title,omitempty"`
	BackgroundColor string       `yaml:"backgroundColor,omitempty"`
	Components      []Component  `yaml:"components"`
	Connections     []Connection `yaml:"connections,omitempty"`
	// contains filtered or unexported fields
}

Draft represents a whole diagram.

func NewDraft ΒΆ

func NewDraft(r io.Reader) (*Draft, error)

NewDraft returns a new decoded Draft struct

func (*Draft) Sketch ΒΆ

func (ark *Draft) Sketch() (string, error)

Sketch generates the GraphViz definition for this architecture diagram.

Directories ΒΆ

Path Synopsis
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL