🎄 Leveraging Graphviz for Programmatic Visualization in Software Engineering 🌟
Graphviz, a robust visualization tool, is not only useful for static diagram creation but also excels in dynamic, programmatically generated visualizations.
On day 2 of Advent, we already talked about MermaidJS, a tool for generating diagrams from text. However, we recommend to use Graphviz inside scripts and command line, often when you just want to understand a data structure or a process.
And MermaidJS is better at web-based applications, where you already know what you want to visualize.
Let's go over couple examples where Graphviz would be a great fit.
1. Dynamic Dependency Analysis
Consider a Python script that parses the source code to extract dependencies between classes or modules.
As developers commit new code, this script runs, updating the Graphviz-generated dependency graph. This real-time visualization helps in identifying complex dependencies and architectural drifts.
digraph G {
"ClassA" -> "ClassB";
"ClassB" -> "ClassC";
"ClassC" -> "ClassA";
}
This markup describes a simple circular dependency between three classes, showcasing the relationship visually.
2. Tracking Service Call Dependencies in Microservices
A tool can be developed to parse the access logs of various microservices. This tool identifies which services are calling others and how frequently. Graphviz is then used to create a diagram representing these interactions, providing a clear view of the service mesh and its dependencies.
digraph G {
"ServiceA" -> "ServiceB" [label="calls: 10/day"];
"ServiceB" -> "ServiceC" [label="calls: 5/day"];
"ServiceC" -> "ServiceA" [label="calls: 2/day"];
}
In this markup, directed edges between services are annotated with call frequencies, offering insights into the communication patterns and potential bottlenecks.