# pasiotestudio/underground architecture

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

- Interactive diagram: https://gitdiagram.com/pasiotestudio/underground
- Repository: https://github.com/pasiotestudio/underground

## Overview

Underground helps a Spotify user build a playlist of low-popularity tracks, filtering out tracks already in the playlist or previously used and artists the user has banned. The workflow spans Spotify login and token refresh, profile and playlist loading, genre-based track discovery, eligibility checks, playlist updates, and recording used tracks. The repository also provides genre and banned-artist management. Backend route excerpts expose most service relationships; frontend UI wiring is less visible in the available evidence, so its component-level connections are omitted.

Main entry points: [`backend/route/login.js`](https://github.com/pasiotestudio/underground/blob/main/backend/route/login.js) (Login and logout), [`backend/route/user.js`](https://github.com/pasiotestudio/underground/blob/main/backend/route/user.js) (User profile API), [`backend/route/tracks.js`](https://github.com/pasiotestudio/underground/blob/main/backend/route/tracks.js) (Track and artist API), [`backend/util/prisma.js`](https://github.com/pasiotestudio/underground/blob/main/backend/util/prisma.js) (Database client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web application"]
  node_home["Main page<br/>[page.tsx]"]
  node_redirect["Login redirect<br/>[page.tsx]"]
  node_profile_context["Profile state<br/>[Profile.tsx]"]
  node_add_tracks_ui["Add tracks UI<br/>[AddTracks.tsx]"]
  node_genres_ui["Genre controls<br/>[Genres.tsx]"]
  node_banned_ui["Banned artists UI<br/>[BannedArtists.tsx]"]
  node_playlist_ui["Playlist view<br/>[Playlist.tsx]"]
  node_http_client["HTTP clients<br/>[axios.ts]"]
  node_spotify_logic["Track selection<br/>[spotify.ts]"]
end

subgraph group_auth["Authentication"]
  node_backend_app["API server<br/>[index.js]"]
  node_login_routes["Login and logout<br/>[login.js]"]
  node_auth_middleware["Cookie authentication<br/>[auth.js]"]
  node_token_refresh["Token refresh<br/>[token.js]"]
end

subgraph group_profile["Profile and playlist"]
  node_user_routes["User profile API<br/>[user.js]"]
  node_playlist_service["Playlist service<br/>[playlist.js]"]
  node_database_client["Database client<br/>[prisma.js]"]
  node_database[("Application database<br/>[schema.prisma]")]
end

subgraph group_tracks["Track discovery and controls"]
  node_track_routes["Track and artist API<br/>[tracks.js]"]
end

node_user(("Spotify user"))
node_spotify_auth["Spotify accounts"]
node_spotify_api["Spotify Web API"]

node_user -.->|"uses"| node_home
node_backend_app -->|"mounts routes"| node_login_routes
node_backend_app -->|"mounts routes"| node_user_routes
node_backend_app -->|"mounts routes"| node_track_routes
node_login_routes -->|"exchanges code"| node_spotify_auth
node_login_routes -->|"fetches user"| node_spotify_api
node_login_routes -->|"gets playlist"| node_playlist_service
node_login_routes -->|"reads and writes"| node_database_client
node_login_routes -->|"protects logout"| node_auth_middleware
node_user_routes -->|"protects routes"| node_auth_middleware
node_track_routes -->|"protects routes"| node_auth_middleware
node_user_routes -->|"handles token route"| node_token_refresh
node_token_refresh -->|"refreshes token"| node_spotify_auth
node_user_routes -->|"reads and writes"| node_database_client
node_track_routes -->|"reads and writes"| node_database_client
node_login_routes -->|"creates playlist"| node_spotify_api
node_user_routes -->|"loads playlist"| node_playlist_service
node_playlist_service -->|"manages playlists"| node_spotify_api
node_database_client -.->|"connects to"| node_database
node_spotify_logic -->|"uses clients"| node_http_client
node_spotify_logic -->|"searches and edits"| node_spotify_api
node_spotify_logic -->|"checks and records tracks"| node_track_routes
node_http_client -->|"refreshes access token"| node_user_routes
node_user_routes -->|"fetches user and tracks"| node_spotify_api
node_track_routes -->|"fetches artist and track"| node_spotify_api

click node_home "https://github.com/pasiotestudio/underground/blob/main/frontend/app/page.tsx"
click node_redirect "https://github.com/pasiotestudio/underground/blob/main/frontend/app/redirect/page.tsx"
click node_profile_context "https://github.com/pasiotestudio/underground/blob/main/frontend/context/Profile.tsx"
click node_add_tracks_ui "https://github.com/pasiotestudio/underground/blob/main/frontend/components/underground/AddTracks.tsx"
click node_genres_ui "https://github.com/pasiotestudio/underground/blob/main/frontend/components/underground/Genres.tsx"
click node_banned_ui "https://github.com/pasiotestudio/underground/blob/main/frontend/components/underground/BannedArtists.tsx"
click node_playlist_ui "https://github.com/pasiotestudio/underground/blob/main/frontend/components/underground/Playlist.tsx"
click node_http_client "https://github.com/pasiotestudio/underground/blob/main/frontend/util/axios.ts"
click node_spotify_logic "https://github.com/pasiotestudio/underground/blob/main/frontend/util/spotify.ts"
click node_backend_app "https://github.com/pasiotestudio/underground/blob/main/backend/index.js"
click node_login_routes "https://github.com/pasiotestudio/underground/blob/main/backend/route/login.js"
click node_auth_middleware "https://github.com/pasiotestudio/underground/blob/main/backend/middleware/auth.js"
click node_token_refresh "https://github.com/pasiotestudio/underground/blob/main/backend/util/token.js"
click node_user_routes "https://github.com/pasiotestudio/underground/blob/main/backend/route/user.js"
click node_playlist_service "https://github.com/pasiotestudio/underground/blob/main/backend/spotify/playlist.js"
click node_track_routes "https://github.com/pasiotestudio/underground/blob/main/backend/route/tracks.js"
click node_database_client "https://github.com/pasiotestudio/underground/blob/main/backend/util/prisma.js"
click node_database "https://github.com/pasiotestudio/underground/blob/main/backend/prisma/schema.prisma"

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_home,node_redirect,node_profile_context,node_add_tracks_ui,node_genres_ui,node_banned_ui,node_playlist_ui,node_http_client,node_spotify_logic,node_user toneBlue
class node_backend_app,node_login_routes,node_auth_middleware,node_token_refresh toneAmber
class node_user_routes,node_playlist_service,node_database_client,node_database,node_spotify_api toneMint
class node_track_routes toneRose
class node_spotify_auth toneIndigo
```

## Components

### Web application

- [Main page](https://github.com/pasiotestudio/underground/blob/main/frontend/app/page.tsx): `frontend/app/page.tsx`
- [Login redirect](https://github.com/pasiotestudio/underground/blob/main/frontend/app/redirect/page.tsx): `frontend/app/redirect/page.tsx`
- [Profile state](https://github.com/pasiotestudio/underground/blob/main/frontend/context/Profile.tsx): `frontend/context/Profile.tsx`
- [Add tracks UI](https://github.com/pasiotestudio/underground/blob/main/frontend/components/underground/AddTracks.tsx): `frontend/components/underground/AddTracks.tsx`
- [Genre controls](https://github.com/pasiotestudio/underground/blob/main/frontend/components/underground/Genres.tsx): `frontend/components/underground/Genres.tsx`
- [Banned artists UI](https://github.com/pasiotestudio/underground/blob/main/frontend/components/underground/BannedArtists.tsx): `frontend/components/underground/BannedArtists.tsx`
- [Playlist view](https://github.com/pasiotestudio/underground/blob/main/frontend/components/underground/Playlist.tsx): `frontend/components/underground/Playlist.tsx`
- [HTTP clients](https://github.com/pasiotestudio/underground/blob/main/frontend/util/axios.ts): `frontend/util/axios.ts`
- [Track selection](https://github.com/pasiotestudio/underground/blob/main/frontend/util/spotify.ts): `frontend/util/spotify.ts`

### Authentication

- [API server](https://github.com/pasiotestudio/underground/blob/main/backend/index.js): `backend/index.js`
- [Login and logout](https://github.com/pasiotestudio/underground/blob/main/backend/route/login.js): `backend/route/login.js`
- [Cookie authentication](https://github.com/pasiotestudio/underground/blob/main/backend/middleware/auth.js): `backend/middleware/auth.js`
- [Token refresh](https://github.com/pasiotestudio/underground/blob/main/backend/util/token.js): `backend/util/token.js`

### Profile and playlist

- [User profile API](https://github.com/pasiotestudio/underground/blob/main/backend/route/user.js): `backend/route/user.js`
- [Playlist service](https://github.com/pasiotestudio/underground/blob/main/backend/spotify/playlist.js): `backend/spotify/playlist.js`
- [Database client](https://github.com/pasiotestudio/underground/blob/main/backend/util/prisma.js): `backend/util/prisma.js`
- [Application database](https://github.com/pasiotestudio/underground/blob/main/backend/prisma/schema.prisma): `backend/prisma/schema.prisma`

### Track discovery and controls

- [Track and artist API](https://github.com/pasiotestudio/underground/blob/main/backend/route/tracks.js): `backend/route/tracks.js`

### Other components

- **Spotify user**
- **Spotify accounts**
- **Spotify Web API**

## Connections

- Spotify user → Main page: uses (evidence: `README.md`)
- API server → Login and logout: mounts routes (evidence: `backend/index.js`)
- API server → User profile API: mounts routes (evidence: `backend/index.js`)
- API server → Track and artist API: mounts routes (evidence: `backend/index.js`)
- Login and logout → Spotify accounts: exchanges code (evidence: `backend/route/login.js`)
- Login and logout → Spotify Web API: fetches user (evidence: `backend/route/login.js`)
- Login and logout → Playlist service: gets playlist (evidence: `backend/route/login.js`)
- Login and logout → Database client: reads and writes (evidence: `backend/route/login.js`)
- Login and logout → Cookie authentication: protects logout (evidence: `backend/route/login.js`)
- User profile API → Cookie authentication: protects routes (evidence: `backend/route/user.js`)
- Track and artist API → Cookie authentication: protects routes (evidence: `backend/route/tracks.js`)
- User profile API → Token refresh: handles token route (evidence: `backend/route/user.js`)
- Token refresh → Spotify accounts: refreshes token (evidence: `backend/util/token.js`)
- User profile API → Database client: reads and writes (evidence: `backend/route/user.js`)
- Track and artist API → Database client: reads and writes (evidence: `backend/route/tracks.js`)
- Login and logout → Spotify Web API: creates playlist
- User profile API → Playlist service: loads playlist (evidence: `backend/route/user.js`)
- Playlist service → Spotify Web API: manages playlists (evidence: `backend/spotify/playlist.js`)
- Database client → Application database: connects to
- Track selection → HTTP clients: uses clients (evidence: `frontend/util/spotify.ts`)
- Track selection → Spotify Web API: searches and edits (evidence: `frontend/util/spotify.ts`)
- Track selection → Track and artist API: checks and records tracks (evidence: `frontend/util/spotify.ts`)
- HTTP clients → User profile API: refreshes access token (evidence: `frontend/util/axios.ts`)
- User profile API → Spotify Web API: fetches user and tracks (evidence: `backend/route/user.js`)
- Track and artist API → Spotify Web API: fetches artist and track (evidence: `backend/route/tracks.js`)
