How eziokwuche/music-analytics-service works
This is a small Express music-listening analytics API. A browser uses the demo login to establish a session; protected routes then synchronize recent Last.fm scrobbles into PostgreSQL or return per-user top-artist counts. The graph separates route/authentication, request handling, external history retrieval, and persistence/analytics. The README documents the API behavior and schema; sampled source confirms the calls shown. The Spotify-named service actually calls Last.fm, as documented and implemented.
Main entry points: index.js Express server · apiRoutes.js API routes · authController.js Demo login · analyticsController.js History and analytics
Components 13
HTTP and sessions
- Express server
src/index.js - Cookie sessions
src/index.js - Login route
src/routes/authRoutes.js - API routes
src/routes/apiRoutes.js - Session guard
src/middleware/requireAuth.js
Request handlers
- Demo login
src/controllers/authController.js - History and analytics
src/controllers/analyticsController.js
History and analytics
- Recent-track fetch
src/services/spotifyService.js - History queries
src/services/dbService.js - Postgres pool
src/config/db.js
External systems
- PostgreSQL
- Last.fm API
Other components
- Browser client
Connections 19
- Browser client → Express server: sends requests
README.md - Express server → Cookie sessions: configures
src/index.js - Express server → Login route: mounts
src/index.js - Express server → API routes: mounts
src/index.js - Express server → Postgres pool: checks connection
src/index.js - Browser client → Login route: requests login
README.md - Login route → Demo login: routes to
src/routes/authRoutes.js - Demo login → History queries: finds or creates user
src/controllers/authController.js - Demo login → Cookie sessions: sets user ID
src/controllers/authController.js - Demo login → API routes: redirects to history
README.md - Browser client → API routes: requests protected API
README.md - API routes → Session guard: checks session
src/routes/apiRoutes.js - Session guard → History and analytics: passes authorized request
src/routes/apiRoutes.js - API routes → History and analytics: routes handlers
src/routes/apiRoutes.js - History and analytics → Recent-track fetch: fetches recent tracks
src/controllers/analyticsController.js - Recent-track fetch → Last.fm API: requests scrobbles
src/services/spotifyService.js - History and analytics → History queries: saves plays or reads counts
src/controllers/analyticsController.js - History queries → Postgres pool: queries pool
src/services/dbService.js - History queries → PostgreSQL: reads and writes
src/services/dbService.js