April 18, 2022
The First Rule of Building Microservices: Don’t Build Microservices
In a previous blog post, I did a brief introduction to Architecture Software Visualization using the C4 Model.
On this one, I want to show you some of the available tooling and give you a quick walkthrough on how to create our architecture models.
Simon Brown created Structurizr to build software architecture models as code (Diagrams as code 2.0).
It’s a Domain Specific Language (DSL) that you use to define your model, and then it can be visualized with some tooling.
The DSL uses the domain language of software architecture, check the documentation for the full language reference.
In Diagrams as code 2.0 you create and maintain a single model, and the tool generates and keep in sync multiple diagrams. Just for reference, with the first version, you would have to create and maintain the code for multiple diagrams and keep them all in sync.
With Structurizr you can use different programming languages to create your model, or a text-based DSL, I will try to keep it simple, and we are going to use the text-based DSL version.
Here is a full sample (workspace) and some comments on the structure.
The first building block is the workspace (1), a wrapper for your model (2), views (4), and additional documentation.
Notice the naming of the views, systemContext, container, component, implement to the C4 Model, also the code view is not available in the DSL, because is not expected to be in our models.
Inside your model you will have the different elements that defines your architecture in the C4 Model, like softwareSystem, container or component along with the properties for every element, and the relations (3) between the different parts.
The theme and styles (5) section allow customization of your model.
Now that we have our model defined, let me show you how we can visualize it.
This is a free version of Structurizr designed for developers and packaged as a Docker container. You can locally view your diagrams and export it as PNG files.
To use Structurizr Lite on your local computer, you will need Docker installed.
After you have Docker running, you need to pull the Structurizr Lite image, and run the tool with the following command (I’m using Power Shell on a Windows PC)
docker pull structurizr/lite
docker run -it –rm -p 8080:8080 -v C:/architecture-demo:/usr/local/structurizr structurizr/lite
Structurizr will start and show the following message
Notice that we are setting a local folder (c:\architecture-demo) were our dsl file will be deployed, so, we take our example file, name it workspace.dsl, and copy it to that folder.
Now we can open any web browser and navigate to http://localhost:8080, accept the license, and see our model in the Diagram section.
The diagrams window has a navigation panel to the left, that you can use to access any of the views (1), the thumbnails will be created after you access the individual views.
In any diagram that you can zoom in, you will see a + sign that will navigate to that view (2). In the following screenshot, the plus sign will navigate to the container diagram.
This is just a quick overview, a lot of interesting topics are not covered here like exporting views, the cloud services to use Structurizr as a hosted app, extensions to work with text-based DSL on Visual Studio Code or code-based DSL with .NET.
Please check the resources section, and thanks for reading!