Generate plantuml diagrams from go source files or directories

go-plantuml

Build Status Go Report Card

go-plantuml generates plantuml diagrams from go source files or directories.

Installation

go get -u github.com/bykof/go-plantuml

Please consider that $GOPATH/bin should be on our $PATH.

Usage

Usage:
  go-plantuml [command]

Available Commands:
  generate    Generate a plantuml diagram from given paths
  help        Help about any command

Flags:
  -h, --help     help for go-plantuml
  -t, --toggle   Help message for toggle

Use "go-plantuml [command] --help" for more information about a command.
Usage:
  go-plantuml generate [flags]

Flags:
  -d, --directories strings   the go source directories (default [.])
  -f, --files strings         the go source files
  -h, --help                  help for generate
  -o, --out string            the graphfile (default "graph.puml")
  -r, --recursive             traverse the given directories recursively

Example

For example we have to files in the directory test.

// address.go
package models

type (
	Address struct {
		Street        string
		City          string
		PostalCode    string
		Country       string
		CustomChannel chan string
		AnInterface   *interface{}
	}
)

func (address Address) FullAddress(withPostalCode bool) string {
	return ""
}
// user.go
package models

import "github.com/bykof/go-plantuml/test/address/models"

type (
	User struct {
		FirstName      string
		LastName       string
		Age            uint8
		Address        *models.Address
		privateAddress models.Address
	}
)

func (user *User) SetFirstName(firstName string) {
	user.FirstName = firstName
}

Then we run go-plantuml generate or go-plantuml generate -d . -o graph.puml.

This will create a graph.puml file and check for .go files inside your current directory.

