How harsheeee/spotify-stats works
Project Type and Purpose
• This is a full-stack web application:
• Frontend: React + TypeScript + Vite + Tailwind CSS
• Backend: Go HTTP server performing OAuth with Spotify and proxying API calls
• No on-prem database layer—data is fetched live from the Spotify Web API
File Structure
• Top-level:
• backend/ – Go service entrypoint (main.go), handlers/, models/
• frontend/ – Vite + React SPA (src/, public/, config files)
• Patterns:
• SPA communicates over REST endpoints exposed by Go backend
• OAuth dance handled in backend handlers
• Utility functions in frontend/src/lib/utils.ts
Main Components
A. User’s Web Browser (SPA)
B. Frontend Application
• UI components (Dashboard, HomePage, UI library)
• Client-side router & state
C. Backend API Service
• HTTP server (main.go)
• OAuth & token handling (models/tokenResponse.go)
• Request handlers (handlers/handlers.go)
D. External Service
• Spotify Accounts Service (OAuth endpoints)
• Spotify Web API (data endpoints)
Component Relationships & Data Flows
1) User → Browser SPA
• Initiates “Sign in with Spotify”
2) SPA → Backend (/login, /callback)
• Backend redirects to Spotify Accounts Service
3) Spotify Accounts → Backend
• Callback with authorization code → Backend exchanges for access token
4) Browser SPA ← Backend (tokenResponse)
• Backend returns token (or session cookie) to SPA
5) SPA → Backend (/top-artists, /top-tracks)
• Backend uses access token to call Spotify Web API
6) Backend → Spotify Web API
• Fetch user data (top artists/tracks)
7) Browser SPA ← Backend
• Receives JSON payload, renders charts
Architectural Patterns & Design Principles
• Single-page app (SPA) with a thin API backend
• Clear separation of concerns: UI vs. business logic vs. external API integration
• RESTful API endpoints in Go
• OAuth 2.0 Authorization Code Grant flow
• No persistent storage—stateless backend
Technologies & Frameworks to Call Out
• Frontend: React, TypeScript, Vite, Tailwind CSS
• Backend: Go (net/http), Go modules (go.mod), custom handlers
• External: Spotify OAuth + Web API