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
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:
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:
- 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.
- The naming of elements and the definition of relationships between elements remains consistent across diagrams.
- The software architecture model at the component level can be created by extracting components from a codebase, using static analysis and reflection techniques.