# syedtanzim/typing-speed-game-burdenoff architecture

> Architecture diagram of the GitHub repository syedtanzim/typing-speed-game-burdenoff, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/syedtanzim/typing-speed-game-burdenoff
- Repository: https://github.com/syedtanzim/typing-speed-game-burdenoff

## Overview

#### 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: [`frontend/src/App.tsx`](https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/frontend/src/App.tsx) (App composition), [`backend/src/schema.ts`](https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/backend/src/schema.ts) (Schema and resolvers), [`backend/src/index.ts`](https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/backend/src/index.ts) (HTTP server), [`frontend/src/components/TypingGame.tsx`](https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/frontend/src/components/TypingGame.tsx) (Typing game)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["React SPA"]
  node_client_entry["SPA entry<br/>React entry<br/>[main.tsx]"]
  node_app["App composition<br/>React shell<br/>[App.tsx]"]
  node_typing_game["Typing game<br/>game UI<br/>[TypingGame.tsx]"]
  node_game_logic["Game scoring<br/>game logic<br/>[gameLogic.ts]"]
  node_auth_ui["Login and registration<br/>auth UI<br/>[Auth.tsx]"]
  node_auth_state["Auth state and JWT<br/>React context<br/>[AuthContext.tsx]"]
  node_graphql_client["GraphQL client<br/>API client<br/>[graphqlClient.ts]"]
  node_operations["GraphQL operations<br/>operation definitions<br/>[queries.ts]"]
end

subgraph group_backend["Bun GraphQL API"]
  node_api_bootstrap["HTTP server<br/>Bun / Yoga bootstrap<br/>[index.ts]"]
  node_schema["Schema and resolvers<br/>GraphQL API<br/>[schema.ts]"]
  node_request_context{{"Request auth context<br/>authorization boundary<br/>[context.ts]"}}
  node_auth_service["Credential and JWT service<br/>auth utility<br/>[auth.ts]"]
end

subgraph group_data["Persistence"]
  node_prisma["Prisma client<br/>data access<br/>[prisma.ts]"]
  node_data_model["Result data model<br/>Prisma schema<br/>[schema.prisma]"]
  node_postgres[("PostgreSQL<br/>database")]
  node_migrations["Initial migration<br/>database migration<br/>[migration.sql]"]
end

subgraph group_deployment["Runtime hosting"]
  node_vercel["Vercel frontend<br/>production host"]
  node_railway["Railway API and database<br/>production host"]
  node_local_postgres[("Local PostgreSQL<br/>Docker service<br/>[docker-compose.yml]")]
end

node_client_entry -->|"mounts"| node_app
node_app -->|"renders"| node_typing_game
node_typing_game -->|"uses"| node_game_logic
node_app -->|"renders"| node_auth_ui
node_auth_ui -->|"updates session"| node_auth_state
node_app -->|"reads session"| node_auth_state
node_app -->|"uses"| node_operations
node_typing_game -->|"submits authenticated scores"| node_graphql_client
node_operations -->|"executed by"| node_graphql_client
node_graphql_client -->|"GraphQL over HTTP with JWT"| node_api_bootstrap
node_api_bootstrap -->|"routes requests"| node_schema
node_api_bootstrap -->|"builds context"| node_request_context
node_request_context -->|"verifies bearer token"| node_auth_service
node_schema -->|"authorizes protected operations"| node_request_context
node_schema -->|"registers and logs in"| node_auth_service
node_schema -->|"reads and writes results"| node_prisma
node_prisma -->|"maps models"| node_data_model
node_prisma -->|"queries"| node_postgres
node_migrations -->|"creates schema"| node_postgres
node_local_postgres -.->|"local runtime"| node_postgres
node_vercel -.->|"hosts build"| node_client_entry
node_railway -.->|"hosts API"| node_api_bootstrap
node_railway -.->|"managed database"| node_postgres

