This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Tutorials

In this area you will find tutorials. The goal of those tutorials is to help you bootstraping your projects.

1 - Hello World

Your first diagram from cue to plantuml

In this tutorial you will:

  • represent a very simple C1 diagram as cue data
  • render it into plantuml

This tutorial works on MacOS and Linux, but should be adaptable to Windows easily.

Prerequisites

Only the cue utility is required. You can download is from this page

Setting up the directory

mkdir $TMPDIR/helloworld
cd $TMPDIR/helloworld

Bootstraping the project

Init a new cue module:

cue mod init

The vendor the cue4puml4c4 library:

mkdir -p cue.mod/pkg/github.com/owulveryck/cue4puml4c4
git clone https://github.com/owulveryck/cue4puml4c4.git cue.mod/pkg/github.com/owulveryck/cue4puml4c4

Create the command to generate the puml locally

Write the content below in a file name command_tool.cue with your favorite editor:

package main

import (
        "tool/cli"
        "text/template"
        "github.com/owulveryck/cue4puml4c4:c4"
)

command: genpuml: {
        c1: cli.Print & {
                text: template.Execute(c4.plantumlTemplate, C1) // change C1 here with the name of your object
        }
}

Create the diagram

in a file named test.cue write the content below:

package main

import "github.com/owulveryck/cue4puml4c4:c4"

C1: c4.#C1 & { // the name C1 should be coherent with the name you declare in the command
        Systems: [{id: "sample", label: "my sample"}]
}

Generate the plantuml diagram

run the following command to generate the plantuml diagram:

cue genpuml | grep -v '^$'

Note: the | grep command is to remove the blank lines for brevity but does not impact the result.

Generates the following output:

@startuml MyDiagram
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml
!include https://raw.githubusercontent.com/owulveryck/PlantUML-icons-GCP/master/official/GCPCommon.puml
LAYOUT_TOP_DOWN()
HIDE_STEREOTYPE()
/'Relation Tags'/ 
/'Element Tags'/ 
/' Systems '/
System(sample,"my sample")
SHOW_LEGEND()
@enduml

Which renders as:

@startuml MyDiagram
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml
!include https://raw.githubusercontent.com/owulveryck/PlantUML-icons-GCP/master/official/GCPCommon.puml
LAYOUT_TOP_DOWN()
HIDE_STEREOTYPE()
/'Relation Tags'/ 
/'Element Tags'/ 
/' Systems '/
System(sample,"my sample")
SHOW_LEGEND()
@enduml

You can copy/paste the content in plantuml server online to see how it renders

Cleaning

rm $TMPDIR/helloworld/*.cue
rmdir $TMPDIR/helloworld