Data model
Class and component diagrams from compact text, with a card for each entity.
What it shows
Draw UML from compact text, and give a model's entities cards of their own.
What you learn
A plugin block for diagrams, a palette colour, a block rule that makes a card, a line rule that splits a line in two, a keep rule for stereotypes, word rules for key badges.
Try this
- In the Plan card, copy the perMinute line and rename it dailyCap, and it lines up with the other fields.
- Change
modelin the palette to #2b8a3e, and every card, operation and key badge turns green.
Bikes, docks and trips
The model the team agreed at the design review on 14 October 2026. A rider unlocks a bike at one station, rides, and docks it at another, and a plan prices the trip.
Entities
Each entity the database stores, with its key and the fields the apps read.
| Plan | Unlock | Per minute | Who it is for |
| Day | £1.00 | £0.12 | Visitors and one-off rides |
| Commuter | £0.00 | £0.08 | Riders with a monthly pass |
| Student | £0.50 | £0.06 | Students with a college email |
Components
The backend is split so that pricing can change weekly without touching the fleet code.
How it's made
- The diagrams are nomnoml text in blocks marked
uml. A class is[Name|fields|operations], with;between lines, and[Vehicle]<:-[Bike]says a bike is a kind of vehicle. - A card is a
[[line, a= Nameline, one line per field and a]]line. The:::: cardsblock around them lays them out in a grid. - A field line is a name, a colon with a space either side, and a type. The rule splits it in two, so the types line up on the right.
- Marks. A line starting with
+is an operation,<<entity>>is a stereotype, and the words PK and FK become badges. They all take their colour frommodelin the palette.
Try it yourself
- In the Plan card, copy the
perMinuteline and rename the copydailyCap. It lines up with the other fields. - In the class diagram, add
[Dock|number: int;free: bool]and[Station] 1 -> 1..*[Dock]. The diagram draws the new class and its link. - Add a fifth card for the Bike, with
= Bike <<entity>>, anidfield ending in PK and aframeSizefield. The grid makes room for it. - Change
modelin the palette to #2b8a3e. The cards, the operations and the PK badges turn green.
Next: Design document puts diagrams like these in a proposal; Code snippets shows the code that goes with them.
~~~ selfscribe
# Lesson: Draw UML from compact text, and give a model's entities cards of their own.
# You learn: a plugin block for diagrams, a palette colour, a block rule that makes a card, a line rule that splits a line in two, a keep rule for stereotypes, word rules for key badges.
# Try this: in the Plan card, copy the perMinute line and rename it dailyCap, and it lines up with the other fields.
# Try this: change `model` in the palette to #2b8a3e, and every card, operation and key badge turns green.
# summary: Class and component diagrams from compact text, with a card for each entity.
# category: diagrams
# tags: document, simple, work
# uses: diagram, cards
use markdown
set title Data model
set style sans
set font IBM Plex Sans
set heading-font IBM Plex Sans
# ---- The model's colour, with its shade for dark pages ---------------------------------
palette model #1864ab dark #74c0fc
# ---- ```uml ... ```: a nomnoml diagram, drawn by the uml plugin ------------------------
block ``` uml ... ``` -> uml verbatim
# ---- "system …" above the title: the system the model belongs to ------------------------
line system _ -> div.system { font: 600 0.78em/1 var(--doc-font-mono); letter-spacing: 0.06em; color: var(--model); margin-bottom: -2.4em } as um-system
line lead _ -> p.lead { font-size: 1.1em; line-height: 1.5; opacity: 0.8 } as um-lead
# ---- ":::: cards" ... "::::": a grid that holds the cards side by side -----------------
block :::: cards ... :::: -> div.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(14em, 1fr)); gap: 0.9em; margin: 1em 0 1.6em } as um-cards
# ---- "[[" ... "]]": one entity card; "= Name" heads it, "name : type" is a field ---------
block [[ ... ]] -> section.entity { padding: 0.75em 1em 0.6em; border-radius: 10px; border: 1px solid color-mix(in srgb, currentColor 14%, transparent); border-top: 3px solid var(--model); background: color-mix(in srgb, var(--model) 5%, transparent); font-size: 0.88em } as um-entity
line = _ -> div.entity-name { font: 700 1.1em/1.3 var(--doc-font-ui); padding-bottom: 0.45em; margin-bottom: 0.35em; border-bottom: 1px solid color-mix(in srgb, currentColor 14%, transparent) } as um-entity-name
# The colon splits the line: the name goes left, the type right.
line _ : _ -> div.field split ":" span { display: flex; justify-content: space-between; gap: 1em; padding: 0.16em 0; font-family: var(--doc-font-mono); font-size: 0.9em } as um-field
# "+ name()" is an operation, in the model's colour.
line + _ -> div.op keep { font-family: var(--doc-font-mono); font-size: 0.85em; color: var(--model); padding-top: 0.3em } as um-op
# "<<entity>>" is a stereotype; keep shows the angle brackets.
inline <<_>> -> span.stereo keep { font: italic 400 0.74em var(--doc-font-ui); opacity: 0.6; margin-left: 0.3em } as um-stereo
# PK marks the key, FK a key that points at another entity: one badge shape, two tints.
class key { font: 700 0.65em/1 var(--doc-font-ui); padding: 0.25em 0.4em; border-radius: 4px; margin-left: 0.4em; vertical-align: 0.1em }
word PK -> span.key { background: color-mix(in srgb, var(--model) 18%, transparent); color: var(--model) } as um-pk
word FK -> span.key { background: color-mix(in srgb, currentColor 9%, transparent) } as um-fk
~~~
system wexcombe-bikes / model
# Bikes, docks and trips
lead The model the team agreed at the design review on 14 October 2026. A rider unlocks a bike at one station, rides, and docks it at another, and a plan prices the trip.
```uml
#direction: right
#spacing: 38
#padding: 10
[Rider|email: string;joined: Date|startTrip(bike)]
[Plan|name: string;unlockFee: Money;perMinute: Money]
[Trip|started: Time;ended: Time?;distance: km?|price(): Money]
[<abstract>Vehicle|id: VehicleId;battery: Percent?|unlock();lock()]
[Bike|frameSize: cm]
[EBike|motorWatts: int;range: km]
[Station|name: string;location: LatLng;docks: int|freeDocks(): int]
[Rider]-> 1[Plan]
[Rider] 1 -> 0..*[Trip]
[Trip]-> 1[Vehicle]
[Trip]-> from 1[Station]
[Vehicle]<:-[Bike]
[Vehicle]<:-[EBike]
[Station]o-> 0..*[Vehicle]
```
## Entities
Each entity the database stores, with its key and the fields the apps read.
:::: cards
[[
= Station <<aggregate>>
id : StationId PK
name : string
location : LatLng
docks : int
+ freeDocks() : int
]]
[[
= Trip <<entity>>
id : TripId PK
rider : RiderId FK
vehicle : VehicleId FK
started : Time
ended : Time?
+ price() : Money
]]
[[
= Rider <<entity>>
id : RiderId PK
email : string
plan : PlanName FK
joined : Date
]]
[[
= Plan <<value>>
name : PlanName PK
unlockFee : Money
perMinute : Money
]]
::::
| Plan | Unlock | Per minute | Who it is for |
|---|---|---|---|
| Day | £1.00 | £0.12 | Visitors and one-off rides |
| Commuter | £0.00 | £0.08 | Riders with a monthly pass |
| Student | £0.50 | £0.06 | Students with a college email |
## Components
```uml
#direction: down
[<actor>Rider]
[<frame>Mobile app|[Map];[Scanner]]
[<frame>Backend|[Trips API]->[Pricing];[Trips API]->[Fleet]]
[<database>Trips DB]
[Rider]->[Mobile app]
[Mobile app]->[Backend]
[Backend]->[Trips DB]
```
The backend is split so that pricing can change weekly without touching the fleet code.
---
## How it's made
- **The diagrams** are nomnoml text in blocks marked `uml`. A class is `[Name|fields|operations]`, with `;` between lines, and `[Vehicle]<:-[Bike]` says a bike is a kind of vehicle.
- **A card** is a `[[` line, a `= Name` line, one line per field and a `]]` line. The `:::: cards` block around them lays them out in a grid.
- **A field line** is a name, a colon with a space either side, and a type. The rule splits it in two, so the types line up on the right.
- **Marks.** A line starting with `+` is an operation, `<<entity>>` is a stereotype, and the words PK and FK become badges. They all take their colour from `model` in the palette.
## Try it yourself
1. In the Plan card, copy the `perMinute` line and rename the copy `dailyCap`. It lines up with the other fields.
2. In the class diagram, add `[Dock|number: int;free: bool]` and `[Station] 1 -> 1..*[Dock]`. The diagram draws the new class and its link.
3. Add a fifth card for the Bike, with `= Bike <<entity>>`, an `id` field ending in PK and a `frameSize` field. The grid makes room for it.
4. Change `model` in the palette to #2b8a3e. The cards, the operations and the PK badges turn green.
Next: *Design document* puts diagrams like these in a proposal; *Code snippets* shows the code that goes with them.