How clxxiii/osu-bingo works
1. Overall shape
- This is a SvelteKit application written in TypeScript, built and run with Bun.
- It is not just a frontend: the repo contains the web UI, API endpoints, server-side game logic, database access, and background/game-stream integration for osu! Bingo.
2. Primary user-facing surfaces
- The app is split into route groups:
- (main): the core product UI for games, templates, login, and the home page.
- (overlays): stream-overlay pages, especially the board overlay.
- (api): backend endpoints for auth, game stream control, and utility calls.
- The UI is mostly composed from reusable Svelte components under src/lib/components, which act as the presentation layer for cards, lists, chat, timers, boards, settings, and overlays.
3. Core domain model
- The central domain is osu! Bingo game management: games, templates, maps, squares, teams, scores, events, chat, users, sessions, and tokens.
- The README’s gameplay loop is implemented around claiming squares on a bingo board, reclaiming them with better scores, and winning by completing lines.
- Board presets are explicit in src/lib/bingo-helpers/boards for 3x3, 5x5, and 7x7 boards, with helper logic for win detection and “claimworthy” checks.
4. Game rules and claim logic
- src/lib/bingo-helpers and src/lib/gamerules contain the rule engine for:
- evaluating whether a score can claim/reclaim a square,
- computing the best score,
- checking wins,
- deriving rule meaning/options.
- This is the core gameplay boundary: the UI displays state, but these helpers determine the actual game outcomes.
5. Persistence layer
- The data layer is built on Drizzle ORM with schema and migrations under src/lib/drizzle.
- Query modules are split by domain:
- user, session, token
- game, gameuser, square, score
- map, mappool, template
- event, chat
- This separation implies a service/repository boundary where route handlers and server services call domain-specific query modules rather than touching SQL directly.
6. Auth and session flow
- Authentication is centered on osu! account login via API routes under src/routes/(api)/auth/....
- The app stores and reads login/session state server-side through the session and token data modules.
- src/routes/(api)/login_request suggests a login-request handoff flow, likely used to coordinate browser login state with server-side auth/session creation.
7. Live game ingestion and updates
- The live gameplay pipeline is handled by src/lib/server/game and related endpoints:
- start/final-call/rule-change/update-score/watch logic,
- automatic deletion and state management.
- src/routes/(api)/game_stream and its subroutes for channel/game changes indicate a live stream of game state into the UI.
- src/lib/emitter suggests an internal publish/update mechanism, while src/lib/server/rabbit.ts indicates a queue/messaging integration for asynchronous coordination.
8. External osu! integration
- The server has a dedicated osu integration layer in src/lib/server/osu.ts, plus Bancho-specific support in src/lib/server/bancho.
- The README confirms scores can come from osu!stable and osu!lazer, so the backend likely normalizes multiple score sources before applying bingo rules.
- bancho_board.ts points to an integration boundary with osu! chat/lobby or match events, which is probably how live game activity is observed or controlled.
9. Polling and scheduling
- src/lib/server/polling contains an event scheduler and token handling, which suggests periodic background work for:
- refreshing game state,
- syncing external data,
- managing expiring tokens or timed game events.
- This is a separate operational path from the request/response routes: the app has both interactive HTTP flows and scheduled/background updates.
10. Streaming overlays
- The (overlays) route group is a distinct read-only presentation layer for live broadcast use.
- The board overlay page likely consumes the same game state as the main UI but presents it in a minimal, stream-friendly format that updates as the game progresses.
- This is an important boundary: overlay pages depend on the same game data model, but are optimized for display rather than control.
11. Route-level responsibilities
- (main) pages handle the normal product experience: home, game detail, game list, templates, and creation flows.
- API routes handle stateful operations like login/logout, game stream control, retrieving a user’s game, and closing login requests.
- The application uses SvelteKit server-side load/actions heavily, so many state transitions happen on the server rather than in a separate backend service.
12. Shared UI and app shell
- src/lib/components acts as a shared design system for the entire app: navigation, cards, lists, chat, timers, controls, board rendering, and game summaries.
- src/routes/(main)/+layout.* and src/routes/+layout.server.ts define the application shell and server-provided global state.
- src/hooks.server.ts is the top-level request hook boundary for cross-cutting server concerns such as auth, redirects, or request context.
13. Operational/deployment context
- The presence of Dockerfile, docker-compose.yml, and GitHub Actions workflows shows the app is containerized and CI-tested.
- Drizzle migrations are committed, so database schema evolution is part of the deployment workflow.
- Overall, this repo is a stateful, server-driven game platform with a live-update architecture: database as source of truth, server game logic as the arbiter, and SvelteKit pages/components as the presentation layer.
Main entry points: game Game service · queries Queries · (api) API routes · auth Auth flow
Components 20
Presentation
SvelteKit pages and shared UI components.
- Main app · Core product pages for games, templates, login, and home.
src/routes/(main) - Board overlay · Read-only stream overlay for the bingo board.
src/routes/(overlays)/overlays/board - UI kit · Shared presentation layer for cards, lists, timers, chat, boards, and controls.
src/lib/components
API
HTTP endpoints for auth, game stream control, and lookups.
- API routes · Backend endpoints for auth, game streaming, and utility calls.
src/routes/(api) - Auth flow · osu login, callback, logout, and auth state endpoints.
src/routes/(api)/auth - Game stream · Live game channel/game selection endpoints.
src/routes/(api)/game_stream - Login request · Hand-off endpoint for login request coordination.
src/routes/(api)/login_request/+server.ts - User game lookup · Fetches the active game for a user.
src/routes/(api)/get_user_game/+server.ts
Domain
Game rules and state-transition logic.
- Bingo helpers · Claim/reclaim evaluation, win checks, and board utilities.
src/lib/bingo-helpers - Rule engine · Rule meaning and option derivation for gameplay behavior.
src/lib/gamerules
Server
Runtime services that coordinate live games and external integrations.
- Game service · Starts games, updates scores, applies rule changes, watches state, and handles deletion.
src/lib/server/game - Bancho bridge · Bancho-specific match/chat integration for live game events.
src/lib/server/bancho - osu client · Server-side integration with osu account and score data.
src/lib/server/osu.ts - Polling jobs · Scheduled event syncing and token management.
src/lib/server/polling - Emitter · Internal update propagation and server-side event emission.
src/lib/emitter
Data
Drizzle schema, migrations, and query modules.
- Schema · Drizzle schema definitions and relations.
src/lib/drizzle/schema.ts - Queries · Domain-specific query modules for users, games, scores, maps, events, and chat.
src/lib/drizzle/queries - Migrations · Committed schema evolution for deployment.
src/lib/drizzle/migrations
Platform
App shell and request-level cross-cutting hooks.
- Request hooks · Top-level request context, auth, and redirect boundary.
src/hooks.server.ts - App state · Global server-provided state for the application shell.
src/routes/+layout.server.ts
Connections 24
- Main app → UI kit: renders with · Main pages compose the shared UI kit.
- Board overlay → UI kit: uses · Overlay page reuses board and display components.
- Main app → App state: loads state · Main route group receives global layout data.
- API routes → Auth flow: contains · Auth-related API routes live under the API group.
- API routes → Game stream: contains · Game stream control endpoints live under the API group.
- API routes → Login request: contains · Login request handoff endpoint is part of API surface.
- API routes → User game lookup: contains · User-game lookup endpoint is part of API surface.
- Auth flow → osu client: authenticates via · Login and callback flow depends on osu integration.
- Auth flow → Queries: persists sessions · Auth flow reads and writes session/token state.
- Game stream → Game service: controls · Stream endpoints manipulate live game state.
- User game lookup → Queries: reads · Lookup endpoint queries game ownership/state.
- Game service → Bingo helpers: applies rules · Game service uses claim and win helpers.
- Game service → Rule engine: evaluates rules · Live game service consults rule meaning/options.
- Game service → Queries: reads/writes · Game service persists games, squares, scores, events, and chat.
- Game service → Emitter: publishes · Game changes are emitted for downstream consumers.
- Game service → Bancho bridge: ingests · Game service receives Bancho-driven events.
- Bancho bridge → osu client: depends on · Bancho bridge normalizes osu-side data and identities.
- Polling jobs → osu client: syncs with · Background jobs refresh external osu data and tokens.
- Polling jobs → Queries: updates · Polling jobs persist scheduled state and token changes.
- Emitter → Game stream: feeds updates · Emitter supports live game-stream propagation to clients.
- Queries → Schema: built on · Query modules operate over the shared schema.
- Queries → Migrations: evolves with · Query layer tracks the committed migration history.
- Request hooks → App state: initializes · Request hook sets up context used by the app shell.
- Request hooks → API routes: guards · Cross-cutting server logic applies to API requests.