Unsaved
Ready
Loading Monaco Editor...
Preview
Styling
All diagram types

ZenUML Sequence Syntax & Mermaid Examples

ZenUML is a code-shaped way to write a sequence diagram. Calls look like methods, and braces show what happens inside the call.

Examples

Copy an example, or open it in the live editor with this diagram already loaded.

Nested order call

The braces are the body of the call. return is the value that call hands back to its caller.

zenuml
    title Place an order
    @Actor Client
    @Boundary Api
    @Entity Orders
    Client->Api.place(cart) {
        Api->Orders.create(cart) {
            return order
        }
        return confirmation
    }

A call that reaches storage

Each extra level of braces is another participant doing work before the outer call can return.

zenuml
    title Save a draft
    @Actor Author
    @Boundary Editor
    @Entity Drafts
    Author->Editor.save(text) {
        Editor->Drafts.upsert(text) {
            return id
        }
        return id
    }

Two sequential calls

Calls one after another, without nesting, are two messages in order. Nest only the work that happens inside a call.

zenuml
    title Sign in
    @Actor User
    @Boundary Api
    @Entity Directory
    User->Api.login(email) {
        Api->Directory.find(email) {
            return user
        }
        return session
    }

What is a ZenUML Diagram?

ZenUML is an alternate sequence syntax that Mermaid renders with the ZenUML diagram type. You still have actors and participants, but a message is a method call: Client->Api.place(order) { ... }. The braces are the work that happens before the call returns. return sends a value back. Annotations such as @Actor, @Boundary, and @Entity change how a participant is drawn. Use ZenUML when the interaction really is a call stack. Use a classic sequence diagram when you want arrows, notes, and alt/loop fragments.

When to use it

Use ZenUML for a service call tree you want to read like code. Use a sequence diagram when the interaction has branches, loops, or several independent replies. Use a class diagram when you need the types rather than one execution.

Edit this zenuml diagram in the live editor, read the Mermaid cheat sheet, or compare it with Sequence Diagram, Flowchart and Class Diagram.

Common Use Cases

  • •API documentation - Document service interactions with code-like syntax
  • •Developer communication - Express sequence logic in familiar programming style
  • •Microservice interactions - Show service-to-service method calls
  • •Code review - Visualize complex call chains before implementation
  • •Technical specifications - Define interaction contracts between services

Syntax Quick Reference

ElementSyntaxDescription
Titletitle NameDiagram heading
Participant@Actor NameDefine an actor or participant
Method callA->B.method(args)Synchronous call
Nested call{ ... }Calls within a method scope
Returnreturn valueReturn from a method call
Stereotype@Boundary, @EntityParticipant type annotation

Syntax tips

  • •Start with zenuml. title is optional and sits on the next line.
  • •Annotate a participant before it is used: @Actor Client, @Boundary Api, @Entity Orders.
  • •A message is Caller->Callee.method(args). The braces that follow are the callee's work.
  • •return value ends that call. Put it inside the braces of the call that is returning.
  • •Indent the nested calls so the braces match. ZenUML is easier to reread when it looks like the code it describes.

Common mistakes

Using sequenceDiagram arrows inside a zenuml block.

ZenUML messages are method calls, Caller->Callee.method(). Arrow syntax belongs in a sequence diagram.

Closing the braces in the wrong order, so a return belongs to the outer call.

The return sits inside the call that produces it. Close the inner braces before the outer return.

Reaching for ZenUML when you need alt or loop.

Those combined fragments are sequence diagram features. Switch diagrams if the interaction has several branches.

Export Options

ZenUML diagrams read well in API docs. SVG keeps the call text sharp. Free PNG exports include a watermark.

Got Mermaid code from ChatGPT? Paste it here to render and export instantly.

Get the Free Mermaid Syntax Cheat Sheet

Free Mermaid Syntax Cheat Sheet

All 21 diagram types in one PDF reference.

Frequently Asked Questions

Ready to create your own zenuml diagram?

Open the editor with this example pre-loaded and start customizing.

Related Diagram Types

All diagram types