Skip to content

Architecture: games and the Homefelt platform

Homefelt is a suite of card and board games; Canasta is the first. Today each game ships as its own app on iPhone, Android and the web. This page sets the boundary that keeps a later single Homefelt app, hosting several games, a matter of adding a shell instead of untangling code. Read it when adding a game or an app-level feature.

At a glance

For the whole system on one page (the clients, the server’s modules, a move end to end, and what is built, planned and still to come), see the architecture map.

One spec, three cores. spec/ pins the rules; the Swift, Kotlin and Rust cores each pass it, and the behaviour suite tests every platform’s CLI, and the Wasm module, the same way. The Rust engine also runs the game server and, compiled to WebAssembly, the web game.

flowchart LR
  accTitle: The spec feeds every platform
  accDescr: spec/ pins the Swift, Kotlin and Rust cores. Each core has a CLI, and the behaviour suite tests every CLI and the Wasm module the same way. The Swift and Kotlin cores run the iPhone and Android apps; the Rust rules run the game server and, as canasta-wasm, the web game.
  spec[("spec/<br/>rule sets, scenarios,<br/>parity, saves, protocols")]
  subgraph swiftp [Swift]
    swift[CanastaCore] --> swiftcli[Swift CLI] & ios[iPhone app]
  end
  subgraph kotlinp [Kotlin]
    kotlin[kotlin/core] --> kotlincli[Kotlin CLI] & android[Android app]
  end
  subgraph rustp [Rust]
    rust[canasta-rules] --> rustcli[Rust CLI] & server[canasta-server] & wasm[canasta-wasm]
    wasm --> web[web/: the browser game]
  end
  spec --> swift & kotlin & rust
  behaviour[[spec/behaviour:<br/>one suite for all]]
  swiftcli & kotlincli & rustcli & wasm -. tested by .-> behaviour

Game and platform: a game’s core and UI are named for the game and know nothing of sign-in, settings or storage; the platform, named for Homefelt, owns those and hosts the games.

flowchart TB
  accTitle: Game and platform
  accDescr: The game side holds the game core and the game UI, pinned by spec/. The platform side holds sign-in and the server client, theme and display settings, saved-game storage, the web home with the game registry and routes, and the server's accounts, groups and invites. The UI sends actions to the core and gets state back; it reads platform settings but never owns them.
  spec[(spec/)]
  subgraph game [Game: named for the game, Canasta]
    core[Game core<br/>rules, state, update, bots,<br/>saved-game format]
    ui[Game UI<br/>table, hand, action bar,<br/>refusals, scores]
  end
  subgraph platform [Platform: shared, named for Homefelt]
    signin[Sign-in and<br/>the server client]
    settings[Theme and display<br/>settings]
    storage[Saved-game storage<br/>per-game keys]
    shell[Web home, game<br/>registry and routes]
    accounts[Server: accounts, groups,<br/>friends, invites, sessions]
  end
  spec -- pins --> core
  ui -- actions in --> core
  core -- state out --> ui
  shell -- loads lazily --> ui
  ui -. reads, never owns .-> settings
  ui -. online tables .-> signin
  core -- save --> storage

Game and platform

Lives in Today
Game core: rules, state, update, bots, saved-game format one core per platform, named for the game CanastaCore, kotlin/core (canasta.core), canasta-rules, canasta-wasm; spec/ pins them
Cards: decks, card codes, parse and format, PCG32, the shuffle one game-agnostic module per platform, named for Homefelt HomefeltCards (Swift target in the CanastaCore package), kotlin/cards (homefelt.cards), homefelt-cards; spec/decks/ pins them
Game UI: table, hand, action bar, refusals, scores the game’s UI module swift/App/Sources, kotlin/app (canasta.app), web/src outside online/
Platform: sign-in, the server client, theme and display settings, saved-game storage, the store, analytics shared code, named for Homefelt sign-in and the server client in web/src/online and canasta-server; the web home, game registry and routes (web/src/Home.tsx, games.ts, routes.ts); theme from design/tokens.json (bin/gen-theme); homefelt.settings; the store and analytics are not built yet

Names follow the side: game code keeps the game’s name (Canasta*, canasta-*), platform names say Homefelt (HOMEFELT_* server settings, the homefelt_refresh cookie, the homefelt token issuer, the homefelt_dev database, bundle ids under dev.edsancha.homefelt).

