UML and standard diagrams

Sequence, class, state, ERD, activity: the workhorses.

The diagram types most engineers already half-know. Sequence and state diagrams are the two that repay the effort most often, because both describe things prose is genuinely bad at: interleaving over time, and the set of legal transitions.

When to use these

When not to

Common mistakes

Sequence diagrams grow horizontally without limit and become unreadable somewhere around eight participants. If yours has more, it is usually two diagrams: the happy path, and the failure handling.

State diagrams are worth drawing precisely because they force you to answer "what happens if this arrives twice?", a question that rarely gets asked in prose.

The 10 templates

Sequence Diagram.puml

The highest-value diagram in this list. Time runs down; participants across.

Sequence Diagram: rendered example
Show the source
@startuml

title Sequence Diagram

actor User as U
participant "Web App" as W
participant "API" as A
database "Database" as D

U -> W: Request
activate W

W -> A: API Call
activate A

A -> D: Query
activate D
D --> A: Results
deactivate D

A --> W: Response
deactivate A

W --> U: Display

The rest of this template, and how to use it

Activity / Flow Diagram.puml

Earns its place when there are real branches and joins.

Activity / Flow Diagram: rendered example
Show the source
@startuml

title Activity Diagram

start

:Initialize;

if (Condition?) then (yes)
  :Action A;
  :Action B;
else (no)
  :Action C;
endif

fork
  :Parallel Task 1;
fork again
  :Parallel Task 2;
end fork

:Final Step;

stop

The rest of this template, and how to use it

Use Case Diagram.puml

Actor-to-goal. Dated, but still the clearest way to show scope boundaries.

Use Case Diagram: rendered example
Show the source
@startuml

title Use Case Diagram

left to right direction

actor "User" as user
actor "Admin" as admin

rectangle "System" {
  usecase "Login" as UC1
  usecase "View Dashboard" as UC2
  usecase "Manage Users" as UC3
  usecase "Generate Report" as UC4
}

user --> UC1
user --> UC2
user --> UC4

admin --> UC1
admin --> UC3
UC3 ..> UC1 : <<include>>

The rest of this template, and how to use it

Class Diagram.puml

Best used for a single bounded context, not a codebase.

Class Diagram: rendered example
Show the source
@startuml

title Class Diagram

abstract class Animal {
  - name: String
  - age: int
  + getName(): String
  + makeSound(): void
}

class Dog extends Animal {
  - breed: String
  + fetch(): void
  + makeSound(): void
}

class Cat extends Animal {
  - indoor: boolean
  + scratch(): void
  + makeSound(): void
}

interface Trainable {

The rest of this template, and how to use it

State Diagram.puml

Forces the awkward questions about duplicate and out-of-order events.

State Diagram: rendered example
Show the source
@startuml

title State Diagram

[*] --> Idle

state Idle {
  [*] --> Waiting
  Waiting --> Waiting : timeout
}

Idle --> Processing : start
Processing --> Success : complete
Processing --> Error : fail

Success --> Idle : reset
Error --> Idle : reset
Error --> Processing : retry

Success --> [*]

@enduml

Notes and a copy button for this template

ER Diagram.puml

Cardinality is the part people get wrong. Write it explicitly.

ER Diagram: rendered example
Show the source
@startuml

title Entity Relationship Diagram

entity "User" as user {
  * id : INT <<PK>>
  --
  * email : VARCHAR(255)
  * password_hash : VARCHAR(255)
  created_at : TIMESTAMP
}

entity "Post" as post {
  * id : INT <<PK>>
  --
  * user_id : INT <<FK>>
  * title : VARCHAR(255)
  content : TEXT
  published : BOOLEAN
  created_at : TIMESTAMP
}

entity "Comment" as comment {
  * id : INT <<PK>>

The rest of this template, and how to use it

Mind Map.puml

For structuring thinking, not for documenting a system.

Mind Map: rendered example
Show the source
@startmindmap

title Mind Map

* Project
** Planning
*** Requirements
*** Timeline
*** Resources
** Development
*** Frontend
**** Components
**** Styling
*** Backend
**** API
**** Database
** Testing
*** Unit Tests
*** Integration Tests
** Deployment
*** Staging
*** Production

@endmindmap

Notes and a copy button for this template

Gantt Chart.puml

Plans, not architecture, but it renders from text, so it diffs in review.

Gantt Chart: rendered example
Show the source
@startgantt

title Project Timeline

Project starts 2024-01-01

[Planning] lasts 10 days
[Design] lasts 15 days
[Design] starts at [Planning]'s end

[Development] lasts 30 days
[Development] starts at [Design]'s end

[Testing] lasts 15 days
[Testing] starts at [Development]'s end

[Deployment] lasts 5 days
[Deployment] starts at [Testing]'s end

@endgantt

Notes and a copy button for this template

Work Breakdown Structure.puml

Work breakdown. Useful for scoping a piece of delivery.

Work Breakdown Structure: rendered example
Show the source
@startwbs

title Work Breakdown Structure

* Project
** Phase 1: Planning
*** Define Scope
*** Identify Stakeholders
*** Create Timeline
** Phase 2: Execution
*** Task 1
**** Subtask 1.1
**** Subtask 1.2
*** Task 2
*** Task 3
** Phase 3: Closure
*** Documentation
*** Handover

@endwbs

Notes and a copy button for this template

Render these offline

Every template here ships in Gnomon and renders on your machine, with no account and nothing sent to a server. The browser editor is free and needs no install.

Get GnomonOpen the browser editor