Skip to content
Tutorials Center
My learning

Topics

Lesson 13 of 39 ยท Use Case and Activity Diagrams

Activity Diagram Basics

Learn UML activity diagrams: initial and final nodes, actions, decisions, merges, loops, and how to model a business process or algorithm step by step.

An activity diagram shows the flow of a process: what happens, in what order, and where the path branches. It is UML's version of the flowchart, with a richer vocabulary (parallel flows, swimlanes, object flows) that you will meet in the next lesson. Use it for business processes, use case scenarios, workflows and algorithms.

Core notation

Element Symbol Meaning
Initial node filled black circle Where the flow starts
Action rounded rectangle One step of work
Control flow arrow Order between nodes
Decision diamond with one input, several guarded outputs Choose one path
Merge diamond with several inputs, one output Join alternative paths
Activity final circle with a dot inside (bullseye) End of the whole activity
Flow final circle with an X End of one path only

Mermaid has no activity-specific type, so we use flowchart. Rounded stadium shapes serve as actions and start/end markers, diamonds as decisions.

flowchart TD
    S(("Start")) --> A["Receive order"]
    A --> B["Check stock"]
    B --> C{"In stock?"}
    C -- "[yes]" --> D["Pack and ship"]
    C -- "[no]" --> E["Notify customer"]
    D --> F(("End"))
    E --> F

A tiny order-handling activity. Guards in square brackets label the decision outputs.

Actions

An action is a single, atomic step: Check stock, Send email, Calculate total. Name actions with a verb phrase. An action begins when all its inputs arrive and, when it finishes, offers a token to its outgoing flow.

The tokens idea is useful: imagine a marker travelling along the arrows. A decision sends the token one way; a merge lets any incoming token through. This model explains parallel flows in the next lesson.

Decisions and merges

A decision node has outgoing flows with guards, boolean conditions in square brackets. Rules:

  • Guards on one decision must be mutually exclusive and cover all cases. Use [else] as a safety net.
  • A decision does not wait for anything; it just routes the token.

A merge node brings alternative paths back together. It does not synchronize; the first token through continues. (Synchronization is a join, covered later.)

flowchart TD
    S(("Start")) --> A["Enter password"]
    A --> B{"Password correct?"}
    B -- "[yes]" --> C["Open account"]
    B -- "[else]" --> D["Show error"]
    D --> E{"Attempts left?"}
    E -- "[yes]" --> A
    E -- "[else]" --> F["Lock account"]
    C --> G(("End"))
    F --> G

A login activity with a loop: a decision sends the token back to an earlier action.

Loops

UML has no special loop symbol on activity diagrams: a loop is a decision that sends flow backwards to an earlier node (as above). For clarity, give the loop a guard that says when to continue and when to leave.

Reading and writing a diagram

  1. Find the start and follow arrows. Every path must lead to an end.
  2. For each decision, check that the guards cover all cases.
  3. Check that every action has at least one input and one output (except at the start and end).
  4. Avoid dead ends: a node with no way out and no end symbol is an error.
Python Run an activity as a state machine of tokens

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Python Validate an activity: every path must reach the end

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The checker finds the missing arrow at d, and also reports its predecessors. Tools can run similar checks automatically.

Activity diagrams for algorithms

Activity diagrams can describe an algorithm before you code it. Here is "find the largest number in a list".

flowchart TD
    S(("Start")) --> A["max = first item"]
    A --> B{"more items?"}
    B -- "[yes]" --> C["x = next item"]
    C --> D{"x > max?"}
    D -- "[yes]" --> E["max = x"]
    D -- "[no]" --> B
    E --> B
    B -- "[no]" --> F["return max"]
    F --> G(("End"))

Nested decisions and a loop in one diagram.

Python The same algorithm in code

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Activity vs flowchart vs sequence

Which diagram for which flow?

Activity Steps and decisions of a process.
Sequence Messages between objects.
State machine Life of one object.

Activity diagrams show work; sequence diagrams show talk.

1 / 2

An activity diagram focuses on control flow (what comes next), not on which object performs a step; sequence diagrams focus on who sends what to whom. Use activity diagrams to explain a process to a business audience or to flesh out a use case; use sequence diagrams to design a collaboration.

Common mistakes

  • Too much detail. One action per mouse click makes the diagram useless. Use one action per meaningful step.
  • Missing guards. A decision with unlabeled branches leaves readers guessing.
  • Unclear start or end. Include exactly one start; multiple ends are fine when they mean different outcomes.
  • Mixing levels. "Calculate tax" next to "Open database connection" belongs in two diagrams.
  • Treating it as a state diagram. Boxes in an activity diagram are work, not states.

When a use case specification has many alternative flows, draw its activity diagram. Gaps in the text show up as missing arrows.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does a decision node look like?

    Decision nodes are diamonds whose outgoing flows have guard conditions.
  2. 2. What is the difference between a merge and a join?

    Merges bring alternative paths together; joins synchronize parallel flows.
  3. 3. How is a loop shown in an activity diagram?

    A flow back to an earlier node, controlled by a decision, forms a loop.
  4. 4. What should guards on one decision satisfy?

    Exactly one path should be chosen; [else] covers the remainder.

Summary

  • Activity diagrams model control flow: initial node, actions, decisions, merges and final nodes.
  • Guards in square brackets label decision outputs; they must be exclusive and complete.
  • Loops are flows back to an earlier node through a decision.
  • Use them for processes, use case scenarios and algorithms; verify that every path ends.
  • Keep actions at one meaningful level of detail.

Next: Swimlanes, Forks and Joins