3.3.1 Why Notes and Loops Are Important
So far, sequence diagrams have shown:
However, real-world systems also require:
Two powerful constructs in Mermaid help here:
Notes → Add explanation to interactions
Loops → Represent repeated execution
These features transform a basic interaction diagram into production-grade documentation.
3.3.2 Adding Notes
Notes provide commentary inside the diagram.
Basic syntax:
Positions:
Example 1 — Note on a Single Participant
Explanation:
The note appears beside Server.
Notes improve clarity without changing logic.
3.3.3 Notes Over Multiple Participants
You can attach notes across participants.
Syntax:
Example:
This is useful for:
3.3.4 Multi-Line Notes
Mermaid supports block notes.
Use block notes for:
3.3.5 Loops: Modeling Repetition
In distributed systems, repetition is common:
Iteration through collections
Mermaid provides the loop keyword.
Basic syntax:
Example 2 — Retry Mechanism
This represents repeated attempts.
3.3.6 Practical Example — Payment Retry
The loop visually communicates:
Dependency on external state
3.3.7 Combining Activation with Loops
Loops can contain activations.
This models polling systems clearly.
3.3.8 Loops with Nested Calls
Example: Order processing with inventory check.
This models iteration across data collections.
3.3.9 Notes Inside Loops
You can annotate loop logic.
Combining notes and loops improves documentation depth.
3.3.10 Real-World Example — Authentication with Token Refresh
This captures:
Repeated refresh attempts
3.3.11 Best Practices for Notes
Use notes for context, not logic
Avoid overloading diagram with excessive commentary
Use Note over for system-level assumptions
Example of good use:
3.3.12 Best Practices for Loops
Clearly describe loop condition
Avoid vague labels like “Loop”
Use loops only when repetition is essential
Good:
Poor:
3.3.13 Common Mistakes
Nesting loops incorrectly
Using loops where a single call suffices
Incorrect:
Correct:
3.3.14 Hands-On Exercise
Build a File Upload Workflow:
Requirements:
Add note explaining file size limit
Show final success response
Constraints:
Maintain clean chronological order
3.3.15 Key Takeaways
Notes add contextual clarity.
Loops model repeated behavior.
Together, they allow you to represent:
By mastering participants, messages, activation, notes, and loops, you can now model realistic, production-level system interactions using Mermaid sequence diagrams.
In the next chapter, we will move into Class Diagrams, where structural modeling replaces chronological interaction modeling.