A backend-first, SaaS-style Spotify analysis service built with FastAPI, SQLAlchemy, and Spotify Web API. The system demonstrates real API integration, API key authentication, usage-based rate limiting, premium feature gating, and end-to-end CI validation.
This project is designed to be recruiter-reviewable, interview-defendable, and production-realistic.
- Uses Spotify Client Credentials Flow
- Fetches real track metadata from Spotify Web API
- No mock data in production paths
- API-key based access control
- Free and Premium plans
- Invalid key handling with proper HTTP semantics
- Daily request limits for free users
- Persistent usage tracking via database
- Clean error signaling when limits are exceeded
- Premium-only endpoints protected at API layer
- Audio features endpoint intentionally gated
- Placeholder clearly documents OAuth Authorization Code requirement
- Layered structure: API → Services → Integrations → Domain
- Clear separation of concerns
- Testable, maintainable modules
- Unit tests with isolated in-memory database
- End-to-end API tests using real HTTP calls
- GitHub Actions pipeline with Python version matrix
- CI badge reflecting repository health
- Python 3.9 – 3.11
- FastAPI
- SQLAlchemy
- SQLite
- Spotify Web API
- Pytest
- GitHub Actions
- Docker
spotify_audio_analyzer/
├── src/
│ ├── app/
│ │ ├── api/ # FastAPI routes
│ │ ├── services/ # Business logic
│ │ ├── integrations/ # Spotify API client
│ │ ├── core/ # Config, DB, errors
│ │ └── domain/ # Domain logic
│ └── main.py # App entrypoint
├── tests/
│ ├── unit/ # Fast unit tests (in-memory DB)
│ └── e2e/ # API-level integration tests
├── scripts/
│ └── e2e.sh # Full end-to-end test script
├── docker/
│ ├── Dockerfile
│ └── docker-compose.yml
├── .github/workflows/ci.yml
├── Makefile
├── requirements.txt
├── LICENSE
└── README.md
GET /health
GET /analyze/{track_id}
Header: X-API-Key
Returns:
- Track name
- Artist
- Album
- Popularity
- Duration
- Explicit flag
POST /premium/audio-features/{track_id}
Header: X-API-Key
- Free users receive
402 Payment Required - Premium users receive a documented placeholder response
- Designed for OAuth Authorization Code flow extension
Create a .env file (not committed):
SPOTIFY_CLIENT_ID=your_client_id
SPOTIFY_CLIENT_SECRET=your_client_secret
conda create -n spotify-audio-analyzer python=3.10
conda activate spotify-audio-analyzer
pip install -r requirements.txt
uvicorn src.main:app --reload
pytest tests/unit -v
chmod +x scripts/e2e.sh
./scripts/e2e.sh
The GitHub Actions workflow performs:
- Python syntax validation
- Unit tests with in-memory SQLite
- End-to-end API tests
- Multi-version Python validation (3.9, 3.10, 3.11)
All checks must pass before merge.
- Audio features endpoint gated to reflect real Spotify OAuth constraints
- Client Credentials used only where allowed by Spotify policy
- In-memory DB for unit tests to ensure speed and isolation
- File-based DB only used in runtime/E2E paths
- Explicit SaaS-style error handling instead of silent failures
MIT License
Saniya Acharya B.Tech Computer Science Engineering Backend / Systems / API Engineering Focus