The cards module is the first shared, game-agnostic piece: it knows decks (spec/decks/*.json: french, spanish-40, spanish-48) and cards, never a game’s rules. Each game declares the decks it is played with in spec/games/<id>.json (Canasta: french only, in CanastaGame), and a rule set’s deck must be one of them. A game core depends on the cards module; the cards module depends on nothing.

Rules that keep bundling possible

  • No app-global state named for one game. Settings, sign-in and the session belong to the platform; a game reads them and never owns them.
  • Per-game storage namespaces. Shared settings under homefelt., a game’s own data under homefelt.<game>. (the web’s homefelt.canasta.savedGame.v1, web/src/storageKeys.ts). The native apps keep one saved-game.json in their own sandbox, which is per game while each game is its own app; a shared app moves it to <game>/saved-game.json.
  • Per-game routes on the web. Each game lives under its own path on play.homefelt.io (/canasta), listed once in the game registry; the platform owns /, /online, /join/* and /table/* (“Web routes” below). The marketing site links each game’s Play button there.
  • Server protocol and tables. One server serves one game today: tables, seats, game_snapshots, game_results and hand_results hold Canasta games, and the WebSocket messages are Canasta’s (spec/protocol/server.md). Accounts, groups, friends, invites and sessions are platform data. The game id is already in the protocol (decision 0016, #254): tables.game (canasta by default), game on POST /tables (unknown ids refused with unknownGame), in the table message, on GET /me/tables and on every invite answer. The server checks it against a fixed list (rust/canasta-server/src/games.rs) and never loads a table of a game it does not run. Future work, once a second game exists (not now): choosing the rules engine, the snapshots’ and results’ shape, and the WebSocket messages by that id.

Web routes

Path on play.homefelt.io Shows
/ the Homefelt home: a card per game (Play, and How it plays on the site), your online tables across games when signed in, and the display settings every game shares
/canasta and its subpaths Canasta on this device: new game, Continue game, the table
/online the shared sign-in and lobby (your tables, join with a code, a new table)
/join/*, /table/* invites and tables, unchanged URLs, each sent to its table’s game
anything else a not-found page linking home
  • The registry (web/src/games.ts): one entry per game, with its id, name, path, one-line description, rules URL on the site (VITE_SITE_URL, default https://homefelt.io) and a lazy load() for its UI and engine. The home page and the router (web/src/routes.ts) read it; nothing else names a game’s path.
  • Dispatch. The URL carries no game, so /join/* and /table/* open with openingTableGame (Canasta, the only game so far). From then on the server’s game decides, through gameForTable(route, game), strictly (an answer that names none counts as unknown): a redeem or an approved join request opens the table only if this app has its game, a listed table of another game says to update the app, and the table message ends the connection with unknownGame rather than showing the table as another game. A saved table whose game the server no longer runs is refused at the hello with a final unknownGame, which the client does not retry. The online lobby loads Canasta too, since its New table form lists Canasta’s rule sets.
  • Lazy engines. A game’s UI and Wasm engine load with dynamic import() only on its pages (its path, its tables and invites, the lobby), so / fetches no .wasm.
  • Game two: the router loads the engine the table’s game names (a /table or /join URL learns it from GET /me/tables or the invite answer before loading), and /online offers a game per new table; the URLs stay as they are.

What one Homefelt app would change

  • A shell app with a game picker, owning sign-in, settings, the server client, the store and analytics, and embedding each game’s core and UI module (a Swift package target, a Gradle module, a route subtree on the web).
  • Bundle ids. Each game is dev.edsancha.homefelt.<game> today (iOS and Android; store name “Homefelt Canasta”, home-screen name “Canasta”). A shell either keeps one app per game beside it or moves to dev.edsancha.homefelt; Sign in with Apple then needs that App ID listed in HOMEFELT_APPLE_BUNDLE_ID or HOMEFELT_APPLE_SERVICE_IDS, and saved games move into the shell’s sandbox.
  • The server already carries the game id above; nothing else in the platform tables has to move.

Keeping the map current

The architecture map shows what is built, in progress, planned and future, so it goes stale with every merge unless each pull request moves its own boxes. It is written by hand; nothing generates it.

Every pull request asks one question: does this change what the map or this page says? If so, the same pull request updates them. It does when the change:

  • adds, removes, renames or moves a module, crate, target, screen group, route, endpoint, WebSocket message, database table, side-effect interface, or hosted service;
  • changes a status: it starts something the map shows as planned (mark it in progress, with the issue and pull request), or finishes it (mark it built, and drop the issue number);
  • records a decision that picks, drops or reorders something on the map, or answers one of its proposals;
  • changes a number the map states: a limit, a count in spec/, a region, a machine size.

It does not for a rule change inside a core, a scenario, a bug fix, a string, a style, or a dependency bump: most checkpoints leave the map alone.

How to update it:

  • A box’s status is its class: built, progress, planned or future on a .mod in the layer maps, b-progress, b-planned or b-future on a .box in the SVG diagrams (with the matching dot- circle). Keep the issue number in the box’s small text while it is not built.
  • Move the item between the columns of the board in section 06, and keep sections 04 and 05 on the same rows: a module added to one client gets a box, built or planned, in the other two.
  • A decision goes in section 08, with the issue that carries it. A proposal that was decided keeps its card, tagged “decided”.
  • Update the line under the title: the date, the commit on main the pull request starts from, and the highest issue number.
  • Update the diagrams and tables on this page too when the boundary between game and platform moves.
  • Run bin/test docs, and say in the pull request which boxes moved.

A pull request that needs no update says so in its body, in one line. When the map and the code disagree, the code is right: fix the map in the pull request that noticed, or open an issue.

Why these boundaries were chosen: decision records, 0001, 0006 to 0008.