Blog
Wild & Free Tools

Sequence Diagram Examples: 8 Real-World Systems with Copy-Paste Code

Last updated: January 2026 12 min read
Quick Answer

Table of Contents

  1. User Login System
  2. ATM Cash Withdrawal
  3. Online Shopping Cart
  4. Library Management System
  5. Hospital Appointment Booking
  6. More Examples: Registration, Email, Payment
  7. Frequently Asked Questions

The fastest way to learn sequence diagrams is to study real examples. Below are eight complete, copy-paste-ready sequence diagrams covering the systems that come up most often in software engineering courses and real-world projects. Each one includes the Mermaid code you can paste directly into our free sequence diagram tool to see it rendered instantly.

These are not toy examples. Each diagram uses proper UML notation with error handling, alt blocks for conditional flows, and realistic participant names. Use them as starting points and modify them for your specific system.

1. User Login with Authentication

The login flow is the most commonly requested sequence diagram in both courses and real documentation. Here is a complete version with password hashing and JWT tokens:

sequenceDiagram
    actor User
    participant UI as Login Page
    participant Auth as Auth Server
    participant DB as User Database

    User->>UI: Enter email + password
    UI->>Auth: POST /auth/login
    Auth->>DB: Find user by email
    alt User exists
        DB-->>Auth: User record + hashed password
        Auth->>Auth: Compare password hash
        alt Password matches
            Auth->>Auth: Generate JWT
            Auth-->>UI: 200 {token, user}
            UI-->>User: Redirect to dashboard
        else Wrong password
            Auth-->>UI: 401 Invalid credentials
            UI-->>User: Show error message
        end
    else User not found
        Auth-->>UI: 401 Invalid credentials
        UI-->>User: Show error message
    end

Notice the nested alt blocks. The outer one checks if the user exists. The inner one checks the password. This two-layer validation is how real auth systems work. The response for "user not found" and "wrong password" should be identical (both 401) to prevent account enumeration attacks.

2. ATM System: Cash Withdrawal

The ATM is a classic software engineering assignment. This diagram covers card validation, PIN verification, balance check, and cash dispensing:

sequenceDiagram
    actor Customer
    participant ATM
    participant Bank as Bank Server
    participant Account as Account DB

    Customer->>ATM: Insert card
    ATM->>Bank: Validate card number
    Bank-->>ATM: Card valid

    Customer->>ATM: Enter PIN
    ATM->>Bank: Verify PIN
    alt PIN correct
        Bank-->>ATM: PIN verified
        Customer->>ATM: Select withdrawal, enter amount
        ATM->>Bank: Check balance
        Bank->>Account: Query balance
        Account-->>Bank: Current balance
        alt Sufficient funds
            Bank->>Account: Debit amount
            Account-->>Bank: Updated balance
            Bank-->>ATM: Approved
            ATM-->>Customer: Dispense cash
            ATM-->>Customer: Print receipt
        else Insufficient funds
            Bank-->>ATM: Declined
            ATM-->>Customer: Show insufficient funds
        end
    else PIN incorrect
        Bank-->>ATM: PIN invalid
        ATM-->>Customer: Show error, retry
    end

The alt blocks model two decision points: PIN verification and balance check. In a real system, there would also be a loop for PIN retries (max 3 attempts before the card is retained), but this version keeps it focused on the main flow.

3. Online Shopping: Add to Cart and Checkout

sequenceDiagram
    actor Shopper
    participant Web as Web App
    participant Cart as Cart Service
    participant Inv as Inventory
    participant Pay as Payment Gateway
    participant Order as Order Service

    Shopper->>Web: Add item to cart
    Web->>Cart: Add item (productId, qty)
    Cart->>Inv: Check stock
    alt In stock
        Inv-->>Cart: Available
        Cart-->>Web: Item added
        Web-->>Shopper: Updated cart view
    else Out of stock
        Inv-->>Cart: Unavailable
        Cart-->>Web: Out of stock error
        Web-->>Shopper: Show out of stock
    end

    Shopper->>Web: Proceed to checkout
    Web->>Cart: Get cart summary
    Cart-->>Web: Items + total
    Shopper->>Web: Enter payment info
    Web->>Pay: Charge card
    alt Payment success
        Pay-->>Web: Confirmed
        Web->>Order: Create order
        Order->>Inv: Reserve items
        Inv-->>Order: Reserved
        Order-->>Web: Order ID
        Web-->>Shopper: Order confirmation
    else Payment failed
        Pay-->>Web: Declined
        Web-->>Shopper: Payment error
    end

This diagram separates the cart flow from the checkout flow. In a microservices architecture, the cart service, inventory service, payment gateway, and order service are often separate deployments. The sequence diagram shows exactly which service calls which and in what order, making it useful for both documentation and onboarding new developers to the codebase.

Sell Custom Apparel — We Handle Printing & Free Shipping

4. Library System: Book Borrowing

sequenceDiagram
    actor Member
    participant Lib as Library System
    participant Cat as Catalog DB
    participant Acc as Member Account

    Member->>Lib: Search for book
    Lib->>Cat: Query by title/author
    Cat-->>Lib: Search results
    Lib-->>Member: Display available books

    Member->>Lib: Request to borrow book
    Lib->>Acc: Check borrowing limit
    alt Under limit
        Acc-->>Lib: Can borrow
        Lib->>Cat: Check availability
        alt Available
            Cat-->>Lib: Book available
            Lib->>Cat: Mark as borrowed
            Lib->>Acc: Add to member record
            Acc-->>Lib: Updated
            Lib-->>Member: Book issued, due date set
        else All copies out
            Cat-->>Lib: Not available
            Lib-->>Member: Add to waitlist?
        end
    else Limit reached
        Acc-->>Lib: At maximum
        Lib-->>Member: Return a book first
    end

