Skip to main content
Software development for researchers

Drawing diagrams

Table of contents

C4

Using graphviz

Graphviz is a powerful open source graph visualization tool written in (mostly) C that allows you to define graphs using the dot language.

I did not find any good pre-defined templates for making C4 diagrams using Graphviz so I have written my own. As I have also made a bunch of other diagrams in this course using the dot language I wanted to keep the graphing language consistent. You can have a look at one example here:

Example c4 container diagram made in the dot language
digraph iterative{
    rankdir="TB";
    dpi=300;
    edge [ style=dashed ];
    node[
        shape = rect
        style = "filled, rounded"
        color = "#a4fad0"
    ];
    user [
        label=<
            <table border="0" cellborder="0">
                <tr> <td><b>Scientist</b></td> </tr>
                <tr> <td>[Person]</td> </tr>
                <tr> <td>A researcher using the tool</td> </tr>
            </table>
        >
    ]
    node[
        shape = rect
        style = filled
        fillcolor = "#9db5f7"
        color = "black"
    ];
    subgraph cluster_software {
        label=<<b>Solar-system simulation</b>>
        cli [
            label=<
                <table border="0" cellborder="0">
                    <tr> <td><b>Simulation CLI interface</b></td> </tr>
                    <tr> <td>[Container: Python]</td> </tr>
                    <tr> <td>The interface for configuring and\nrunning the simulations</td> </tr>
                </table>
            >
        ]
        lib [
            label=<
                <table border="0" cellborder="0">
                    <tr> <td><b>Simulation library</b></td> </tr>
                    <tr> <td>[Container: C]</td> </tr>
                    <tr> <td>The simulation software that solves\nthe equations of motion</td> </tr>
                </table>
            >
        ]
        vis [
            label=<
                <table border="0" cellborder="0">
                    <tr> <td><b>Visualization tool</b></td> </tr>
                    <tr> <td>[Container: Odin]</td> </tr>
                    <tr> <td>A tool to create 3d visualizations\nof the simulation results</td> </tr>
                </table>
            >
        ]
        storage [
            shape = cylinder
            label=<
                <table border="0" cellborder="0">
                    <tr> <td><b>Results</b></td> </tr>
                    <tr> <td>[Container: Filesystem and HDF5]</td> </tr>
                    <tr> <td>The simulation results stored on\na file system using HDF5</td> </tr>
                </table>
            >
        ]
    }
    node[
        shape = rect
        style = filled
        fillcolor = "#cfcfcf"
        color = "black"
    ];
    horizons [
        label=<
            <table border="0" cellborder="0">
                <tr> <td><b>JPL Horizons System</b></td> </tr>
                <tr> <td>[Software system]</td> </tr>
                <tr> <td>A software system to calculate positions<br/>and velocities of solar system bodies at a requested time</td> </tr>
            </table>
        >
    ]
    user -> cli [label="Configures and\nsimulates scenarios\n[SSH]"]
    cli -> horizons [label="Gets the solar-system\nbody states for scenario\n[JSON/HTTPS]"]
    cli -> lib [label="Configures and calls functions"]
    cli -> vis [label="Configures and runs"]
    lib -> storage [label="Reads from \nand writes to"]
    vis -> storage [label="Reads from"]
    user -> vis [label="Views results\n[RTSP stream]"]
}

The above code generates this figure:

Example C4 Container diagram for a solar-system simulation tool

Using plantUML

PlantUML is a Java tool for drawing a wide range of diagrams, notably Unified Modeling Language (UML) and similar diagrams.

There is a predefined set for drawing specifically C4-architecture diagrams called C4-PlantUML that you can include into your PlantUML files by

!include <C4/C4_Container>

To read more on how to use C4-PlantUML, see the github README.md.

Other tooling

There is an extensive list of other tooling for C4 listen on c4model.com’s tooling page.

State diagrams

A state diagram is fairly simple to draw. If we follow the UML definition we can draw them using the plantUML’s state-diagram or any other UML diagram drawing tool.

Using graphviz

My own recipe for drawing state-diagrams using graphviz is:

digraph finite_state_machine {
    label="Pressure valve";
    rankdir="LR";
    dpi=300;
    node [shape=point, label=""];
    ENTRY;
    EXIT;
    node [shape=rect, style=rounded];

    A[label="Low flow"];
    B[label="High flow"];
    C[label="No flow"];

    ENTRY->A [label="Start"];
    A->C [label="Shutdown"];
    B->A [label="Pressure drops"];
    A->B [label="Request recived"];
    C->EXIT [label="End"];
}

Which results in

Example state diagram of a pressure valve control system
To top
× Zoomed Image