click node_client_entry "https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/frontend/src/main.tsx"
click node_app "https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/frontend/src/App.tsx"
click node_typing_game "https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/frontend/src/components/TypingGame.tsx"
click node_game_logic "https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/frontend/src/lib/gameLogic.ts"
click node_auth_ui "https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/frontend/src/components/Auth.tsx"
click node_auth_state "https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/frontend/src/context/AuthContext.tsx"
click node_graphql_client "https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/frontend/src/api/graphqlClient.ts"
click node_operations "https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/frontend/src/api/queries.ts"
click node_api_bootstrap "https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/backend/src/index.ts"
click node_schema "https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/backend/src/schema.ts"
click node_request_context "https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/backend/src/context.ts"
click node_auth_service "https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/backend/src/utils/auth.ts"
click node_prisma "https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/backend/src/prisma.ts"
click node_data_model "https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/backend/prisma/schema.prisma"
click node_migrations "https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/backend/prisma/migrations/20260826144822_init/migration.sql"
click node_local_postgres "https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/docker-compose.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_client_entry,node_app,node_typing_game,node_game_logic,node_auth_ui,node_auth_state,node_graphql_client,node_operations toneBlue
class node_api_bootstrap,node_schema,node_request_context,node_auth_service toneAmber
class node_prisma,node_data_model,node_postgres,node_migrations toneMint
class node_vercel,node_railway,node_local_postgres toneRose
```

## Components

### React SPA

Vite-built browser application.

- [SPA entry](https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/frontend/src/main.tsx): React entry · `frontend/src/main.tsx`
- [App composition](https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/frontend/src/App.tsx): React shell · Coordinates game, stats, and leaderboard views. · `frontend/src/App.tsx`
- [Typing game](https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/frontend/src/components/TypingGame.tsx): game UI · Owns real-time challenge state and completion. · `frontend/src/components/TypingGame.tsx`
- [Game scoring](https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/frontend/src/lib/gameLogic.ts): game logic · Generates sequences and calculates timing penalties. · `frontend/src/lib/gameLogic.ts`
- [Login and registration](https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/frontend/src/components/Auth.tsx): auth UI · `frontend/src/components/Auth.tsx`
- [Auth state and JWT](https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/frontend/src/context/AuthContext.tsx): React context · Persists browser authentication state. · `frontend/src/context/AuthContext.tsx`
- [GraphQL client](https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/frontend/src/api/graphqlClient.ts): API client · Sends operations with authorization headers. · `frontend/src/api/graphqlClient.ts`
- [GraphQL operations](https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/frontend/src/api/queries.ts): operation definitions · Game, personal-statistics, and leaderboard operations. · `frontend/src/api/queries.ts`

### Bun GraphQL API

Authenticated game-data service.

- [HTTP server](https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/backend/src/index.ts): Bun / Yoga bootstrap · Configures endpoint, CORS, and request handling. · `backend/src/index.ts`
- [Schema and resolvers](https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/backend/src/schema.ts): GraphQL API · Serves auth, result, history, statistics, and leaderboard operations. · `backend/src/schema.ts`
- [Request auth context](https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/backend/src/context.ts): authorization boundary · Derives authenticated identity from bearer JWT. · `backend/src/context.ts`
- [Credential and JWT service](https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/backend/src/utils/auth.ts): auth utility · Hashes passwords and issues or verifies JWTs. · `backend/src/utils/auth.ts`

### Persistence

PostgreSQL-backed result storage.

- [Prisma client](https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/backend/src/prisma.ts): data access · `backend/src/prisma.ts`
- [Result data model](https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/backend/prisma/schema.prisma): Prisma schema · Defines users, results, and relationships. · `backend/prisma/schema.prisma`
- **PostgreSQL**: database · Stores authenticated users and completed-game results.
- [Initial migration](https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/backend/prisma/migrations/20260826144822_init/migration.sql): database migration · `backend/prisma/migrations/20260826144822_init/migration.sql`

### Runtime hosting

- **Vercel frontend**: production host
- **Railway API and database**: production host · Runs the Bun API, managed PostgreSQL, and migrations.
- [Local PostgreSQL](https://github.com/syedtanzim/typing-speed-game-burdenoff/blob/main/docker-compose.yml): Docker service · Exposed locally on host port 5433. · `docker-compose.yml`

## Connections

- 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