Which looks like this:

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Owner
Michael Bykovski
C'mon dude, u rly programming java?!
Michael Bykovski
Comments
  • [feature request] excluding files/folder by name

    [feature request] excluding files/folder by name

    problem currently, only ignore non .go files and _test.go files suppose i have _mock file inside the same folder, said mock will pollute the the whole graph

    how to reproduce

    generate mock file inside target folder / sub folder

    proposed solution

    1. option to ignore file by name, eg. ^.+mock$ or
    2. option to ignore generated files or
    3. ability to ignore folders
  • Support top-level functions

    Support top-level functions

    It would be nice if go-plantuml would support top-level functions (instead of only methods).

    The main problem will be the decision on how to represent these, as UML ususally doesn't provide a notion of top-level functions.

    One possibility would be to misuse a class for that purpose. See this discussion about such a topic.

    I have prepared a rough idea how that could be achieved.

    For the following classes:

    // mypackage/functions.go
    package mypackage
    
    func Function1() []string {
      return []string{}
    }
    
    func Function2(param1, param2 string) {
    }
    
    // otherpackage.functions.go
    package otherpackage
    
    func New() MyStruct {
      return MyStruct{}
    }
    
    func Frobnicate(subject []string) {
    }
    
    // otherpackage/mystruct.go
    package otherpackage
    
    import (
      "fmt"
    
      "my.domain/rough/mypackage"
    )
    
    type MyStruct struct {
      Name string
    }
    
    func (s *MyStruct) DoSomething() {
      v := mypackage.Function1()
      fmt.Println(v)
    }
    
    func (s *MyStruct) GetSomething() string {
      return s.Name
    }
    

    the following puml file could be generated:

    @startuml
    title Rough idea
    namespace mypackage {
      class mypackage.functions << (F, blanchedalmond) >> {
        + Function1() []string
        + Function2(string, string)
      }
    }
    namespace otherpackage {
      class otherpackage.MyStruct << (S, aquamarine) >> {
        + Name string
        + DoSomething()
        + GetSomething() string
      }
    
      class otherpackage.functions << (F, blanchedalmond) >> {
        + New() MyStruct
        + Frobnicate([]string)
      }
    }
    
    otherpackage.MyStruct uses --> mypackage.functions
    @enduml
    

    which would be rendered as:

    dummy

    Here a class with the dummy name "functions" is generated inside each package to hold all global functions of that package. To differentiate between this function "holder" and real structs I added the "F" and "S" symbol to them (an idea I have taken from https://github.com/jfeliu007/goplantuml). Maybe the functions "holder" could also be specified as "abstract".

    As MyStruct calls mypackage.Function1 in its DoSomething() method I added a "usage"-association between them.

  • Messages while installing

    Messages while installing

    When I install, I've got the following "disturbing" messages:

    cd /Users/marcelloh/go/src/golang.org/x/sys; git pull --ff-only

    error: Your local changes to the following files would be overwritten by merge: error: The following untracked working tree files would be removed by merge:

    Please move or remove them before you merge. Aborting package golang.org/x/sys/unix: exit status 1

    cd /Users/marcelloh/go/src/gopkg.in/yaml.v2; git pull --ff-only

    error: Your local changes to the following files would be overwritten by merge: Please commit your changes or stash them before you merge. Aborting package gopkg.in/yaml.v2: exit status 1

    Totally not what I expect for installing software :-(

  • Can not install on macOS 12.3.1

    Can not install on macOS 12.3.1

    What I did?

     go install github.com/bykof/go-plantuml@latest
    

    Error

    nikolaydubina@Nikolays-MacBook-Pro ~ % go install github.com/bykof/go-plantuml@latest
    # golang.org/x/sys/unix
    go/pkg/mod/golang.org/x/[email protected]/unix/syscall_darwin.1_13.go:25:3: //go:linkname must refer to declared function or variable
    go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.1_13.go:27:3: //go:linkname must refer to declared function or variable
    go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.1_13.go:40:3: //go:linkname must refer to declared function or variable
    go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.go:28:3: //go:linkname must refer to declared function or variable
    go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.go:43:3: //go:linkname must refer to declared function or variable
    go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.go:59:3: //go:linkname must refer to declared function or variable
    go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.go:75:3: //go:linkname must refer to declared function or variable
    go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.go:90:3: //go:linkname must refer to declared function or variable
    go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.go:105:3: //go:linkname must refer to declared function or variable
    go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.go:121:3: //go:linkname must refer to declared function or variable
    go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.go:121:3: too many errors
    

    os: macos 12.3.1 apple silicon

    go env

    nikolaydubina@Nikolays-MacBook-Pro ~ % go env
    GO111MODULE=""
    GOARCH="amd64"
    GOBIN="//Users/nikolaydubina/go/bin"
    GOCACHE="/Users/nikolaydubina/Library/Caches/go-build"
    GOENV="/Users/nikolaydubina/Library/Application Support/go/env"
    GOEXE=""
    GOEXPERIMENT=""
    GOFLAGS=""
    GOHOSTARCH="amd64"
    GOHOSTOS="darwin"
    GOINSECURE=""
    GOMODCACHE="/Users/nikolaydubina/go/pkg/mod"
    GONOPROXY=""
    GONOSUMDB=""
    GOOS="darwin"
    GOPATH="/Users/nikolaydubina/go"
    GOPRIVATE=""
    GOPROXY="https://proxy.golang.org,direct"
    GOROOT="/usr/local/go"
    GOSUMDB="sum.golang.org"
    GOTMPDIR=""
    GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
    GOVCS=""
    GOVERSION="go1.18"
    GCCGO="gccgo"
    GOAMD64="v1"
    AR="ar"
    CC="clang"
    CXX="clang++"
    CGO_ENABLED="1"
    GOMOD="/dev/null"
    GOWORK=""
    CGO_CFLAGS="-g -O2"
    CGO_CPPFLAGS=""
    CGO_CXXFLAGS="-g -O2"
    CGO_FFLAGS="-g -O2"
    CGO_LDFLAGS="-g -O2"
    PKG_CONFIG="pkg-config"
    GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/dt/1y99_j6s0yj7y151_dr026gh0000gn/T/go-build1622984580=/tmp/go-build -gno-record-gcc-switches -fno-common"
    
  • Hi! Error when installing github.com/alecthomas/template

    Hi! Error when installing github.com/alecthomas/template

    Hi! What's wrong?

    D:\Go\freicon>go get -u github.com/bykof/go-plantuml
    go: downloading github.com/bykof/go-plantuml v1.0.0
    go get: github.com/bykof/[email protected] requires
            github.com/spf13/[email protected] requires
            github.com/prometheus/[email protected] requires
            github.com/prometheus/[email protected] requires
            github.com/alecthomas/[email protected]: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in D:\Go\pkg\mod\cache\vcs\61f91bfbd5e8d360ddae1fd4e3843dd5ed1a8022685
    79745aa0647da3aee84d3: exit status 128:
            fatal: 'origin' does not appear to be a git repository
            fatal: Could not read from remote repository.
    
            Please make sure you have the correct access rights
            and the repository exists.
    
    
    D:\Go\freicon>go get github.com/alecthomas/template
    go get: module github.com/alecthomas/template: git ls-remote -q origin in D:\Go\pkg\mod\cache\vcs\61f91bfbd5e8d360ddae1fd4e3843dd5ed1a802268579745aa0647da3aee84d3: exit status 128:
            fatal: 'origin' does not appear to be a git repository
            fatal: Could not read from remote repository.
    
            Please make sure you have the correct access rights
            and the repository exists.
    
  • issue with golang 1.18 - golang.org/x/sys/unix

    issue with golang 1.18 - golang.org/x/sys/unix

    I am getting

    go: downloading github.com/bykof/go-plantuml v1.0.0
    # golang.org/x/sys/unix
    ../../go/pkg/mod/golang.org/x/[email protected]/unix/syscall_darwin.1_13.go:25:3: //go:linkname must refer to declared function or variable
    ../../go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.1_13.go:27:3: //go:linkname must refer to declared function or variable
    ../../go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.1_13.go:40:3: //go:linkname must refer to declared function or variable
    ../../go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:28:3: //go:linkname must refer to declared function or variable
    ../../go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:43:3: //go:linkname must refer to declared function or variable
    ../../go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:59:3: //go:linkname must refer to declared function or variable
    ../../go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:75:3: //go:linkname must refer to declared function or variable
    ../../go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:90:3: //go:linkname must refer to declared function or variable
    ../../go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:105:3: //go:linkname must refer to declared function or variable
    ../../go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:121:3: //go:linkname must refer to declared function or variable
    ../../go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:121:3: too many errors
    make: *** [deps] Error 2
    

    when running

    go install github.com/bykof/[email protected]
    

    related issue 49219

  • methods are not generated on User if using a pointer receiver

    methods are not generated on User if using a pointer receiver

    methods are not generated if using a pointer receiver

    example

    type (
    	User struct {
    		FirstName      string
    		LastName       string
    		Age            uint8
    		Address        Address
    		privateAddress Address
    	}
    )
    
    func (user *User) SetFirstName(firstName string) {
    	user.FirstName = firstName
    }
    

    will not generate the method in the resulting puml file

    @startuml
    class User {
    +FirstName: string
    +LastName: string
    +Age: uint8
    +Address: Address
    -privateAddress: Address
    
    }
    class Address {
    +Street: string
    +City: string
    +PostalCode: string
    +Country: string
    +FullAddress(withPostalCode bool): string
    }
    User --> Address
    @enduml
    

    this will

    type (
    	User struct {
    		FirstName      string
    		LastName       string
    		Age            uint8
    		Address        Address
    		privateAddress Address
    	}
    )
    
    func (user User) SetFirstName(firstName string) {
    	user.FirstName = firstName
    }
    
    
    @startuml
    class User {
    +FirstName: string
    +LastName: string
    +Age: uint8
    +Address: Address
    -privateAddress: Address
    +SetFirstName(firstName string): 
    }
    class Address {
    +Street: string
    +City: string
    +PostalCode: string
    +Country: string
    +FullAddress(withPostalCode bool): string
    }
    User --> Address
    @enduml
    
    go version go1.15.2 linux/amd64
    
    openjdk version "11.0.9.1" 2020-11-04
    OpenJDK Runtime Environment (build 11.0.9.1+1-Ubuntu-0ubuntu1.18.04)
    OpenJDK 64-Bit Server VM (build 11.0.9.1+1-Ubuntu-0ubuntu1.18.04, mixed mode, sharing)
    
    NAME="Ubuntu"
    VERSION="18.04.5 LTS (Bionic Beaver)"
    ID=ubuntu
    ID_LIKE=debian
    PRETTY_NAME="Ubuntu 18.04.5 LTS"
    VERSION_ID="18.04"
    HOME_URL="https://www.ubuntu.com/"
    SUPPORT_URL="https://help.ubuntu.com/"
    BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
    PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
    VERSION_CODENAME=bionic
    UBUNTU_CODENAME=bionic
    
    
  • Added go-recipes badge

    Added go-recipes badge

    Hello, Hi!! 👋🏻

    I like your project and I think broader Go community will benefit from it too.

    Thus, I added it to the curated list of Go tools.

    I hope this badge will serve as a mark of quality and appreciation to your project.

    Once again, thank you for your work!!

    ❤️

    -- Nikolay

  • fix format and fix problem from linter

    fix format and fix problem from linter

    changes:

    • format files :
      • sort imports
    • fix linter problems
      • field privateAddress is unused
      • S1017: should replace this if statement with an unconditional strings.TrimPrefix
      • SA1019: "io/ioutil" has been deprecated since Go 1.16: As of Go 1.16, the same functionality is now provided by package io or package os, and those implementations should be preferred in new code. See the specific function documentation for details.
  • upgrade: go version 1.18

    upgrade: go version 1.18

    When using go mod tidy in go version 1.17, a problem occurred.

    Log: github.com/bykof/go-plantuml/astParser tested by github.com/bykof/go-plantuml/astParser.test imports github.com/stretchr/testify/assert imports gopkg.in/yaml.v3 tested by gopkg.in/yaml.v3.test imports gopkg.in/check.v1 loaded from gopkg.in/[email protected], but go 1.16 would select v1.0.0-20190902080502-41f04d3bba15

    To upgrade to the versions selected by go 1.16: go mod tidy -go=1.16 && go mod tidy -go=1.17 If reproducibility with go 1.16 is not needed: go mod tidy -compat=1.17 For other options, see: https://golang.org/doc/modules/pruning

    Solve: Upgrade go version to 1.18.

  • Handle cases relations to a pointer

    Handle cases relations to a pointer

    This addresses the case where a relationship from one struct to another is set up as a pointer.

    I found this easiest to illustrate by changing both of the Address references in test/user/models/user.go to pointers, which results in the following diagram prior to this change:

    image

    And with the change it results in what you would expect:

    image

  • Unknown field type assertion

    Unknown field type assertion

    Hello, I am receiving the following error when I run the package.

    % go-plantuml generate -d . -o graph.puml
    2022/11/25 12:18:07 unknown Field Type *ast.IndexListExpr
    

    No other output or description is provided.

  • Error when struct declaration is in a different file than its method

    Error when struct declaration is in a different file than its method

    Hi,

    go-plantuml cannot seem to find a type if its declaration is in a different file than one of its method.

    For example, with the following files:

    impl.go:

    package models
    
    func (user *User) SetFirstName(firstName string) {
    	user.FirstName = firstName
    }
    
    func PackageFunction() string {
    	return "Hello World"
    }
    

    user.go:

    package models
    
    type User struct {
    	FirstName      string
    	LastName       string
    	Age            uint8
    }
    

    I'm getting the following error when running go-plantuml generate:

    2022/09/08 14:45:56 Could not find class: User for function SetFirstName
    

    This seems to depend on the name of the files and the order in which they are parsed by the tool. The same issue happens if the type is an alias (e.g. type User string).

  • Add depth option for

    Add depth option for "file"command

    When generating a graph for a file it would be nice to have an option to specify a depth for dependencies. A pratical example would be in a file blahblah.go I have a struct A that has a struct B as a property. When generating the diagram for blahblah.go it would be awesome to be able to specify a depth that followed A properties to a certain depth. The following command: go-plantuml generate -f model/blahblah.go --depth=1 -o graph.puml would then generate a puml file of both blahblah.go as well as of the first level dependencies of A.

    Another example would be if depth is 2, it would mean that if B had a dependency C we should be able to request issue go-plantuml generate -f model/blahblah.go --depth=2 -o graph.puml and see the relationships of A, B and C.

  • Could not find class: TPMEventLog for function Add

    Could not find class: TPMEventLog for function Add

    Hello.

    I'm trying to build an UML diagram for this code: https://github.com/9elements/converged-security-suite/pull/330/commits/9e980b2dd18a090ba322592480f5e11882d242ce

    But I receive error Could not find class:

    [xaionaro@void converged-security-suite]$ go-plantuml generate -o /tmp/1.uml -r -d pkg/bootflow/
    2022/05/26 16:45:59 Could not find class: References for function Bytes
    2022/05/26 16:45:59 Could not find class: StaticData for function Data
    2022/05/26 16:45:59 Could not find class: UEFIGUIDFirst for function Data
    2022/05/26 16:45:59 Could not find class: PCRValues for function Get
    2022/05/26 16:45:59 Could not find class: PCRValues for function Set
    2022/05/26 16:45:59 Could not find class: TPMEventLog for function Add
    2022/05/26 16:45:59 Could not find class: StaticStep for function Actions
    

    What do I do wrong?

Wrapper to easily generate "X-Request-Auth" header for Mesh sites in golang.

hawk mesh go ?? ?? Description Wrapper to easily generate "X-Request-Auth" header for Mesh sites in golang. Based on hawk-go. Getting Started Import t

Dec 4, 2022
White Matrix Micro Service Generate CLI Tool

micro-service-gen-tool White Matrix Micro Service Generate CLI Tool usage templa

Jan 5, 2022
Automatically generate tags for golang struct.

gotag is a command tool that can automatically generate tags for golang struct. Quick start Install gotag go install github.com/sycki/gotag@latest Pr

Feb 12, 2022
Swagger-go-chi - Generate a go-chi server from swagger

swagger-go-chi Install go install github.com/cugu/swagger-go-chi@main Run swagge

Nov 5, 2022
Erda is an open-source platform created by Terminus to ensure the development of microservice applications.
Erda is an open-source platform created by Terminus to ensure the development of microservice applications.

Erda is an open-source platform created by Terminus to ensure the development of microservice applications.

Jan 5, 2023
Source code related to an on-site demonstration (for Ardan Labs) of packaging Go applications with Nix

Ardan Labs Nix Demo High-Level Overview We bumbled the scheduling of an earlier presentation about git worktree that a few co-workers attended. In eff

Oct 12, 2022
This tool generates Go language bindings of services in protobuf definition files for go-kit

protoc-gen-go-kit This tool generates Go language bindings of services in protobuf definition files for go-kit. Installation $ go install github.com/x

Nov 9, 2021
Generate plantuml diagrams from go source files or directories
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

Jan 1, 2023
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

Nov 15, 2022
Create diagrams from the Kubernetes API with go-diagrams.
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

Dec 12, 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

Aug 30, 2022
🌳 Go Bonzai™ File Completer, normal completion looking at files and directories with trailing slashes on directories (like bash)

?? Go Bonzai™ File Completer, normal completion looking at files and directories with trailing slashes on directories (like bash)

Apr 12, 2022
erchive is a go program that compresses and encrypts files and entire directories into .zep files (encrypted zip files).

erchive/zep erchive is a go program that compresses and encrypts files and entire directories into .zep files (encrypted zip files). it compresses usi

May 16, 2022
Generate PlantUML ER diagram textual description from PostgreSQL tables
Generate PlantUML ER diagram textual description from PostgreSQL tables

Generate PlantUML ER diagram textual description from PostgreSQL tables

Dec 22, 2022
Generate High Level Cloud Architecture diagrams using YAML syntax.
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.

Dec 24, 2022
A command line tool to generate sequence diagrams
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

Dec 22, 2022
PlantUML Class Diagram Generator for golang projects
PlantUML Class Diagram Generator for golang projects

GoPlantUML PlantUML Class Diagram Generator for golang projects. Generates class diagram text compatible with plantuml with the information of all str

Dec 31, 2022
Converts a trace of Datadog to a sequence diagram of PlantUML (Currently, supports only gRPC)
Converts a trace of Datadog to a sequence diagram of PlantUML (Currently, supports only gRPC)

jigsaw Automatically generate a sequence diagram from JSON of Trace in Datadog. ⚠️ Only gRPC calls appear in the sequence diagram. Example w/ response

Jul 12, 2022
A CLI for generating ER diagrams for Ent schema
A CLI for generating ER diagrams for Ent schema

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

Dec 18, 2022
Create beautiful system diagrams with Go
Create beautiful system diagrams with Go

Go-Diagrams Fast and easy application diagrams Go-Diagrams is a loose port of diagrams. Contents Features Usage Features Turn this: d, err := diagram.

Jan 7, 2023