# Design rationale Why UJN works the way it does: the main decisions behind the notation, in plain words, each with a small drawing that shows it. ## A journey is written as plain text You write a journey as plain text, from `@startujn` to `@endujn`, with no positions. The PlantUML extension draws it as SVG or PNG, and can also write a file other tools read. Why: - Text is easy to compare between versions, tools can read it, and AI assistants can write it. - One file is both the picture and the data, so nothing has to be kept in step. - The layout is automatic, so nobody places boxes by hand, and the same text always gives the same drawing. What we did not do: - We did not start with draw.io shapes, because tools could not read them without an exporter, and layouts would stay hand-made. - We did not write journeys inside `@startuml`, because words like `actor`, `start` and `end` already mean something there. ```ujn @startujn journey SHOP "Checkout" view cart { title: "Cart"; route: /cart } view pay { title: "Payment"; route: /pay } end paid { description: "Order placed" } cart --> pay : [Check out] pay --> paid : [Pay] @endujn ``` The text gives no positions: the PlantUML extension placed every box and arrow, left to right. ## Other tools read the journey's data file On request, the PlantUML extension also writes the journey as a data file that other editors and tools can read. The spec calls this file the model, and a schema describes every field in it. Why: - Tools build from the data, not the picture, and a picture not drawn from data drifts away from it. - The schema was written with the language, before the code, so each field has one name that every tool uses. - Notes for developers, such as accessibility notes and links to tests, go into the data file and show only as hover text in an SVG, so the drawing stays as designed. What we did not do: - We did not draw pictures first and define the data later, because the pictures would then be redrawn. - We did not keep notes and links in a second file, because two files would have to be kept in step. ```ujn @startujn journey LOGIN "Sign in" view login { title: "Login" description: "Email and password" a11y: "Focus starts in the email field" } view home { title: "Home"; route: /home } login --> home : [Sign in] @endujn ``` The description is drawn; the accessibility note (`a11y`) is not, and goes into the data file and SVG hover text. ## A short first line, details in a block Each screen or step is a short line, such as `view login`, with an optional block of details in braces. An arrow works the same way: `login --> home : [Sign in]`, its name after the colon, then an optional block. Why: - A simple screen stays short: `view register` alone is a complete statement. - Long details, such as a description or links to tests, get room in the block. - Each detail is named, so it is clear, easy for tools to read, and easy for AI assistants to write. What we did not do: - We did not put everything on one line, because a line stays readable only up to about four details. - We did not keep details in a separate data file, because every journey would then need two files. ```ujn @startujn journey REG "Register" view register view details { title: "Your details" description: "Name and email" route: /register/details } view welcome { type: toast; title: "Welcome" } register --> details : [Start] details --> welcome : [Create account] @endujn ``` `register` has no block and shows its own name; `details` takes its title, description and route from its block. ## Nine kinds of node, plus short type lists A journey is drawn with nine kinds of node, such as a screen (view), a system step (action) and an end. Most kinds have a short list of types; a type changes the icon and the type name drawn in the box, but rarely the shape. Why: - Each kind or type earns its place only if it changes what gets built or tested, or clearly helps people read. - Nine kinds are few enough to learn at a glance, yet enough to draw a whole journey. - A type brings fixed behavior: a modal blocks the screen behind it, while a drawer leaves it usable. What we did not do: - We did not give every idea its own shape, because there would be more to learn, and some of those shapes would change nothing that gets built or tested. - We did not stop at three basic shapes, because three were too few to draw a whole journey. ```ujn @startujn journey DEL "Delete a claim" view claim { title: "Claim"; route: /claims/:id } view confirm { type: modal; title: "Delete claim?" } action remove { title: "Delete claim" } view deleted { type: toast; title: "Claim deleted" } claim --> confirm : [Delete] confirm --> remove : [Yes, delete] remove --> deleted @endujn ``` The three views share one frame, with a different icon and type name; the action has its own shape. ## Every screen and pop-up is its own box A pop-up, a side panel, a tab or a wizard step gets its own box, linked to its screen by arrows. No box sits inside another, and there are no swimlanes (bands that group steps by who does them). Why: - PlantUML lays out flat boxes and arrows well, and boxes inside boxes less well. - One rule keeps it simple: links are arrows, and the arrow into a pop-up shows what it opens over. - A swimlane only arranges the drawing by owner; tools read who does what from the boxes themselves. What we did not do: - We did not draw pop-ups or steps inside their screens, because boxes inside boxes are harder to lay out. - We did not add swimlanes, because they need a special layout for something tools do not read from them. ```ujn @startujn journey CLM "New claim" view claims { title: "Claims"; route: /claims } view wizard { type: wizard; title: "New claim" } view details { title: "Details"; parent: wizard } view help { type: modal; title: "Help" } claims --> wizard : [New claim] wizard --> details : [Start] details --> help : [Help] help ..> details @endujn ``` Help and Details are boxes of their own, joined by arrows; `parent: wizard` tells tools that Details is a wizard step. ## Leaving the app gets its own box When the user leaves the app, UJN draws a handoff: a box with a dashed border. It shows where they went and how long they have, and dashed arrows show where they come back. Why: - A box gives the pause a place for its facts: where the user went, the time limit, the link back. - It shows developers, and tools that write code, what to build: the exit, the wait and the way back in. - Leaving and coming back, as with email links and one-time codes, is central to the journeys UJN draws. What we did not do: - We did not just tag the arrow that leaves, because the time limit and way back would need extra boxes. - We did not use a handoff for a new browser tab, because the user stays in the app. ```ujn @startujn journey RESET "Reset password" view forgot { title: "Forgot password"; route: /forgot } action send_link { type: message; title: "Send reset link"; channel: email } handoff email_link { title: "Reset link"; channel: email; timeout: 24 h; resume: /reset/:token } view reset { title: "New password"; route: /reset/:token } view link_expired { title: "Link expired"; route: /reset/expired } forgot --> send_link : [Send link] send_link --> email_link email_link ..> reset : [Open link] valid email_link ..> link_expired : [Open link] expired @endujn ``` The dashed box is the trip to the inbox, marked "email · 24 h"; two dashed arrows bring the user back. ## No decision diamond: conditions sit on arrows UJN has no diamond shape for decisions: the conditions written on the arrows out of a box show the branch. From a screen, the user takes one arrow. From a system step, every arrow without a condition runs, and of the arrows with a condition, exactly one runs. For now: see 23.18. Why: - For a tool that writes code, a diamond and conditions on the arrows mean the same thing. - Drawings stay smaller and cleaner, with no extra diamond for every branch. - On a system step, a condition marks a branch and no condition marks an arrow that always runs; for now, mixing the two on one step is a warning (question 23.18). What we did not do: - We did not draw a diamond for every branch, because each condition would add one more shape. - We did not make the diamond optional, because then one branch could be drawn two ways. ```ujn @startujn journey AUTH "Sign in" view login { title: "Login"; route: /login } action validate { title: "Validate credentials" } view dashboard { title: "Dashboard"; route: /home } view bad_login { type: toast; title: "Incorrect credentials" } login --> validate : [Sign in] validate --> dashboard : valid validate -x-> bad_login : invalid bad_login ..> login @endujn ``` The step "Validate credentials", drawn as an Action, branches with no diamond: its arrows carry "valid" and "invalid". ## Arrow names: what the user does, then when An arrow's name can have two parts: what the user does, in square brackets, then the condition as plain text. The drawing joins them with a dot: `[Sign in] valid credentials` shows as "Sign in · valid credentials". For now: see 23.12. Why: - They are separate facts for testing: a test performs what the user does, and checks the condition both ways. - It reads like PlantUML, with the user's step in brackets after a colon, so PlantUML users read it at once. - After a system step no user acts, so an arrow may carry a condition alone; the brackets tell what the user does apart from a condition. What we did not do: - We did not write arrows as sentences, like `go login check [Sign in]`, because no PlantUML diagram looks like that. - We did not add a word like "if" before the condition; for now it is plain text (question 23.12). ```ujn @startujn journey AUTH "Sign in" view login { title: "Login"; route: /login } view dashboard { title: "Dashboard"; route: /home } view bad_login { type: toast; title: "Incorrect credentials" } view forgot { title: "Forgot password"; route: /forgot } login --> dashboard : [Sign in] valid credentials login -x-> bad_login : [Sign in] wrong password login --> forgot : [Forgot password] bad_login ..> login @endujn ``` Two names show what the user does, then the condition after a dot, as in "Sign in · valid credentials"; "Forgot password" has no condition. ## Going back has an arrow of its own Going back, such as closing a modal or pressing Back, has its own arrow: `..>`, dashed with an open head. Going back after a failure is written `.x.>` and also gets a cross. For now: see 23.11. Why: - Going back is built differently: the app steps back in its history instead of opening a new page. - A failure that sends the user back needed its own arrow, because a plain way back hid the failure. - For a trip to another journey or out of the app, `returns` on one arrow also draws the way back. What we did not do: - We did not, for now, give a retry its own arrow, because a retry opens its screen like any other arrow: it is `-->` with the trigger `[Retry]` (question 23.11). - We did not add an "optional" arrow, because every arrow the user chooses is already optional. ```ujn @startujn journey AUTH "Sign in" view login { title: "Login"; route: /login } action validate { title: "Validate credentials" } view dashboard { title: "Dashboard"; route: /home } ref registration { journey: REG; title: "Registration" } login --> validate : [Sign in] validate --> dashboard : valid validate .x.> login : invalid login --> registration : [Create account] { returns } @endujn ``` The dashed "invalid" arrow with a cross is a failed way back; the dashed arrow from Registration comes from `returns`. ## Flags never change a box's shape A flag marks where a part of the journey stands, such as `future`, or asks for a review, such as `security`. A flagged box keeps its shape: its border turns dotted (a handoff stays dashed) and a tab shows each flag. Why: - A box has one type, which changes the code; it may have several flags, which do not. - Flags such as `future` let one drawing show today's product and the plan together. - The border turns dotted too, because readers of black-and-white prints notice a line more than a small tab. What we did not do: - We did not make the type a flag, because then a screen could be both a modal and a toast. - We did not add a flag for "current", because a box with no status flag is already current. ```ujn @startujn journey AUTH "Sign in" view login { title: "Login"; route: /login } view terms { type: modal; title: "Terms of use" } view passkey { type: modal; title: "Passkey prompt"; flags: [future, security] } login --> terms : [Terms of use] terms ..> login : [Close] login --> passkey : [Use passkey] passkey ..> login : [Cancel] @endujn ``` Both modals keep the same frame; "Passkey prompt" only adds a dotted border and a tab for each of its two flags. ## Delivery flags carry forward; review flags stay put A delivery flag, such as `future`, carries forward to everything reached only through the flagged screen, step or arrow. A review flag, such as `risk`, marks one place only. For now: see 23.3. Why: - You flag one place, and everything reached only through it follows, also when you change that flag later. - A delivery flag says where a part of the journey stands; a review flag asks for attention at one spot. - UJN works out the flags passed on, so the drawing and the file other editors and tools can read agree. What we did not do: - We did not keep each flag where it is set, because you would then flag every later screen by hand. - We did not let `legacy` carry forward, because a new screen behind an old one would be marked legacy too. For now `legacy` stays where it is set; the question is still open (23.3). ```ujn @startujn journey SHOP "Checkout" view cart { title: "Cart" } view pay_later { title: "Pay later"; flags: [future] } view dates { title: "Choose dates" } view card { title: "Card payment"; flags: [risk] } view paid { title: "Order placed" } cart --> pay_later : [Pay later] pay_later --> dates : [Continue] cart --> card : [Pay by card] card --> paid : [Pay] @endujn ``` Choose dates gets `future` from Pay later, as an outlined tab and a dotted border; Order placed gets nothing from `risk`. ## Everything still reads in black and white Shapes, icons, lines, arrowheads and small symbols carry every meaning, so a black-and-white print says the same as color. For now, two flags with no symbol yet, `legacy` and `needs-updates`, show the letters L and U (23.28). For now: see 23.28. Why: - On paper the eye reliably tells apart only three line styles, so UJN uses just three: solid, dashed and dotted. - On an arrow, each style has one job: solid moves on, dashed goes back or comes back, dotted marks a flag. - An arrow for a failure carries a cross, so it reads as a failure without red. What we did not do: - We did not give each kind of arrow its own line style, because some pairs already looked alike in print. - We did not mark flags with a small badge only, because black-and-white readers would have to find it. ```ujn @startujn render { colors: mono } journey PAY "Pay" view card { title: "Card details"; flags: [legacy] } view wallet { title: "Wallet"; flags: [future] } view declined { type: toast; title: "Card declined" } end paid { title: "Paid" } card --> paid : [Pay] card accepted card -x-> declined : [Pay] card declined declined ..> card card --> wallet : [Use wallet] @endujn ``` In one ink (`render { colors: mono }`), the cross marks the failure, the dashed line goes back, and tabs mark flags. ## Two ids: one to show, one to link A screen or step can show a short display id for people, such as `AUTH-002`, and that id may change. Links use a second, permanent unique id: 11 random hex digits (0 to 9, a to f). You write `unique_id: {{auto}}`, and a tool fills it in once; this must happen before the file's first commit. Why: - Tests, code and requirements link to a screen through its id, so that id must never change. - Ids built from what people edit go wrong: add a screen above, and the shown numbers shift. - The permanent id depends on nothing you edit, so you can rename a screen and links still hold. What we did not do: - We did not build the type into the id, as in `MOD-001`, because a type change would make it wrong. - We did not let links use the shown ids, because those ids move when screens are added. ```ujn @startujn journey AUTH "Sign in" increment { auto; view_prefix: "AUTH" } view login [AUTH-10] { title: "Login"; unique_id: 6f2f4d29ca5 } view forgot { title: "Forgot password"; unique_id: 0b7e3a91c42 } view sent { title: "Check your email" } login --> forgot : [Forgot password] forgot --> sent : [Send link] @endujn ``` The tabs show display ids: `AUTH-10` written by hand, the others numbered in order; unique ids are not drawn. ## A broken rule still draws, with a warning If a journey breaks a rule, UJN still draws it and lists each problem, with its line, underneath. Only a syntax error, such as a line UJN cannot read, stops the drawing. Why: - You see problems as you work, and you can still look at a half-finished journey. - The same warnings go into the file other editors and tools can read, so they need not check again. - One warning is about layout, when an arrow's name has no free spot; it stays out of that file, which does not depend on layout. What we did not do: - We did not refuse to draw a broken journey, because then you could not look at a half-finished one. - We did not leave the checks to a separate tool, because mistakes would show only when someone ran it. ```ujn @startujn journey SIGNUP "Sign up" view email { title: "Your email" } view code { title: "Enter code" } view welcome { title: "Welcome" } email --> code : [Send code] code --> welcome @endujn ``` The arrow into Welcome does not say what the user does (its trigger, in square brackets), yet it is drawn, and the box underneath names line 7.