- Imagine this: You sketch out a class diagram in Mermaid.js 🏗️, but then manually translate it into code 💻.
- Each time the design evolves, documentation and implementation drift apart 📉.
- The result? Confusion, outdated docs, and inconsistencies across teams.
❓ What if the diagram itself could be the single source of truth?
I'm not asking to change how Mermaid works – i want to make it more powerful.💪
Right now, Mermaid.js is fantastic for visualization. But what if we could go beyond diagrams and make them actionable?
Generate an intermediate structure that can easily be imported and used to generate a number of things.
In this piece of code a example application a classdiagram is converted into a yml file.
e.g.
Car.yml
You can then add additional properties to the Car that is valuable for a classdiagram visualization but might be valuable for a software unit.
Forexample, description above methods/classes and attributes.
Therefore you can add your own file
Car.Custom.yml
You can then load both into memory and then generate code from this.
Maybe use liquid / xslt / handlebarsjs templates for this?
In C# you have the concept of partial classes Which you can then extend to implement the methods mentioned in the class diagrams
I used classdiagrams but technically you can extend this structure for more than just class diagrams , think of, Threat modeling with STRIDE Drawing the diagram and then being able directly see which elements of the STRIDE is applicable.
Or Generating SQL Schema from ERDs
This repo makes use of the class diagram jison file that was copied from the following location. It simply transforms mermaid to yml.
1️⃣ Write a diagram in Mermaid.js 📊
2️⃣ Convert it to YAML/JSON with a lightweight parser
3️⃣ Use YAML to generate transforms to yml 🎯
🔗 The prototype builds on Mermaid’s existing grammar, ensuring a non-intrusive extension.
🔹 Would this feature help your workflow?
🔹 Would you support adding YAML/JSON generation to Mermaid?
This is a proposal for future implementation, but with the right momentum, we can bring this to life.
👥 Let’s discuss! I’d love to hear feedback, collaborate, and refine this idea further.
I'm not so familiar with the mermaid repository but I am willing to learn and assist building this? Help might be needed
classDiagram.jison
: Contains the Jison grammar for parsing Mermaid class diagrams. This file was copied from the following locationclassDiagramParser.js
: Generated parser from the Jison grammar.mermaid.md
: Example Mermaid class diagram.processJison.js
: Script to generate the parser from the Jison grammar.processMermaid.js
: Script to parse the Mermaid diagram and generate YAML files.output/
: Directory where the generated YAML files are stored.package.json
: Project dependencies and scripts.
-
Install dependencies:
npm install
-
Generate the parser:
npm run produce-js
-
Generate YAML files from the Mermaid diagram:
npm run produce-yml
The mermaid.md file contains an example Mermaid class diagram. Running the above commands will generate corresponding YAML files in the output directory.