Operations & Systems
Generate Mermaid Diagrams from n8n workflows
This n8n workflow retrieves the JSON definition of a specified n8n automation. It then processes this data using a Code node to generate a Mermaid.js flowchart string. This output visualizes the target workflow's structure, representing nodes with specific shapes based on their…
Built · ~3 hours saved per week
Generate Mermaid Diagrams from n8n workflows
Technologies & Automation
This workflow automates the process of creating technical documentation and visual diagrams for n8n workflows. It uses n8n's internal API to fetch a workflow's structure and then uses custom JavaScript to translate that structure into a renderable flowchart.
- Technologies Used: n8n API, JavaScript, Mermaid.js syntax. - Automation Value: It eliminates the tedious and error-prone task of manually creating flowcharts to document or explain complex automations. By running this workflow, a user can instantly generate an accurate, up-to-date visual representation of any other workflow, which is invaluable for code reviews, onboarding, and knowledge sharing.
Node-by-Node Breakdown
H3: When clicking ‘Test workflow’
This is a Manual Trigger node. It serves as the starting point for the workflow, allowing the user to initiate the diagram generation process on-demand with a single click.
H3: Fetch Single Workflow
This n8n node uses the platform's own API to retrieve data about itself. In this configuration, it performs a get operation to fetch the complete JSON structure of a specific, pre-selected workflow. This JSON output contains all the necessary details about the target workflow's nodes, their parameters, and how they are connected.
H3: Generate Mermaid Chart
This is a Code node that acts as the core engine of the workflow. It executes a JavaScript snippet to perform a complex data transformation:
1. Parse Input: It takes the workflow JSON from the previous node as input. 2. Map Nodes & Shapes: It iterates through every node in the JSON, assigning a unique ID to each. It intelligently maps different n8n node types to specific flowchart shapes (e.g., an IF node becomes a rhombus {}, a Code node becomes a subroutine [[]], and standard nodes are rectangles []). It also identifies and excludes non-functional nodes like Sticky Notes. 3. Build Connections: The code then analyzes the connections object from the workflow JSON. It translates each connection between nodes into a line of Mermaid syntax.
Tags: n8n, Data Transformation
Integrations: Code