Skip to content
← All articles
Article

ComfyUI-UML: diagrams as nodes, images and shareable source

Listen to the audio story

Diagrams as ComfyUI nodes · 2:15 · AI-written script, synthetic voices

Transcript

Ava: Here's a small idea: what if a diagram in your AI image workflow wasn't a screenshot, but text you could read, edit and regenerate?

Andrew: Like a recipe instead of a photo of the cake.

Ava: That's exactly it. Antoine built ComfyUI-UML, a custom node for ComfyUI. Text in, and out come an image, a saved file, and a shareable link.

Andrew: What kind of text? Is it some special format?

Ava: Mermaid or PlantUML, the popular diagram languages. The README documents 28 diagram types through a service called Kroki, with output formats checked for each type. Because the source stays inside the workflow, you can inspect it, compare versions and re-run it.

Andrew: And where does the drawing happen?

Ava: By default the node sends the source to a Kroki renderer on the web. If you'd rather stay offline, or you're working on a sensitive architecture, the repository documents local Mermaid and Graphviz paths too.

Andrew: I heard language models can write these diagrams. Does it handle that?

Ava: It does, as an option. Models often wrap a diagram in a chatty explanation. The node cleans up several response shapes, pulls out the fenced code block, and prefers the one matching the diagram type you chose. A language model isn't required, though.

Andrew: Then how does a picture show up inside ComfyUI?

Ava: For a regular image, it opens the bytes with Pillow, converts to RGB, scales values between zero and one, and wraps them as a tensor ComfyUI understands. For SVG, it tries a CairoSVG conversion for the preview, and the saved file is kept either way.

Andrew: So you get both a preview and the real file.

Ava: Yes. And there's a viewer URL if you want to share the result.

Andrew: How would someone try it?

Ava: Install it with the comfy node install command, restart ComfyUI, and open the example workflow called uml single diagram only. It's just two nodes, a diagram node feeding a preview. There are also examples for Mermaid, PlantUML and Ollama.

Andrew: So you start with the smallest thing and grow from there.

Ava: Exactly. Diagrams become one more node in your workflow. The full write-up has the flow diagram and links to the node's source code.

A ComfyUI-UML diagram workflow, from the repository README
Table of contents

ComfyUI is useful beyond image generation when an intermediate result can become a node output. ComfyUI-UML applies that idea to diagrams: text enters a rendering node; an image, a saved file, and a shareable URL can leave it.

1. Keep the source in the workflow

A screenshot is hard to revise. Mermaid or PlantUML source is much easier to inspect, compare, and regenerate. The node lets that source travel with the rest of a ComfyUI workflow instead of becoming an unexplained image.

The README documents 28 Kroki diagram types, with output formats validated per type. This does not mean every renderer supports every format.

flowchart TD
  T["Diagram text or optional LLM output"] --> N["Normalize diagram source"]
  N --> U["UMLDiagram node"]
  U --> K["Kroki web renderer"]
  U --> L["Optional local Mermaid / Graphviz"]
  K --> O["Image, file and URL outputs"]
  L --> O
  O --> P["PreviewImage or Diagram Viewer URL"]

This is a conceptual view of the documented nodes, not a requirement to use an LLM.

2. What the code does with model output

nodes/uml_diagram.py[1] normalizes strings and several response shapes, extracts fenced diagram blocks, and prefers a block matching the selected type. That helps when a model returns prose around Mermaid code.

Extraction is not the same thing as syntax validation. A clean code block can still contain a broken diagram; the renderer must accept it.

3. From rendered bytes to a ComfyUI image

Raster output is opened with Pillow, converted to RGB, normalized to floating-point values between zero and one, and wrapped as a tensor shaped [1, H, W, 3].

SVG is different. The code attempts a CairoSVG conversion for an image preview. For non-raster output without a successful conversion, it can return a tiny placeholder tensor while preserving the file output. That distinction explains why a saved SVG and its preview may behave differently.

4. Start with the smallest workflow

comfy node install comfyui-uml

Then restart ComfyUI and try the repository’s uml_single_diagram_only.json: UMLDiagram → PreviewImage. Add the viewer after rendering works. The repository also supplies Mermaid, PlantUML, and Ollama examples.

The web backend sends diagram source to the selected Kroki service. For sensitive architecture or offline use, the repository documents optional local Mermaid and Graphviz paths. Local Mermaid needs its JavaScript dependencies; SVG preview may need CairoSVG.

5. Source trail

References

  1. antoinebou12. (). nodes/uml_diagram.py. [Source file or documentation] github.com.
  2. antoinebou12. (). ComfyUI-UML. [Software repository] github.com.
  3. antoinebou12. (). Example workflows. [Source file or documentation] github.com.

References use this article’s publication date.