Creating visual diagrams is an essential part of communicating complex systems, relationships, and workflows. However, not all diagrams are created equal. Traditional tools like Microsoft Visio or Adobe Illustrator focus on visual design but often fall short in terms of scalability, automation, and integration. In contrast, semantic diagrams and Diagrams-as-Code offer a transformative approach to diagramming by encoding meaning and enabling automation.
This article explores the concept of semantic diagrams, their distinction from traditional tools, the benefits they offer, and how you can leverage them to create powerful, data-driven visualizations.
You can find a working version of the this article at: https://github.com/mattbriggs/semantic-diagrams
Semantic diagrams go beyond being mere visual representations. Semantic diagrams are structured, data-driven models that encode meaning using a defined schema. This approach prioritizes the relationships and types of components within a diagram, enabling tools and scripts to interpret the underlying data programmatically.
Key features of semantic diagrams include:
Diagrams-as-Code involve creating diagrams using text-based representations, such as markup languages or coding syntax. Popular tools like Mermaid.js and Graphviz allow you to write diagram definitions in code, which can then be processed to generate visual outputs.
Benefits of diagrams-as-code:
Traditional tools like Microsoft Visio or Adobe Illustrator are visual-first. While they offer robust design capabilities, they often lack features critical for dynamic and scalable workflows.
Key limitations of traditional tools:
The advantages of semantic diagrams and Diagrams-as-Code go beyond convenience: they enable entirely new ways of working with visual information.
Why they are worth adopting:
To illustrate the workflow of semantic diagrams, consider a scenario where you need to create a class diagram for a software system.
Steps:
classes:
- name: User
attributes:
- id: integer
- name: string
- name: Order
attributes:
- id: integer
- amount: float
relationships:
- type: "has_many"
target: "User"
Process the Data: Use a script to validate the YAML file and convert it into a semantic diagram definition. In this case the following JSON Schema can be used to validate your class diagram:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Class Diagram Schema",
"type": "object",
"required": ["classes"],
"properties": {
"classes": {
"type": "array",
"items": {
"type": "object",
"required": ["name"],
"properties": {
"name": {
"type": "string",
"minLength": 1
},
"attributes": {
"type": "array",
"items": {
"type": "object",
"minProperties": 1,
"maxProperties": 1,
"additionalProperties": {
"type": "string",
"enum": ["string", "integer", "float", "boolean"]
}
}
},
"relationships": {
"type": "array",
"items": {
"type": "object",
"required": ["type", "target"],
"properties": {
"type": {
"type": "string",
"enum": ["has_one", "has_many", "belongs_to", "many_to_many"]
},
"target": {
"type": "string",
"minLength": 1
}
},
"additionalProperties": false
}
}
},
"additionalProperties": false
}
}
},
"additionalProperties": false
}
Generate the Diagram: Use a tool like Mermaid.js to render the diagram as HTML, PNG, or another format:
Transform to diagram-as-code:
classDiagram
class User {
integer id
string name
}
class Order {
integer id
float amount
}
User "1" <-- "has_many" Order
Transform to diagram:
By adopting semantic diagrams and Diagrams-as-Code, you can shift from static, manual processes to dynamic, scalable workflows. These approaches make your diagrams:
Whether you’re a technical writer, developer, or systems architect, semantic diagrams and Diagrams-as-Code can revolutionize how you create, maintain, and share visual information. Start experimenting today and make your diagrams more than static visuals and turn them into integral parts of your data-driven workflows.