The library system has two validation gates: borrowing limit and book availability. Both need to pass before the book is issued. This is a pattern that appears in many systems: validate authorization first (can this user do this?), then validate the resource (is this thing available?). The same pattern applies to hotel reservations, course registrations, and appointment bookings.

5. Hospital: Appointment Booking and Check-In

sequenceDiagram
    actor Patient
    participant Portal as Patient Portal
    participant Sched as Scheduling Service
    participant Doc as Doctor Calendar
    participant Notify as Notification Service

    Patient->>Portal: Select department + date
    Portal->>Sched: Get available slots
    Sched->>Doc: Query open appointments
    Doc-->>Sched: Available time slots
    Sched-->>Portal: Display slots
    Portal-->>Patient: Show available times

    Patient->>Portal: Book slot
    Portal->>Sched: Reserve appointment
    Sched->>Doc: Block time slot
    Doc-->>Sched: Confirmed
    Sched-->>Portal: Booking confirmed

    par Send notifications
        Sched->>Notify: Email confirmation to patient
    and
        Sched->>Notify: Calendar update to doctor
    end

    Portal-->>Patient: Confirmation with details

The par block at the end shows notifications going out simultaneously to both the patient and the doctor. In a real system, these notifications are typically async. The patient does not need to wait for the doctor's calendar to update before seeing their confirmation.

For more diagram types that work well for hospital systems, an ER diagram can map the patient-doctor-appointment data model, while a flowchart can map the triage decision process.

6-8. Student Registration, Email Send, and Payment Processing

6. Student Registration:

sequenceDiagram
    actor Student
    participant Reg as Registration System
    participant Course as Course DB
    participant Billing

    Student->>Reg: Select courses
    Reg->>Course: Check prerequisites
    alt Prerequisites met
        Course-->>Reg: Approved
        Reg->>Course: Check seats available
        alt Seats available
            Course-->>Reg: Enrolled
            Reg->>Billing: Calculate tuition
            Billing-->>Reg: Amount due
            Reg-->>Student: Enrolled, invoice generated
        else Full
            Course-->>Reg: Waitlisted
            Reg-->>Student: Added to waitlist
        end
    else Missing prerequisites
        Course-->>Reg: Blocked
        Reg-->>Student: Prerequisites required
    end

7. Email Sending:

sequenceDiagram
    participant App
    participant Queue as Email Queue
    participant SMTP as SMTP Server
    participant Inbox as Recipient Inbox

    App->>Queue: Enqueue email job
    Queue-->>App: Queued
    Note over Queue: Processed async
    Queue->>SMTP: Send email
    alt Delivered
        SMTP-->>Queue: 250 OK
        SMTP->>Inbox: Deliver message
        Queue->>Queue: Mark as sent
    else Bounced
        SMTP-->>Queue: 550 Rejected
        Queue->>Queue: Mark as bounced, notify sender
    end

8. Payment Processing:

sequenceDiagram
    participant App
    participant Gateway as Payment Gateway
    participant Bank as Issuing Bank
    participant Fraud as Fraud Check

    App->>Gateway: Charge request
    Gateway->>Fraud: Risk assessment
    alt Low risk
        Fraud-->>Gateway: Approved
        Gateway->>Bank: Authorization request
        alt Authorized
            Bank-->>Gateway: Auth code
            Gateway-->>App: Payment confirmed
        else Declined
            Bank-->>Gateway: Declined reason
            Gateway-->>App: Payment failed
        end
    else High risk
        Fraud-->>Gateway: Flagged
        Gateway-->>App: Requires 3D Secure
    end

All eight examples above work in our sequence diagram tool. Paste the code, export as PNG for your assignment or SVG for your documentation wiki.

Paste Any Example and See It Rendered

Copy the code for any system above, paste it in the editor, and export as PNG or SVG. Free, instant, no account.

Open Free Sequence Diagram Maker

Frequently Asked Questions

Where can I find sequence diagram examples for my project?

This page has eight complete examples covering login, ATM, shopping, library, hospital, registration, email, and payment systems. Each includes copy-paste Mermaid code you can modify for your specific system. Paste into our free tool to render instantly.

How do I draw a sequence diagram for a login system?

Define four participants: User, UI, Auth Server, Database. Show the login request flowing from UI to Auth, the database lookup, password comparison as a self-call, and alt blocks for success (return token) and failure (return error). Our tool renders this from text in seconds.

What is the best way to learn sequence diagrams?

Start with simple examples like the login flow, then add complexity with alt blocks and loops. Read the notation guide to understand arrow types, then practice by diagramming a system you already know well. Our free tool gives instant visual feedback as you type.

Can I use these examples for my university assignment?

Yes. These are standard UML sequence diagram patterns using proper notation. Modify the participant names and message labels to match your specific assignment requirements. Export as PNG or SVG for your submission.

Claire Morgan
Claire Morgan AI & ML Engineer

Claire leads development of WildandFree's AI-powered tools, holding a master's in computer science focused on applied machine learning.

More articles by Claire →
Launch Your Own Clothing Brand — No Inventory, No Risk