A proprietary NestJS REST API for managing Discogs music collections and wantlists, with Discogs search, suggestions, automatic sync, and API key authentication. Utilized by side-a, my personal portfolio site.
- Collection & Wantlist: Read your synced Discogs collection and wantlist with sorting and pagination
- Discogs Search: Search releases directly against the Discogs API
- Suggestions: Track releases you want to suggest to others, stored locally
- Auto Sync: Syncs your Discogs collection and wantlist on startup and nightly at midnight UTC
- Advanced Sorting: Sort by date added, title, artist, year, rating, genre, or format
- API Key Authentication: Secure endpoints with token-based access control
- Request Validation: Comprehensive input validation with detailed error messages
- API Documentation: Interactive Swagger/OpenAPI documentation
- Framework: NestJS 10.x
- Database: PostgreSQL with TypeORM
- Validation: class-validator, class-transformer
- Documentation: Swagger/OpenAPI
- Language: TypeScript
- Node.js 18+
- PostgreSQL 13+
- npm or yarn
-
Clone repository
git clone https://github.com/caleb-vanlue/discogs-api.git cd discogs-api -
Install dependencies
npm install
-
Configure environment
cp .env.example .env
Required environment variables:
# API Security API_KEY=your-generated-api-key # Database DB_HOST=localhost DB_PORT=5432 DB_USERNAME=postgres DB_PASSWORD=your_password DB_NAME=discogs # Discogs Integration DISCOGS_USERNAME=your_discogs_username DISCOGS_API_TOKEN=your_discogs_token # Application PORT=3000 NODE_ENV=development # Sync behavior (optional, both default to true) SYNC_ON_STARTUP=true CRON_SYNC_ENABLED=true
-
Database setup
createdb discogs npm run migration:run
-
Start application
# Development npm run start:dev # Production npm run build npm run start:prod
On startup the app automatically syncs your Discogs collection and wantlist into the local database. A daily sync also runs at midnight UTC. Both can be disabled independently via environment variables:
SYNC_ON_STARTUP=false— skip the startup syncCRON_SYNC_ENABLED=false— disable the nightly cron
http://localhost:3000
All endpoints require API key authentication via one of:
- Header:
X-API-Key: your-api-key - Header:
Authorization: Bearer your-api-key
Access Swagger UI at http://localhost:3000/api for complete API documentation with request/response examples.
GET /collection/{userId}— Retrieve user collection with sorting and pagination
GET /collection/{userId}/wantlist— Retrieve user wantlist with sorting and pagination
GET /discogs/search— Search for releases on DiscogsGET /discogs/suggestions/{userId}— Get a user's suggestion listPOST /discogs/suggestions/{userId}— Add a release to a user's suggestionsDELETE /discogs/suggestions/{userId}/{releaseId}— Remove a release from suggestions
Pagination
limit: Items per page (1–100, default: 50)offset: Items to skip (default: 0)
Sorting
sort_by: Field to sort by- Collection:
dateAdded,title,primaryArtist,year,rating,primaryGenre,primaryFormat - Wantlist & Suggestions:
dateAdded,title,primaryArtist,year,primaryGenre,primaryFormat
- Collection:
sort_order:ASCorDESC(default:DESC)
Search (GET /discogs/search)
query: Search string (required)page: Page number (default: 1)per_page: Results per page (default: 25)
Get collection sorted by title
curl -H "X-API-Key: your-key" \
"http://localhost:3000/collection/username?limit=25&sort_by=title&sort_order=ASC"Search Discogs
curl -H "X-API-Key: your-key" \
"http://localhost:3000/discogs/search?query=kind+of+blue"Add to suggestions
curl -X POST -H "X-API-Key: your-key" -H "Content-Type: application/json" \
-d '{"releaseId": 123456}' \
"http://localhost:3000/discogs/suggestions/username"npm run start:dev # Start with hot reload
npm run build # Build for production
npm test # Run unit tests
npm run test:cov # Run tests with coverage
npm run lint # Lint and fix issuesnpm run migration:generate -- --name=MigrationName # Generate from entity changes
npm run migration:run # Apply pending migrations
npm run migration:revert # Rollback last migration