DEV Community

Cover image for How to turn your golang programs into UML Class diagrams

Posted on

How to turn your golang programs into UML Class diagrams

Sometimes it helps to see a class diagram of your projects to understand the big picture. I have always been a fan of PlantUML. When it comes to drawing UML diagrams, plantUML is one of my favorites since drawings are generated out of a human-readable text file, which can be easily committed to git.

For that reason, I decided to write a Golang library to generate class diagrams from a Golang project.

Goplantuml is a Golang library with an added command that you can install if you run go already. It basically turns code like this

package goisawesome

import "strings"

type Foo struct {
    field       int
    PublicField bool
type MyInterface interface {
    GetValue() bool

func (f *Foo) myPrivateFunction() int {
    return 3

func (f *Foo) GetValue() bool {
    return true

func (f *Foo) MyPublicFunction() bool {
    return true

into this

namespace goisawesome {
    class Foo {
        - field int
        + PublicField bool
        - myPrivateFunction() 
        + GetValue() 
        + MyPublicFunction() 
    interface MyInterface {
        + GetValue() 
strings.Builder *-- goisawesome.Foo
goisawesome.MyInterface <|-- goisawesome.Foo

which can be used with plantuml to generate a nice class diagram.

see example here

If you are interested, swing by the goplantuml repo.

GitHub logo jfeliu007 / goplantuml

PlantUML Class Diagram Generator for golang projects

godoc reference Go Report Card codecov License: MIT GitHub release Build Status Mentioned in Awesome Go DUMELS Diagram


PlantUML Class Diagram Generator for golang projects. Generates class diagram text compatible with plantuml with the information of all structures and interfaces as well as the relationship among them.

Want to try it on your code?

Take a look at We have created dumels using this library.

Code of Conduct

Please, review the code of conduct here.


golang 1.10 or above


go get
go get
cd $GOPATH/src/
go install ./

This will install the command goplantuml in your GOPATH bin folder.


goplantuml [-recursive] path/to/gofiles path/to/gofiles2
goplantuml [-recursive] path/to/gofiles path/to/gofiles2 > diagram_file_name.puml
Usage of goplantuml
        Show aggregations for private members. Ignored if -show-aggregations is not used
        hides all connections in the diagram
        hides fields
        hides methods
  -ignore string
        comma separated list of folders to ignore
  -notes string
        Comma separated list of notes to be added to the diagram

I would love to hear you opinions. I also wrote an article about the program and how it is used if you would like more information.

Top comments (0)