# pacomariano28/songuess architecture

> Architecture diagram of the GitHub repository pacomariano28/songuess, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pacomariano28/songuess
- Repository: https://github.com/pacomariano28/songuess

## Overview

Songuess is a browser-based, real-time music-trivia game. Players authenticate, create or join a room, choose a playlist, then compete in server-authoritative rounds: shared previews, first-to-lock guesses, scoring, and rematches. The graph shows the frontend and gateway, authentication and playlist/content services, and the game state machine. Cross-service and deployment links are documented in the README; source excerpts and the SOURCE INDEX support the shown internal calls. Unsampled routes and service wiring are not inferred beyond documented relationships.

Main entry points: [`srcs/backend/api-gateway/src/index.ts`](https://github.com/pacomariano28/songuess/blob/main/srcs/backend/api-gateway/src/index.ts) (Request gateway), [`srcs/backend/game-service/src/services/match.service.ts`](https://github.com/pacomariano28/songuess/blob/main/srcs/backend/game-service/src/services/match.service.ts) (Match orchestrator), [`srcs/backend/playlist-service/src/controllers/playlist.controller.ts`](https://github.com/pacomariano28/songuess/blob/main/srcs/backend/playlist-service/src/controllers/playlist.controller.ts) (Playlist service), [`srcs/backend/auth-service/src/services/auth.service.ts`](https://github.com/pacomariano28/songuess/blob/main/srcs/backend/auth-service/src/services/auth.service.ts) (Auth service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser experience"]
  node_frontend["React application<br/>[App.tsx]"]
  node_auth_ui["Auth provider<br/>[AuthProvider.tsx]"]
  node_room_ui["Room pages<br/>[RoomLobbyPage.tsx]"]
  node_match_ui["Match experience<br/>[MatchPage.tsx]"]
  node_match_socket["Match event sync<br/>[useMatchSocket.ts]"]
  node_guess_search["Guess search"]
end

subgraph group_edge["API gateway"]
  node_gateway["Request gateway<br/>[index.ts]"]
  node_gateway_auth["Access checks<br/>[auth.middleware.ts]"]
  node_gateway_game["Game routing<br/>[game.routes.ts]"]
end

subgraph group_identity["Identity and content"]
  node_auth_service["Auth service<br/>[auth.service.ts]"]
  node_auth_controller["Auth endpoints<br/>[auth.controller.ts]"]
  node_oauth_controller["Spotify OAuth"]
  node_spotify_auth["Spotify identity sync"]
  node_jwt["Access tokens<br/>[jwt.ts]"]
  node_refresh["Refresh sessions<br/>[refreshTokens.ts]"]
  node_auth_db[("Auth database<br/>[prisma.ts]")]
  node_content["Spotify catalog access<br/>[spotify.service.ts]"]
  node_content_search["Catalog search"]
  node_redis[("Token cache<br/>[redis.ts]")]
end

subgraph group_game["Gameplay runtime"]
  node_game_routes["Socket routes<br/>[socket.routes.ts]"]
  node_match_controller["Match events"]
  node_round_controller["Round events"]
  node_match_service["Match orchestrator<br/>[match.service.ts]"]
  node_match_modules["Match lifecycle and rules"]
  node_game_state["Live match state<br/>[match.service.ts]"]
  node_game_auth_client["Identity validation client<br/>[auth.client.ts]"]
end

subgraph group_catalog["Playable catalog"]
  node_playlist_service["Playlist service"]
  node_playlist_generator["Playlist selection"]
  node_clip_worker["Clip preparation"]
  node_media_files["Reusable audio media<br/>[mediaFiles.ts]"]
  node_playlist_db[("Playlist database<br/>[prisma.ts]")]
end

node_browser(("Player browser"))
node_nginx["HTTPS Nginx"]
node_spotify["Spotify Web API"]

node_browser -->|"uses HTTPS"| node_nginx
node_nginx -->|"serves app"| node_frontend
node_nginx -->|"routes API"| node_gateway
node_frontend -->|"wraps routes"| node_auth_ui
node_frontend -->|"routes rooms"| node_room_ui
node_frontend -->|"routes matches"| node_match_ui
node_browser -->|"requests services"| node_gateway
node_gateway -->|"checks access"| node_gateway_auth
node_gateway -->|"routes auth"| node_auth_service
node_gateway -->|"routes content"| node_content
node_gateway -->|"routes playlists"| node_playlist_service
node_gateway -->|"proxies sockets"| node_game_routes
node_auth_controller -->|"calls"| node_auth_service
node_auth_service -->|"reads and writes"| node_auth_db
node_auth_service -->|"signs access"| node_jwt
node_auth_service -->|"rotates tokens"| node_refresh
node_oauth_controller -->|"handles callback"| node_spotify_auth
node_spotify_auth -->|"requests identity"| node_spotify
node_spotify_auth -->|"stores profile"| node_auth_db
node_spotify_auth -->|"issues session"| node_refresh
node_content_search -->|"searches catalog"| node_content
node_content -->|"queries catalog"| node_spotify
node_content -->|"caches tokens"| node_redis
node_game_routes -->|"registers events"| node_match_controller
node_game_routes -->|"registers events"| node_round_controller
node_match_controller -->|"dispatches actions"| node_match_service
node_round_controller -->|"dispatches actions"| node_match_service
node_match_service -->|"delegates rules"| node_match_modules
node_match_service -->|"owns state"| node_game_state
node_game_auth_client -->|"validates identity"| node_auth_service
node_playlist_service -->|"selects tracks"| node_playlist_generator
node_playlist_service -->|"prepares clips"| node_clip_worker
node_clip_worker -->|"reuses media"| node_media_files
node_playlist_service -->|"stores catalog"| node_playlist_db
node_playlist_service -->|"requests metadata"| node_content
node_match_service -->|"prepares playlists"| node_playlist_service
node_match_service -->|"gets track data"| node_content
node_match_socket -->|"exchanges events"| node_browser
node_match_ui -.->|"syncs match"| node_match_socket
node_guess_search -->|"searches songs"| node_content_search
node_guess_search -->|"submits guess"| node_game_routes

click node_frontend "https://github.com/pacomariano28/songuess/blob/main/srcs/frontend/src/App.tsx"
click node_auth_ui "https://github.com/pacomariano28/songuess/blob/main/srcs/frontend/src/auth/AuthProvider.tsx"
click node_room_ui "https://github.com/pacomariano28/songuess/blob/main/srcs/frontend/src/pages/RoomLobbyPage.tsx"
click node_match_ui "https://github.com/pacomariano28/songuess/blob/main/srcs/frontend/src/pages/MatchPage.tsx"
click node_match_socket "https://github.com/pacomariano28/songuess/blob/main/srcs/frontend/src/match/hooks/useMatchSocket.ts"
click node_guess_search "https://github.com/pacomariano28/songuess/blob/main/srcs/frontend/src/match/hooks/useSpotifyGuessSearch.ts"
click node_gateway "https://github.com/pacomariano28/songuess/blob/main/srcs/backend/api-gateway/src/index.ts"
click node_gateway_auth "https://github.com/pacomariano28/songuess/blob/main/srcs/backend/api-gateway/src/middlewares/auth.middleware.ts"
click node_gateway_game "https://github.com/pacomariano28/songuess/blob/main/srcs/backend/api-gateway/src/routes/game.routes.ts"
click node_auth_service "https://github.com/pacomariano28/songuess/blob/main/srcs/backend/auth-service/src/services/auth.service.ts"
click node_auth_controller "https://github.com/pacomariano28/songuess/blob/main/srcs/backend/auth-service/src/controllers/auth.controller.ts"
click node_oauth_controller "https://github.com/pacomariano28/songuess/blob/main/srcs/backend/auth-service/src/controllers/oauth.controller.ts"
click node_spotify_auth "https://github.com/pacomariano28/songuess/blob/main/srcs/backend/auth-service/src/services/spotifyAuth.service.ts"
click node_jwt "https://github.com/pacomariano28/songuess/blob/main/srcs/backend/auth-service/src/lib/jwt.ts"
click node_refresh "https://github.com/pacomariano28/songuess/blob/main/srcs/backend/auth-service/src/lib/refreshTokens.ts"
click node_auth_db "https://github.com/pacomariano28/songuess/blob/main/srcs/backend/auth-service/src/lib/prisma.ts"
click node_content "https://github.com/pacomariano28/songuess/blob/main/srcs/backend/content-service/src/services/spotify.service.ts"
click node_content_search "https://github.com/pacomariano28/songuess/blob/main/srcs/backend/content-service/src/controllers/search.controller.ts"
click node_redis "https://github.com/pacomariano28/songuess/blob/main/srcs/backend/content-service/src/lib/redis.ts"
click node_game_routes "https://github.com/pacomariano28/songuess/blob/main/srcs/backend/game-service/src/routes/socket.routes.ts"
click node_match_controller "https://github.com/pacomariano28/songuess/blob/main/srcs/backend/game-service/src/controllers/match.controller.ts"
click node_round_controller "https://github.com/pacomariano28/songuess/blob/main/srcs/backend/game-service/src/controllers/round.controller.ts"
click node_match_service "https://github.com/pacomariano28/songuess/blob/main/srcs/backend/game-service/src/services/match.service.ts"
click node_match_modules "https://github.com/pacomariano28/songuess/tree/main/srcs/backend/game-service/src/services/match"
click node_game_state "https://github.com/pacomariano28/songuess/blob/main/srcs/backend/game-service/src/services/match.service.ts"
click node_game_auth_client "https://github.com/pacomariano28/songuess/blob/main/srcs/backend/game-service/src/clients/auth.client.ts"
click node_playlist_service "https://github.com/pacomariano28/songuess/blob/main/srcs/backend/playlist-service/src/controllers/playlist.controller.ts"
click node_playlist_generator "https://github.com/pacomariano28/songuess/blob/main/srcs/backend/playlist-service/src/services/playlistGenerator.ts"
click node_clip_worker "https://github.com/pacomariano28/songuess/blob/main/srcs/backend/playlist-service/src/services/clipWorker.service.ts"
click node_media_files "https://github.com/pacomariano28/songuess/blob/main/srcs/backend/playlist-service/src/lib/mediaFiles.ts"
click node_playlist_db "https://github.com/pacomariano28/songuess/blob/main/srcs/backend/playlist-service/src/lib/prisma.ts"

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_frontend,node_auth_ui,node_room_ui,node_match_ui,node_match_socket,node_guess_search,node_browser toneBlue
class node_gateway,node_gateway_auth,node_gateway_game toneAmber
class node_auth_service,node_auth_controller,node_oauth_controller,node_spotify_auth,node_jwt,node_refresh,node_auth_db,node_content,node_content_search,node_redis,node_spotify toneMint
class node_game_routes,node_match_controller,node_round_controller,node_match_service,node_match_modules,node_game_state,node_game_auth_client toneRose
class node_playlist_service,node_playlist_generator,node_clip_worker,node_media_files,node_playlist_db,node_nginx toneIndigo
```

## Components

### Browser experience

- [React application](https://github.com/pacomariano28/songuess/blob/main/srcs/frontend/src/App.tsx): `srcs/frontend/src/App.tsx`
- [Auth provider](https://github.com/pacomariano28/songuess/blob/main/srcs/frontend/src/auth/AuthProvider.tsx): `srcs/frontend/src/auth/AuthProvider.tsx`
- [Room pages](https://github.com/pacomariano28/songuess/blob/main/srcs/frontend/src/pages/RoomLobbyPage.tsx): `srcs/frontend/src/pages/RoomLobbyPage.tsx`
- [Match experience](https://github.com/pacomariano28/songuess/blob/main/srcs/frontend/src/pages/MatchPage.tsx): `srcs/frontend/src/pages/MatchPage.tsx`
- [Match event sync](https://github.com/pacomariano28/songuess/blob/main/srcs/frontend/src/match/hooks/useMatchSocket.ts): `srcs/frontend/src/match/hooks/useMatchSocket.ts`
- [Guess search](https://github.com/pacomariano28/songuess/blob/main/srcs/frontend/src/match/hooks/useSpotifyGuessSearch.ts): `srcs/frontend/src/match/hooks/useSpotifyGuessSearch.ts`

### API gateway

- [Request gateway](https://github.com/pacomariano28/songuess/blob/main/srcs/backend/api-gateway/src/index.ts): `srcs/backend/api-gateway/src/index.ts`
- [Access checks](https://github.com/pacomariano28/songuess/blob/main/srcs/backend/api-gateway/src/middlewares/auth.middleware.ts): `srcs/backend/api-gateway/src/middlewares/auth.middleware.ts`
- [Game routing](https://github.com/pacomariano28/songuess/blob/main/srcs/backend/api-gateway/src/routes/game.routes.ts): `srcs/backend/api-gateway/src/routes/game.routes.ts`

### Identity and content

- [Auth service](https://github.com/pacomariano28/songuess/blob/main/srcs/backend/auth-service/src/services/auth.service.ts): `srcs/backend/auth-service/src/services/auth.service.ts`
- [Auth endpoints](https://github.com/pacomariano28/songuess/blob/main/srcs/backend/auth-service/src/controllers/auth.controller.ts): `srcs/backend/auth-service/src/controllers/auth.controller.ts`
- [Spotify OAuth](https://github.com/pacomariano28/songuess/blob/main/srcs/backend/auth-service/src/controllers/oauth.controller.ts): `srcs/backend/auth-service/src/controllers/oauth.controller.ts`
- [Spotify identity sync](https://github.com/pacomariano28/songuess/blob/main/srcs/backend/auth-service/src/services/spotifyAuth.service.ts): `srcs/backend/auth-service/src/services/spotifyAuth.service.ts`
- [Access tokens](https://github.com/pacomariano28/songuess/blob/main/srcs/backend/auth-service/src/lib/jwt.ts): `srcs/backend/auth-service/src/lib/jwt.ts`
- [Refresh sessions](https://github.com/pacomariano28/songuess/blob/main/srcs/backend/auth-service/src/lib/refreshTokens.ts): `srcs/backend/auth-service/src/lib/refreshTokens.ts`
- [Auth database](https://github.com/pacomariano28/songuess/blob/main/srcs/backend/auth-service/src/lib/prisma.ts): `srcs/backend/auth-service/src/lib/prisma.ts`
- [Spotify catalog access](https://github.com/pacomariano28/songuess/blob/main/srcs/backend/content-service/src/services/spotify.service.ts): `srcs/backend/content-service/src/services/spotify.service.ts`
- [Catalog search](https://github.com/pacomariano28/songuess/blob/main/srcs/backend/content-service/src/controllers/search.controller.ts): `srcs/backend/content-service/src/controllers/search.controller.ts`
- [Token cache](https://github.com/pacomariano28/songuess/blob/main/srcs/backend/content-service/src/lib/redis.ts): `srcs/backend/content-service/src/lib/redis.ts`

### Gameplay runtime

- [Socket routes](https://github.com/pacomariano28/songuess/blob/main/srcs/backend/game-service/src/routes/socket.routes.ts): `srcs/backend/game-service/src/routes/socket.routes.ts`
- [Match events](https://github.com/pacomariano28/songuess/blob/main/srcs/backend/game-service/src/controllers/match.controller.ts): `srcs/backend/game-service/src/controllers/match.controller.ts`
- [Round events](https://github.com/pacomariano28/songuess/blob/main/srcs/backend/game-service/src/controllers/round.controller.ts): `srcs/backend/game-service/src/controllers/round.controller.ts`
- [Match orchestrator](https://github.com/pacomariano28/songuess/blob/main/srcs/backend/game-service/src/services/match.service.ts): `srcs/backend/game-service/src/services/match.service.ts`
- [Match lifecycle and rules](https://github.com/pacomariano28/songuess/tree/main/srcs/backend/game-service/src/services/match): `srcs/backend/game-service/src/services/match`
- [Live match state](https://github.com/pacomariano28/songuess/blob/main/srcs/backend/game-service/src/services/match.service.ts): `srcs/backend/game-service/src/services/match.service.ts`
- [Identity validation client](https://github.com/pacomariano28/songuess/blob/main/srcs/backend/game-service/src/clients/auth.client.ts): `srcs/backend/game-service/src/clients/auth.client.ts`

### Playable catalog

- [Playlist service](https://github.com/pacomariano28/songuess/blob/main/srcs/backend/playlist-service/src/controllers/playlist.controller.ts): `srcs/backend/playlist-service/src/controllers/playlist.controller.ts`
- [Playlist selection](https://github.com/pacomariano28/songuess/blob/main/srcs/backend/playlist-service/src/services/playlistGenerator.ts): `srcs/backend/playlist-service/src/services/playlistGenerator.ts`
- [Clip preparation](https://github.com/pacomariano28/songuess/blob/main/srcs/backend/playlist-service/src/services/clipWorker.service.ts): `srcs/backend/playlist-service/src/services/clipWorker.service.ts`
- [Reusable audio media](https://github.com/pacomariano28/songuess/blob/main/srcs/backend/playlist-service/src/lib/mediaFiles.ts): `srcs/backend/playlist-service/src/lib/mediaFiles.ts`
- [Playlist database](https://github.com/pacomariano28/songuess/blob/main/srcs/backend/playlist-service/src/lib/prisma.ts): `srcs/backend/playlist-service/src/lib/prisma.ts`

### Other components

- **Player browser**
- **HTTPS Nginx**
- **Spotify Web API**

## Connections

- Player browser → HTTPS Nginx: uses HTTPS
- HTTPS Nginx → React application: serves app
- HTTPS Nginx → Request gateway: routes API
- React application → Auth provider: wraps routes (evidence: `srcs/frontend/src/App.tsx`)
- React application → Room pages: routes rooms (evidence: `srcs/frontend/src/App.tsx`)
- React application → Match experience: routes matches (evidence: `srcs/frontend/src/App.tsx`)
- Player browser → Request gateway: requests services
- Request gateway → Access checks: checks access
- Request gateway → Auth service: routes auth
- Request gateway → Spotify catalog access: routes content
- Request gateway → Playlist service: routes playlists
- Request gateway → Socket routes: proxies sockets
- Auth endpoints → Auth service: calls (evidence: `srcs/backend/auth-service/src/controllers/auth.controller.ts`)
- Auth service → Auth database: reads and writes (evidence: `srcs/backend/auth-service/src/services/auth.service.ts`)
- Auth service → Access tokens: signs access (evidence: `srcs/backend/auth-service/src/services/auth.service.ts`)
- Auth service → Refresh sessions: rotates tokens (evidence: `srcs/backend/auth-service/src/services/auth.service.ts`)
- Spotify OAuth → Spotify identity sync: handles callback (evidence: `srcs/backend/auth-service/src/controllers/oauth.controller.ts`)
- Spotify identity sync → Spotify Web API: requests identity (evidence: `srcs/backend/auth-service/src/services/spotifyAuth.service.ts`)
- Spotify identity sync → Auth database: stores profile (evidence: `srcs/backend/auth-service/src/services/spotifyAuth.service.ts`)
- Spotify identity sync → Refresh sessions: issues session (evidence: `srcs/backend/auth-service/src/services/spotifyAuth.service.ts`)
- Catalog search → Spotify catalog access: searches catalog
- Spotify catalog access → Spotify Web API: queries catalog
- Spotify catalog access → Token cache: caches tokens (evidence: `srcs/backend/content-service/src/services/spotify.service.ts`)
- Socket routes → Match events: registers events (evidence: `srcs/backend/game-service/src/routes/socket.routes.ts`)
- Socket routes → Round events: registers events (evidence: `srcs/backend/game-service/src/routes/socket.routes.ts`)
- Match events → Match orchestrator: dispatches actions (evidence: `srcs/backend/game-service/src/controllers/match.controller.ts`)
- Round events → Match orchestrator: dispatches actions (evidence: `srcs/backend/game-service/src/controllers/round.controller.ts`)
- Match orchestrator → Match lifecycle and rules: delegates rules (evidence: `srcs/backend/game-service/src/services/match.service.ts`)
- Match orchestrator → Live match state: owns state (evidence: `srcs/backend/game-service/src/services/match.service.ts`)
- Identity validation client → Auth service: validates identity
- Playlist service → Playlist selection: selects tracks (evidence: `srcs/backend/playlist-service/src/controllers/playlist.controller.ts`)
- Playlist service → Clip preparation: prepares clips (evidence: `srcs/backend/playlist-service/src/controllers/playlist.controller.ts`)
- Clip preparation → Reusable audio media: reuses media (evidence: `srcs/backend/playlist-service/src/controllers/playlist.controller.ts`)
- Playlist service → Playlist database: stores catalog
- Playlist service → Spotify catalog access: requests metadata
- Match orchestrator → Playlist service: prepares playlists
- Match orchestrator → Spotify catalog access: gets track data
- Match event sync → Player browser: exchanges events (evidence: `srcs/frontend/src/match/hooks/useMatchSocket.ts`)
- Match experience → Match event sync: syncs match
- Guess search → Catalog search: searches songs (evidence: `srcs/frontend/src/match/hooks/useSpotifyGuessSearch.ts`)
- Guess search → Socket routes: submits guess (evidence: `srcs/frontend/src/match/hooks/useSpotifyGuessSearch.ts`)
