Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
56 lines (41 sloc) 2.7 KB

PlantUML

Structurizr for .NET also includes a simple exporter that can create diagram definitions compatible with PlantUML. The following diagram types are supported:

  • Enterprise Context
  • System Context
  • Container
  • Component
  • Dynamic
  • Deployment

Simply create your software architecture model and views as usual, and use the PlantUMLWriter class to export the views. For example:

Workspace workspace = new Workspace("Getting Started", "This is a model of my software system.");
Model model = workspace.Model;

Person user = model.AddPerson("User", "A user of my software system.");
SoftwareSystem softwareSystem = model.AddSoftwareSystem("Software System", "My software system.");
user.Uses(softwareSystem, "Uses");

ViewSet views = workspace.Views;
SystemContextView contextView = views.CreateSystemContextView(softwareSystem, "SystemContext", "An example of a System Context diagram.");
contextView.AddAllSoftwareSystems();
contextView.AddAllPeople();

StringWriter stringWriter = new StringWriter();
PlantUMLWriter plantUMLWriter = new PlantUMLWriter();
plantUMLWriter.Write(workspace, stringWriter);
Console.WriteLine(stringWriter.ToString());

This code will generate and output a PlantUML diagram definition that looks like this:

@startuml
title Software System - System Context
caption An example of a System Context diagram.
component "Software System" <<Software System>> as 2
actor "User" <<Person>> as 1
1 ..> 2 : Uses
@enduml

If you copy/paste this into PlantUML online, you will get something like this:

A simple PlantUML diagram

Benefits of using PlantUML with Structurizr

The key benefit of using PlantUML in conjunction with the Structurizr client library is that you can create diagrams from a model of your software system. The model provides a set of rules that must be followed; related to elements, relationships, and how they are exposed using diagrams. This means:

  1. Rather than looking after a collection of disjointed PlantUML diagram definitions, you can create many PlantUML diagrams from a single model and keep them all up to date easily, especially if integrated with your continuous build server and build pipeline.
  2. The naming of elements and the definition of relationships between elements remains consistent across diagrams.
  3. The software architecture model at the component level can be created by extracting components from a codebase, using static analysis and reflection techniques.