Create beautiful system diagrams with Go

Overview

Go-Diagrams

Fast and easy application diagrams

Go-Diagrams is a loose port of diagrams.

Contents

Features

Turn this:

d, err := diagram.New(diagram.Filename("app"), diagram.Label("App"), diagram.Direction("LR"))
if err != nil {
    log.Fatal(err)
}

dns := gcp.Network.Dns(diagram.NodeLabel("DNS"))
lb := gcp.Network.LoadBalancing(diagram.NodeLabel("NLB"))
cache := gcp.Database.Memorystore(diagram.NodeLabel("Cache"))
db := gcp.Database.Sql(diagram.NodeLabel("Database"))

dc := diagram.NewGroup("GCP")
dc.NewGroup("services").
    Label("Service Layer").
    Add(
        gcp.Compute.ComputeEngine(diagram.NodeLabel("Server 1")),
        gcp.Compute.ComputeEngine(diagram.NodeLabel("Server 2")),
        gcp.Compute.ComputeEngine(diagram.NodeLabel("Server 3")),
    ).
    ConnectAllFrom(lb.ID(), diagram.Forward()).
    ConnectAllTo(cache.ID(), diagram.Forward())

dc.NewGroup("data").Label("Data Layer").Add(cache, db).Connect(cache, db)

d.Connect(dns, lb, diagram.Forward()).Group(dc)

if err := d.Render(); err != nil {
    log.Fatal(err)
}

Into this:

app-diagram

Usage

go get github.com/blushft/go-diagrams

Create a diagram:

d, err := diagram.New(diagram.Label("my-diagram"), diagram.Filename("diagram"))
if err != nil {
    log.Fatal(err)
}

fw := generic.Network.Firewall().Label("fw")
sw := generic.Network.Switch().Label("sw")

d.Connect(fw, sw)

Render the output:

if err := d.Render(); err != nil {
    log.Fatal(err)
}

Go-Diagrams will create a folder in the current working directory with the graphviz DOT file and any image assets.

Create an ouput image with any graphviz compatible renderer:

dot -Tpng diagram.dot > diagram.png
Comments
  • Add NewDiagram to allow creating new diagrams from plain diagram.Options

    Add NewDiagram to allow creating new diagrams from plain diagram.Options

    This PR makes it possible to create a diagram from a plain *diagram.Options struct.

    The motivation behind this PR is that one cannot set the Name field of a diagram's options.
    While the preferred way of creating a diagram seems to be passing Option functions that override the default ones, allowing the user to simply pass the object is much more flexible.
    It is also not possible to create a Name function that would set that field, because the diagram package already contains such a function that sets a node's name.

    Maybe all node-related functions should be moved to a separate package to avoid such collisions?

    opened by qbarrand 3
  • Fix default values for groups and nodes.

    Fix default values for groups and nodes.

    This addresses https://github.com/blushft/go-diagrams/issues/12

    For groups, this strips the label if it's empty. For nodes, this uses empty string as the default label which also results in the label attribute being stripped if empty.

    This is necessary because otherwise the default values don't lead to valid graphviz code.

    opened by kdungs 1
  • Default labels for groups and nodes

    Default labels for groups and nodes

    Hello there,

    first of all thanks a lot for this library. :)

    tl;dr: i've found issues with the default labels for groups and prepared a corresponding PR.

    When trying it out, I found some issues with default labels, that can cause problems for newcomers especially if they don't know anything about graphviz.

    The default label for a group is the empty string. When rendered, it produces label=; which to graphviz is a syntax error. So, in order to produce a valid graph, at least the diagram.Label option is needed, as far as I see it. If I'm not mistaken, this could be fixed by adding a call to trimAttrs here: https://github.com/blushft/go-diagrams/blob/master/diagram/options.go#L39

    d, err := diagram.New(
    	diagram.Label("TEST"),
    )
    

    The default label for a node is "node". This is a reserved keyword in graphviz and when left unescaped causes problems. Since graphviz has logic for automatically labelling nodes, I would suggest using empty string here, as well and letting graphviz set the label. The alternative would be something like "\"node\"" which doesn't feel right to me. But feel free to suggest that on the PR if you see it differently.

    opened by kdungs 0
  • Add Screwdriver.cd

    Add Screwdriver.cd

    I added an icon for https://screwdriver.cd as ci tool.

    The tool's name has cd in it, but I've included it in the ci dir because I think the role of this tool is similar to that of Jenkins.

    opened by cappyzawa 0
  •  Warning: #@D3436 is not a known color.

    Warning: #@D3436 is not a known color.

    When I am using dot to produce JPG or PNG file I receive such a Warning:

    dot -Tjpg app.dot > ./1.jpg
     Warning: #@D3436 is not a known color.
    

    Note that all over other places code has #2D3436 not #@D3436 . https://github.com/blushft/go-diagrams/blob/master/diagram/node.go#L140

    opened by aLekSer 0
  • Label quote error

    Label quote error

    Use as label first 8 bytes from SHA1 digest in label and I think that I found some escape problem:

            vkhkhzkc [ fixedsize=true, fontcolor="#2D3436", fontname="Sans-Serif", fontsize=13, height=2.1999999999999997, image="assets/gcp/database/sql.png", imagescale=true, label="2822b7f1...", labelloc=b, shape=none, style=rounded, width=1.4 ];
            xnxdisdb [ fixedsize=true, fontcolor="#2D3436", fontname="Sans-Serif", fontsize=13, height=2.1999999999999997, image="assets/gcp/database/sql.png", imagescale=true, label=ca20af73..., labelloc=b, shape=none, style=rounded, width=1.4 ];
    

    Look like label label=ca20af73... sounds like string is't escape properly by go-diagrams.

    As result cath an error in dot processing:

    Error: diagram.dot: syntax error in line 30 near '.'
    
    opened by vit1251 0
  • Render method errors on subsequent runs (file exists)

    Render method errors on subsequent runs (file exists)

    When running a go-diagram more then once, the Render method errors with the following message:

    mkdir go-diagrams: file exists
    

    Ideally Render supports the option to overwrite the dot file in the go-diagrams directory.

    opened by Blokje5 1
