How syedtanzim/typing-speed-game-burdenoff works
Purpose and entry points
TypeSprint is a full-stack typing-speed game: anonymous users can play locally, while authenticated users persist results, view statistics/history, and compete on a best-time leaderboard. The React SPA starts at frontend/src/main.tsx and composes the application in frontend/src/App.tsx. The Bun GraphQL service starts from backend/index.ts / backend/src/index.ts.
Client application and game loop
The single-page frontend owns the real-time challenge state: generate/display a 20-letter sequence, start timing on first keystroke, advance on correct keys, and add 0.5-second penalties for mistakes. Core UI and game state are concentrated in frontend/src/components/TypingGame.tsx and reusable scoring/game behavior in frontend/src/lib/gameLogic.ts. Completion produces a score; guests retain only session behavior, while signed-in users may submit it.
Client-side composition and API boundary
frontend/src/App.tsx coordinates the game, personal stats, and leaderboard views. frontend/src/context/AuthContext.tsx holds authentication state and JWT persistence; frontend/src/components/Auth.tsx provides register/login interaction. The only backend boundary is GraphQL: frontend/src/api/graphqlClient.ts attaches requests (including authorization), and frontend/src/api/queries.ts defines the operations consumed by game, stats, and leaderboard components.
GraphQL API and request context
The backend exposes a GraphQL Yoga API with schema/resolver logic in backend/src/schema.ts. Server bootstrap in backend/src/index.ts configures the HTTP endpoint, CORS/origin behavior, and request handling. backend/src/context.ts converts the Authorization bearer token into request-scoped authenticated-user context, ensuring game-data operations derive ownership from JWT identity rather than client-provided user IDs.
Authentication and authorization
Account registration and login are API mutations backed by password hashing and JWT issuance/verification in backend/src/utils/auth.ts. The schema uses context authentication to protect me, result saving, personal history, best score, and statistics. This establishes the core trust boundary: the browser stores/sends a JWT, but the server decides which user’s records can be read or written.
Persistence and score-derived views
Prisma connects resolver operations to PostgreSQL through backend/src/prisma.ts, with data models and relationships defined in backend/prisma/schema.prisma. Database evolution is captured in backend/prisma/migrations/20260826144822_init/migration.sql. Completed authenticated games become result rows; personal bests, aggregate stats, and the global leaderboard are derived from those rows at query time, with lowest time ranked first rather than maintained as cached fields.
Runtime and deployment infrastructure
The backend runs on Bun/TypeScript, GraphQL Yoga, Prisma, and PostgreSQL; the frontend runs as a Vite-built React/TypeScript client. Local PostgreSQL is provisioned through docker-compose.yml on host port 5433. Production separates concerns: Vercel hosts the frontend, while Railway hosts the Bun API and managed PostgreSQL, applying Prisma migrations during backend deployment. Environment configuration connects the frontend API URL and backend database, JWT secret, allowed frontend origin, and port.
Main entry points: App.tsx App composition · schema.ts Schema and resolvers · index.ts HTTP server · TypingGame.tsx Typing game
Components 19
React SPA
Vite-built browser application.
- SPA entry
frontend/src/main.tsx - App composition · Coordinates game, stats, and leaderboard views.
frontend/src/App.tsx - Typing game · Owns real-time challenge state and completion.
frontend/src/components/TypingGame.tsx - Game scoring · Generates sequences and calculates timing penalties.
frontend/src/lib/gameLogic.ts - Login and registration
frontend/src/components/Auth.tsx - Auth state and JWT · Persists browser authentication state.
frontend/src/context/AuthContext.tsx - GraphQL client · Sends operations with authorization headers.
frontend/src/api/graphqlClient.ts - GraphQL operations · Game, personal-statistics, and leaderboard operations.
frontend/src/api/queries.ts
Bun GraphQL API
Authenticated game-data service.
- HTTP server · Configures endpoint, CORS, and request handling.
backend/src/index.ts - Schema and resolvers · Serves auth, result, history, statistics, and leaderboard operations.
backend/src/schema.ts - Request auth context · Derives authenticated identity from bearer JWT.
backend/src/context.ts - Credential and JWT service · Hashes passwords and issues or verifies JWTs.
backend/src/utils/auth.ts
Persistence
PostgreSQL-backed result storage.
- Prisma client
backend/src/prisma.ts - Result data model · Defines users, results, and relationships.
backend/prisma/schema.prisma - PostgreSQL · Stores authenticated users and completed-game results.
- Initial migration
backend/prisma/migrations/20260826144822_init/migration.sql
Runtime hosting
- Vercel frontend
- Railway API and database · Runs the Bun API, managed PostgreSQL, and migrations.
- Local PostgreSQL · Exposed locally on host port 5433.
docker-compose.yml
Connections 23
- SPA entry → App composition: mounts
- App composition → Typing game: renders
- Typing game → Game scoring: uses
- App composition → Login and registration: renders
- Login and registration → Auth state and JWT: updates session
- App composition → Auth state and JWT: reads session
- App composition → GraphQL operations: uses
- Typing game → GraphQL client: submits authenticated scores
- GraphQL operations → GraphQL client: executed by
- GraphQL client → HTTP server: GraphQL over HTTP with JWT
- HTTP server → Schema and resolvers: routes requests
- HTTP server → Request auth context: builds context
- Request auth context → Credential and JWT service: verifies bearer token
- Schema and resolvers → Request auth context: authorizes protected operations
- Schema and resolvers → Credential and JWT service: registers and logs in
- Schema and resolvers → Prisma client: reads and writes results · Personal views and lowest-time leaderboard are derived at query time.
- Prisma client → Result data model: maps models
- Prisma client → PostgreSQL: queries
- Initial migration → PostgreSQL: creates schema
- Local PostgreSQL → PostgreSQL: local runtime
- Vercel frontend → SPA entry: hosts build
- Railway API and database → HTTP server: hosts API
- Railway API and database → PostgreSQL: managed database