The website content provides an overview of various open-source libraries and tools for code-based and text-based diagramming, illustrating how to create diagrams programmatically in different programming languages and contexts.
Abstract
The website delves into the utilization of open-source libraries for generating diagrams through code, focusing on Python with the "Diagrams" library and JavaScript with "Mermaid." It also explores "PlantUML" and its applicability across various programming environments, including support for non-UML diagrams. The article introduces the C4 model for describing software architecture at different levels of detail and discusses "C4-PlantUML," which combines PlantUML with the C4 model. Additionally, it covers "Asciidoctor Diagram," a set of extensions for adding diagrams to AsciiDoc documents, and "Structurizr," a toolset for creating architecture diagrams based on the C4 model. The content emphasizes the integration of these diagramming tools with modern editors like VS Code, Emacs, and Neovim, facilitating the process of writing technical documentation with embedded diagrams.
Opinions
The author endorses the use of code-based diagramming tools for their efficiency and integration capabilities with modern editors and workflows.
There is a clear preference for tools that support Markdown-like syntax, highlighting the simplicity and accessibility of text-based diagramming approaches.
The author values the consistency and maintainability provided by tools like "C4-PlantUML" and "Structurizr," which allow for the generation of multiple diagrams from a single model.
The article suggests that using these tools can enhance the process of writing technical documentation, making it more dynamic and visually appealing.
A recommendation is made for non-Medium members to consider subscribing to support the author, suggesting a beneficial relationship between content creators and consumers within the tech community.
Diagrams helps us draw on-premise and cloud system architecture in Python code.
It supports all major cloud providers like AWS, Azure, GCP, IBM, OpenStack, DigitalOcean, Oracle, Firebase, and other platforms like Kubernetes, Saas, and Elastic search services.
Below are some examples taken from the documentation.
AWS
AWS System Architecture
GCP
GCP System Architecture
On-Prem
On-Prem System Architecture
Kubernetes
Kubernetes System Architecture
Note: Go-Diagrams is a port of this library for the Go language.
Mermaid for Javascript
Mermaid is a Javascript-based diagramming and charting tool that renders Markdown-inspired text definitions to create and modify diagrams dynamically.
Using Markdown-like syntax, we can create flow charts, sequence diagrams, class diagrams, ER diagrams, user stories, Gantt charts, pie charts, and requirements diagrams.
sequenceDiagram
Alice->>John: Hello John, how are you?
John-->>Alice: Great!
Alice-)John: See you later!
Mermaid Sequence Diagram
User Journey
journey
title My working day
section Go to work
Make tea: 5: Me
Go upstairs: 3: MeDo work: 1: Me, Cat
section Go home
Go downstairs: 5: Me
Sit down: 5: Me
Mermaid User Journey
PlantUML
PlantUML, developed in Java, is another popular option to generate all sorts of diagrams like sequence diagrams, class diagrams, object diagrams, activity diagrams, component diagrams, deployment diagrams, state diagrams, timing diagrams, etc.
The good thing is that it also supports non-UML diagrams like visualizing JSON and YAML data, network diagrams, wireframe mock-ups, Archimate diagrams, Ditaa diagrams, mind maps, etc.
E.g below is a use case diagram generated by PlantUML.
@startuml
left to right direction
actor Guest as g
package Professional {
actor Chef as c
actor "Food Critic"as fc
}
package Restaurant {
usecase "Eat Food"as UC1
usecase "Pay for Food"as UC2
usecase "Drink"as UC3
usecase "Review"as UC4
}
fc --> UC4
g --> UC1
g --> UC2
g --> UC3
@enduml
Context — Shows the software system we are building and how it fits into the world in terms of the people who use it and the other software systems it interacts with.
Containers — Zooms into the software system, and shows the containers (applications, data stores, microservices, etc.) that make up that software system.
Components — Zooms into an individual container to show the components inside it. These components should map to real abstractions (e.g., a grouping of code) in the codebase.
Code — Shows the code for the component.
C4-PlantUML combines the benefits of PlantUML and the C4 model for providing a simple way of describing and communicating software architectures. It supports system context & system landscape diagrams, container diagrams, component diagrams, dynamic diagrams, and deployment diagrams.
Below is a sample container diagram from the documentation.
Asciidoctor Diagram is a set of Asciidoctor extensions that enable us to add diagrams written in plain text to the AsciiDoc document.
The good thing is we can use syntax that we are familiar with, e.g. Mermaid, PlantUML, GraphiViz, and the diagram processor can generate an SVG, PNG, or TXT file from the input text.
Below is an example from the documentation.
[ditaa]
....
+-------------+
| Asciidoctor |-------+
| diagram ||
+-------------+ | PNG out
^ |
| ditaa in |
| v
+--------+ +--------+----+ /---------------\
|| --+ Asciidoctor +--> ||
| Text | +-------------+ | Beautiful |
|Document|| !magic! || Output |
| {d}|||||
+---+----+ +-------------+ \---------------/
: ^
| Lots of work |
+-----------------------------------+
....
Lastly, you may want to also check out Structurizr which is a collection of tooling to create software architecture diagrams and documentation based upon the C4 model.
It provides a set of authoring and rendering tools that make it possible to generate multiple diagrams from the same model to ensure consistency, with details being in sync across all diagrams, using the Structurizr DSL.
Editor Integration
Modern editors like VS Code, Emacs, Neovim, etc have plugins that help us integrate all these tools.
For Mermaid, check here for the available plugins.
For PlantUML, check here for the available plugins.
For AsciiDoctor, check here for the available plugins.
Also, using an editor like Emacs, we can seamlessly integrate all these tools to help us write technical documentation.
Check out this article for more details on how we can use Emacs to write technical documentation.