Owner
null
yml2dot - Turn YAML into beautiful Graph

yml2dot - Turn YAML into beautiful Graph Use Cases Visualize your YAML files as Graph Generate additional info from your source code

Luca Sepe 102 Sep 19, 2022
Data visualization with chart, Create CSV file, Read Write CSV file

Data visualization with chart, Create CSV file, Read Write CSV file, Read from json file and many more in single project ......

MD FAISAL PORAG 1 Jan 13, 2022
An SVG-based tool to visualize public transport journeys retrieved from a HAFAS system

Time-Space Train Planner An SVG-based tool to visualize public transport journeys retrieved from a HAFAS system, in order to see all possible connecti

Traines 38 Sep 20, 2022
Gfx - Golang file system extension library

gfx Golang文件操作扩展库,包含工作和生活中关于文件操作的各种有用的使用方法,包括 更友好的API 文件创建 文件删除 文件复制 一切皆可配置 文件名

张川 0 Mar 10, 2022
Create diagrams from the Kubernetes API with go-diagrams.

Kubernetes diagrams k8s-diagrams creates diagrams from your kubernetes clusters. You just have to provide a namespace (or not), and you get a picture

Pierre Erraud 123 Sep 2, 2022
This package provides Go (golang) types and helper functions to do some basic but useful things with mxGraph diagrams in XML, which is most famously used by app.diagrams.net, the new name of draw.io.

Go Draw - Golang MX This package provides types and helper functions to do some basic but useful things with mxGraph diagrams in XML, which is most fa

null 2 Aug 30, 2022
Create Mermaid-Js ERD diagrams from existing tables

Mermerd Create Mermaid-Js ERD diagrams from existing tables. Features Supports PostgreSQL and MySQL Select from available schemas Select only the tabl

null 70 Sep 25, 2022
:triangular_ruler: Create beautiful generative image patterns from a string in golang.

geopattern Create beautiful generative image patterns from a string in golang. Go port of Jason Long's awesome GeoPattern library. Read geopattern's d

Pravendra Singh 1.2k Sep 20, 2022
Generate High Level Cloud Architecture diagrams using YAML syntax.

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

Luca Sepe 549 Sep 27, 2022
A command line tool to generate sequence diagrams

goseq - text based sequence diagrams A small command line utility used to generate UML sequence diagrams from a text-base definition file. Inspired by

Leon Mika 183 Sep 27, 2022
Generate plantuml diagrams from go source files or directories

go-plantuml go-plantuml generates plantuml diagrams from go source files or directories. Installation go get -u github.com/bykof/go-plantuml Please co

Michael Bykovski 264 Sep 30, 2022
Generate plantuml diagrams from go source files or directories

go-plantuml go-plantuml generates plantuml diagrams from go source files or directories. Installation go get -u github.com/bykof/go-plantuml Please co

Michael Bykovski 264 Sep 30, 2022
A CLI for generating ER diagrams for Ent schema

enter A CLI for generating ER (entity-relationship) diagrams for Ent schema using mermaid.js.

Ariel Mashraki 95 Sep 13, 2022
Generate PlantUML diagrams from Chrome or Firefox network inspections

hoofli Generate PlantUML diagrams from Chrome or Firefox network inspections This tool reads browser HAR files stored on your local disk and transform

Pascal Dennerly 3 Feb 22, 2022
Minimal and Beautiful Go testing framework

Goblin A Mocha like BDD testing framework written in Go that requires no additional dependencies. Requires no extensive documentation nor complicated

null 861 Sep 18, 2022
yml2dot - Turn YAML into beautiful Graph

yml2dot - Turn YAML into beautiful Graph Use Cases Visualize your YAML files as Graph Generate additional info from your source code

Luca Sepe 102 Sep 19, 2022
Build awesome Golang desktop apps and beautiful interfaces with Vue.js, React.js, Framework 7, and more...

Guark Guark allows you to build beautiful user interfaces using modern web technologies such as Vue.js, React.js..., while your app logic handled and

Guark. 615 Sep 25, 2022
🔥 ~6x faster, stricter, configurable, extensible, and beautiful drop-in replacement for golint

revive Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. Revive provides a framework for developme

Minko Gechev 3.8k Sep 30, 2022
🔥 A fast and beautiful command line tool to build API requests.

Poodle A fast and beautiful command line tool to build API requests ?? Check out the full Demo! Poodle is an interactive command line tool to build an

Ahmed 135 Aug 23, 2022
Hajimari is a beautiful & customizable browser startpage/dashboard with Kubernetes application discovery.

Hajimari ?? ...The beginning of a pleasant experience Features Web search bar Dynamically list apps discovered from Kubernetes ingresses Support for n

Toboshii Nakama 452 Sep 30, 2022