A guided reading of Rally
Rally is a real app made entirely with Globetrotter: three racket sports (pickleball, badminton, tennis), tournaments, live scoring, sign-in by a six-digit code, a Python backend. This page runs it on your machine, walks ten stops in the code, and ends with three small changes of your own.
Every path below was opened and every command run on a copy of the Rally repository (copied without node_modules, backend/.venv, frontend/.next, .env), on ports other than Rally's own. Paths are relative to the Rally repository. Rally's own docs, in docs/: START-HERE.md (run, stage, prod), using-rally.md (what the app does, tap by tap), STUDIO-WALKTHROUGH.md (the studio on Rally), go-live.md (deploy).
0. Run it (5 minutes)
You do not need the zip: the repository already holds Globetrotter 0.3.0 in vendor/globetrotter/.
cd rally-designer
npm install
(cd frontend && npm install)
npx globetrotter dev --port 3101 --app-port 3120The two installs took about 2 minutes. The first dev took about 45 seconds more: it installs the Python workspace (uv sync), applies the ten migrations to a new local SQLite file, loads the demo data (12 players, 12 tournaments), and creates the development people. You see:
db: applied 0001, 0002, … 0010
db: seeded 0001_demo.sql, 0002_display_names.sql
backend → the development people are in the local database …
backend → http://localhost:8120 (ready; …)
app → http://localhost:3120/g (from frontend/)(If a port is busy, dev says nothing started: … and prints the command with free ports. Changing the ports in globetrotter.config.json instead makes the next doctor fail until you run npx globetrotter sync: the port is written into the generated contract.)
Studio: http://localhost:3101/studio, open rally (the Backend view takes about 6 seconds the first time). App: http://localhost:3120/g.
Sign in. Rally has no password. Open /g/signin, type player@example.com, press Send code. Nothing is emailed locally; the code is written to a file. In a second terminal:
cd backend
uv run python tests/tools/last_code.py player@example.com457875Type it into Six-digit code and press Sign in. You are on "Your games" with the demo tournaments. (The same file, backend/.globetrotter/sent.jsonl, holds every code that was "sent".) Limit: 5 codes per address per hour; the sixth says "Too many codes asked for. Try again in 53 minutes." To clear it while testing: sqlite3 backend/db.sqlite "delete from limit_counter".
The checks, so you know the starting point:
npx globetrotter doctor # ends: everything that can be checked is in sync
(cd backend && uv run pytest -q) # 767 passed in about 2 minutesnpx globetrotter sync --check exits 0 but prints about 17 lines, among them two warnings and "257 notes": Rally was handed over with those open. The pass or fail is doctor.
Ten stops
Stop 1: a simple page and its binding
frontend/src/bindings/rally--welcome.ts(29 lines): the binding of the first-run tour page.frontend/src/generated/rally--welcome.tsx: what the design made (do not edit).- In the studio: Layers → page Welcome.
Look at the binding. It has no data to fetch. It returns { data: { picture }, status: 'ready', actions: { skipTour } }: that is the whole contract of a page, the WelcomeBinding type from rally--welcome.types.ts. The picture follows the chosen sport (useSport()), the action calls endTour(go). Why built like this: everything a page may need is a plain object the page's generated type names, so a binding is as small as the page's needs; the design never contains code.
Stop 2: the shared helpers
frontend/src/bindings/rally--games.ts(600 lines): the page "Games" and, more important, the library every other binding imports from ('./rally--games'is imported by 23 bindings).
Search it for export: useSport (the chosen sport, shared across pages through useSyncExternalStore), pickSport, saveSports, useRead (GET with caching, loading and error states and a reload), send (POST), tournamentRow (turns the service's card into the words a page binds), hasSignedIn, rememberReturn/takeReturn (go back where you were heading after sign-in), endTour. Why built like this: there is no lib/ folder in this project. A binding may import any other; Rally grew its helpers in the busiest binding. If you add a second shared file, nothing stops you; src/bindings/*.ts is yours.
Stop 3: a list that follows a choice
frontend/src/bindings/rally--played-earlier.ts(27 lines).
const sport = useSport(); const read = useRead(/tournaments/earlier?sport=${encodeURIComponent(sport)}): change the sport in the app bar's menu and the page re-reads and redraws, with no code that says "when the sport changes". The choice lives in rally--games.ts (pickSport, line 102): it updates a small store, remembers it in localStorage, tells the backend when you are signed in (/api/players/actions/chooseSport). The list is a design node with repeat; the rows come from tournamentRow(card).
Stop 4: show and hide by data
frontend/src/bindings/rally--host.tsline 148:playNow: { hasGroups: (host?.groups ?? []).length > 0, line: … }.frontend/src/bindings/rally--games.ts,tournamentRow: "What the card shows or hides by data (showWhen): a line that is '' or a flag that is false hides its part."- In the studio: Layers → Host, select the "Pick a group" button (shown when
hasGroups) and then the "Make a group" button (hidden whenhasGroups); the panel says When does it show?
A widget's showWhen / hideWhen is bound to a value; an empty string or false hides it. The card has no if: venueLine is '' for a tournament with no venue, and the venue row is gone. Why built like this: the page's structure stays in the design; the binding only computes values. (This is the same showWhen and hideWhen you used in Tutorial 1.)
Stop 5: a dialog that stays open on a refusal
- Design: page Games, the dialog "Your sports" (
find_nodes({design:"rally", query:"Your sports"}); itsclosesprop isdone). frontend/src/bindings/rally--games.ts:useSportBar(line 186), itssaveSportsaction;saveSports(line 114), which returns the backend's words when it refuses.
Dialog.closes has three values: always (a press that does something closes it at once), done (only when the action went through), never. With done, the action saveSports returns false when the backend refuses (for example, ticking none of the sports), the dialog stays open, and the refusal's words appear in the dialog from sportEdit.error. Try it: in the app, open the sport menu (top right), then Edit sports (it says My sports after exercise 1), and tap each ticked sport to untick it. The count reads "0 of 5", "Pick at least 1 sport." appears, and Save leaves the dialog open. Sixteen dialogs in the design use closes: done (the account's Change email, Delete your account, the final score of a match …).
Stop 6: the scoring page, and how the court gets its players
This is the hardest page. Read it in this order.
- Design: page Match score (
/matches/[id]/score), the blockcourt-grid(four tiles). Each tile bindscourt.tl.player,court.tr.player, … (find_nodes({design:"rally", query:"tl.player"})). frontend/src/bindings/rally--match-score.ts(293 lines). The header comment says it all: the page isScoring.state(matchId), read every 5 seconds (useScoreFeedinrally--match-run.ts, line 100) and replaced by the answer of each rally and undo; presses go to the service one after another; a refusal says the service's sentence and reads the state again.cellOf(line 48) maps one court cell to what a tile shows.- Backend:
backend/packages/rally_impl/src/rally_impl/scoring.py._state(line 183) builds theScoreState; at line 353 it fillstl=_cell(cells[0]), tr=…, bl=…, br=…._cell(line 112) turns a domain cell into theCourtCellof the contract. The positions themselves are the rules of the sport, inbackend/packages/rally_impl/src/rally_impl/domain/pickleball.py(Positions: per side, which player stands in the right and left court),badminton.py,tennis.py. After each rally_mirror(line 80) stores them in the game row (positionsJSON), so a reader of the table sees the board without replaying rallies. - Test:
backend/tests/test_court_positions.py: scripted games for every sport and discipline, checked after every rally ("each side keeps its end, a side-out moves nobody …").
The frontend contains no court logic. The server decides where each player stands; the page draws four tiles. Why built like this: the rules of three sports are hard to get right, so they live in Python, in pure functions, with tests; the page cannot disagree with them.
Stop 7: the service design
designs/rally.service.json(the source of the whole backend).- In the studio: Backend → Overview (the entities as a diagram), Services (ten services, 83 operations), Entities, Permissions.
Read it in the studio first. auth says types: session (30 days, stored) and code (signUp pending, entity player, ask at sign-up: handle), roles: player, admin. Each operation says its kind (Query reads, Command changes), what it writes, its params, its refuses (declared refusals: "That handle is taken."), and who may run it (an allow names the lowest role). In your terminal, the same thing as text:
node_modules/.bin/globetrotter status # per page and for the backendor the agent tool service_session({ design: "rally" }), which prints sign-in and roles, every entity with its rules, and every operation.
Stop 8: a rule in rally_impl, and its test
backend/packages/rally_impl/src/rally_impl/matches.py,dispute(line 354): who may dispute a result, what a result must be to be disputed, thenassert_dispute_open(await dispute_is_open(ctx, info)).backend/packages/rally_impl/src/rally_impl/_match_result.py,dispute_is_open(line 529): a result can be disputed until the next match it decides has started, or for a pool result until the playoff is seeded or 24 hours pass.- The refusal
DisputeClosedis declared indesigns/rally.service.json("id": "dispute-closed", 409, "This result can no longer be disputed. Ask the organiser to correct it.") and generated intobackend/packages/rally_core/src/rally_core/errors.py. - Test:
backend/tests/test_flow_rules.py,test_a_result_can_no_longer_be_disputed_a_day_later_or_once_the_next_match_has_started(line 1060): signs in as an organiser and a player with theas_rolefixture, makes a tournament, plays a match, moves the clock in SQL, and asserts the 409 and its exact words.
This is Tutorial 2's pattern at scale: the design says the words and the status, the impl says when, the test presses the real app.
Stop 9: sign-in by code
- Design:
auth.typesindesigns/rally.service.json:{"kind":"code","signUp":"pending","entity":"player","askAtSignUp":"handle"}. - Generated:
backend/packages/rally_core/src/rally_core/codes.py(a code is kept only as an HMAC, tried 5 times, 10 minutes, limited to 5 an hour per address) andaccounts.py. - Yours:
backend/packages/rally_impl/src/rally_impl/auth.py(97 lines: development people, the sign-up check, what happens after sign-up) and the strategy list inwiring.py. - Pages:
frontend/src/bindings/rally--sign-in.ts(200 lines) andrally--check-your-email.ts(134). - Test:
backend/tests/test_code_signin.py("pressed as a person does: ask for a code, read it from the file the console adapter keeps"). - Locally: codes go to
backend/.globetrotter/sent.jsonl;backend/tests/tools/last_code.pyreads the newest. On stage and prod, mail goes by SMTP; Rally'sdocs/go-live.mdsection 5 and 8.
Stop 10: the stage deploy files
globetrotter.config.json: thedeploykey (host, project, url, backendUrl): written byglobetrotter deploy, which puts the pages on Cloudflare Pages.backend/fly.stage.tomlandfly.prod.toml: the backend on Fly.io, written once by the tool and then yours. EveryYOUR_…value must be replaced before the first deploy: the backend refuses to start while one is left (the message is in05-when-it-goes-wrong.md).backend/Dockerfile,backend/compose.yaml.designs/components.stage.json,components.prod.json: which database each environment uses ({secret:RALLY_DB_URL}).scripts/stage-secrets.sh(hidden prompts, five secrets intofly secrets import) andscripts/stage-seed.sh(demo data into stage only; prod is refused).docs/go-live.md: the whole sequence with its commands,docs/environments.mdwhat differs by environment.
Not proven here: Rally's START-HERE.md (written 30 November) says Fly, Neon, Resend and Cloudflare "have never been touched from this project" and the Docker image was never built; globetrotter.config.json now records a deploy of rally-stage on 3 December. Ask the owner what stage looks like today before you rely on any of it.
Your first change to Rally
Do these on a branch: git switch -c first-changes. Each ends with the checks. All three were run on a copy.
Exercise 1: change a word everywhere (10 minutes)
The sport menu has an item "Edit sports", on four pages. Rename it "My sports" on all of them.
Studio: Words tab (every text of every page, grouped by page; Copy sheet and Paste sheet take them all at once). From a terminal, the sheet of the whole app:
npx globetrotter words rally --out /tmp/words.tsv1008 texts → /tmp/words.tsv; edit the Words column, then globetrotter words rally --apply …Edit it (the Words column is the fourth; the sheet is tab-separated):
perl -pi -e 's/\tEdit sports\t/\tMy sports\t/' /tmp/words.tsv
npx globetrotter words rally --apply /tmp/words.tsv --dry Games · Menu item text: “Edit sports” → “My sports”
Find · Menu item text: “Edit sports” → “My sports”
Host · Menu item text: “Edit sports” → “My sports”
People · Menu item text: “Edit sports” → “My sports”
Would change 4 texts in rally; run it without --dry to write them.Then without --dry: Changed 4 texts in rally; 4 page files regenerated. An agent does it in one call: replace_text({ design: "rally", find: "Edit sports", replace: "My sports" }) (answers replaced: 4).
Expected: in the app, open the sport menu: the last item says "My sports". Checks:
npx globetrotter doctor
git status --short # designs/rally.design.json and four frontend/src/generated/rally--*.tsx fileswords --check prints Rally's older findings (apostrophes, a full stop on a label): not yours. Search first: a word also appears in bindings and docs (grep -rn "Edit sports" frontend/src/bindings docs): the Words tool changes the design's words only; those are comments.
Exercise 2: a field on a tournament, shown on the card (30 to 45 minutes)
Add a note ("Bring a spare ball") to a tournament and show it on the Games page's card. This crosses every layer once, and it is the exercise to do if you do one.
The field. The entity is
tournament; the shape the card uses isTournamentCard.add_service_node({ design: "rally", type: "Field", target: { parent: "tournament", slot: "fields" }, props: { name: "note", type: "string", required: false, max: 120, message: "Keep the note under 120 characters." } }) add_service_node({ design: "rally", type: "Part", target: { parent: "tournament-card", slot: "parts" }, props: { name: "note", type: "string", required: false } })(Studio: Backend → Entities, the
tournamentcard, + Field; Backend → Services → Shapes for the part.)The migration:
npx globetrotter syncIt writes
backend/migrations/db/sqlite/0011_add_tournament_note.sqland its Postgres twin:ALTER TABLE "tournament" ADD COLUMN "note" TEXT;. Read them; then apply:cd backend && GLOBETROTTER_ENV=local uv run python -m rally_core.migrate(it saysdb: up to date, nothing to applyifdevalready applied it).The backend fills the card: in
backend/packages/rally_impl/src/rally_impl/_tournament_data.py, in themk(m.TournamentCard, …)call (around line 790), addnote=t.note,aftervenue_address=t.venue_address,.The frontend binding. In
frontend/src/bindings/rally--games.ts, addnote?: string;to theTournamentCardtype (line 474, besidemapUrl?), and intournamentRowaddnoteLine: card.note ?? '',aftermapUrl: card.mapUrl ?? '',. Then(cd frontend && npx tsc --noEmit).The page. The card on the "Playing" tab of Games has a row for the venue (a Stack with
showWhenbound toitem.venueLine). Add a text under it:add_node({ design: "rally", page: "Games", target: { kind: "slot", parentId: "n-stack-0f7gtt", slot: "children" }, index: 6, type: "Text", props: { text: { "$bind": "item.noteLine", "sample": "Bring a spare ball" }, variant: "bodyMedium", showWhen: { "$bind": "item.noteLine", "sample": "Bring a spare ball" } } })n-stack-0f7gttis the Stack that holds the card's rows in this repository today; if it is gone,find_nodes({ design: "rally", query: "item.venueLine" })lists the venue rows andget_nodeon one shows its parent (the id is in the outline fromget_page).Give one tournament a note and look:
sqlite3 backend/db.sqlite "update tournament set note='Bring a spare ball' where name='Wednesday club ladder'"Open
/gsigned in: the card of "Wednesday club ladder" shows "Bring a spare ball" between the venue and the entries line.
The Games page: the first card shows the note under the venue
Checks: npx globetrotter sync, npx globetrotter doctor (everything in sync), (cd frontend && npx tsc --noEmit), cd backend && uv run pytest -q (767 passed).
Two things you will learn here. The same card is drawn in eight places (four on Games, two on Find, two on Host, one on Played earlier: find_nodes({ design: "rally", query: "item.venueLine" })), and they are copies, not one block: this exercise edits one. Doing the others is the stretch. And the note has no form yet: to set it from the app, add a note param to the operation that updates a tournament (Tournaments service) and a field on the "Setup about" page; the same recipe as Tutorial 1, one level deeper.
Exercise 3: a small backend rule with a test (15 minutes)
A tournament that has all its places should say so. In backend/packages/rally_impl/src/rally_impl/_tournament_words.py the function entered_line(entered, cap, unit) writes "5 of 8 players". Make a full one say "8 of 8 players · full".
Change the if cap: branch to:
if cap:
full = " · full" if entered >= cap else ""
return f"{entered} of {cap} {unit}{full}"The test, backend/tests/test_words_full.py:
"""A tournament that has all its places says so: "8 of 8 players · full"."""
from rally_impl import _tournament_words as w
def test_a_full_tournament_says_full():
assert w.entered_line(8, 8, "players") == "8 of 8 players · full"
assert w.entered_line(4, 4, "teams") == "4 of 4 teams · full"
def test_one_with_room_does_not():
assert w.entered_line(7, 8, "players") == "7 of 8 players"
assert w.entered_line(3, None, "players") == "3 players"cd backend
uv run pytest -q tests/test_words_full.py tests/test_flow_a13.py..................... [100%]
21 passed in 4.66s(tests/test_flow_a13.py already tests the same function for the unfull cases; it is the test that would have caught a mistake.) Then the whole suite, and the checks:
uv run pytest -q # 767 passed before your change; yours adds two
cd .. && npx globetrotter doctorThe tool also holds your Python to ruff format; doctor names the file and line if you wrote something it would change, and cd backend && uv run ruff format . fixes it. Expected in the app: a tournament with every place taken says "8 of 8 players · full" on its card.
Where to go next
Make a change of your own and let doctor tell you what else it touched. When you want a thing done and do not know how: 04-recipes.md. When something fails: 05-when-it-goes-wrong.md.