A comprehensive music streaming and merchandise platform built with NestJS, PostgreSQL, and TypeORM. This platform empowers artists to distribute their music, sell merchandise, connect with fans, and manage their music business all in one place.
- Track & Album Management - Upload, organize, and distribute music content
- Audio Streaming - High-quality streaming with multiple bitrate options
- Playlist System - Create, share, and collaborate on playlists
- Music Charts - Real-time charts and trending algorithms
- Genre Classification - Hierarchical genre system for better discovery
- Product Management - Manage apparel, vinyl, accessories, and more
- Inventory Tracking - Real-time stock management with alerts
- Variant System - Handle sizes, colors, and product options
- Bundle Deals - Create merchandise bundles and limited editions
- Artist Profiles - Comprehensive profiles for individuals, bands, and labels
- Fan Engagement - Following, reviews, comments, and social features
- Live Streaming - Host live concerts and studio sessions
- Fan Funding - Tips, donations, and crowdfunding campaigns
- Concert Management - Event creation, ticket sales, and check-in
- Festival Tools - Multi-stage event planning and management
- Music Contests - Host competitions and talent showcases
- Rights Management - Track copyrights, licenses, and royalties
- Analytics Dashboard - Comprehensive insights for artists
- Revenue Sharing - Automated splits for bands and collaborators
- Sync Licensing - License music for media and commercial use
- AI Recommendations - Machine learning-powered music discovery
- Music Education - Courses, tutorials, and certification
- Collaboration Tools - Remote music creation and project management
- Publishing Admin - Mechanical rights and performance royalties
- Backend Framework: NestJS with TypeScript
- Database: PostgreSQL with TypeORM
- Authentication: JWT-based authentication
- File Storage: Multi-provider file upload system
- Audio Processing: Advanced audio processing pipeline
- Caching: Redis for performance optimization
- API Documentation: Swagger/OpenAPI integration
Before you begin, ensure you have the following installed:
- Node.js (v18 or higher)
- PostgreSQL (v13 or higher)
- Redis (v6 or higher)
- npm or yarn package manager
git clone https://github.com/yourusername/music-platform-backend.git
cd music-platform-backend
npm install
# or
yarn install
Copy the example environment file and configure your settings:
cp .env.example .env
Update the .env
file with your configuration:
# Database Configuration
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_USERNAME=your_username
DATABASE_PASSWORD=your_password
DATABASE_NAME=music_platform
# Redis Configuration
REDIS_HOST=localhost
REDIS_PORT=6379
# JWT Configuration
JWT_SECRET=your_jwt_secret_key
JWT_EXPIRES_IN=24h
# File Upload Configuration
UPLOAD_PATH=./uploads
MAX_FILE_SIZE=100MB
# Audio Processing
AUDIO_QUALITY_LEVELS=128,320,lossless
# Run migrations
npm run migration:run
# Seed the database (optional)
npm run seed
# Development mode
npm run start:dev
# Production mode
npm run build
npm run start:prod
The API will be available at http://localhost:3000
Once the application is running, you can access the interactive API documentation at:
- Swagger UI:
http://localhost:3000/api/docs
- OpenAPI JSON:
http://localhost:3000/api/docs-json
src/
βββ modules/
β βββ auth/ # Authentication & authorization
β βββ users/ # User management
β βββ artists/ # Artist profiles and management
β βββ music/ # Tracks, albums, and audio processing
β β βββ tracks/ # Track management
β β βββ albums/ # Album management
β β βββ genres/ # Genre classification
β β βββ playlists/ # Playlist functionality
β βββ merchandise/ # Product and inventory management
β βββ streaming/ # Audio streaming services
β βββ purchases/ # Order and payment processing
β βββ events/ # Concert and event management
β βββ analytics/ # Platform analytics
β βββ notifications/ # Notification system
β βββ admin/ # Administrative functions
βββ common/
β βββ decorators/ # Custom decorators
β βββ guards/ # Authentication guards
β βββ interceptors/ # Request/response interceptors
β βββ pipes/ # Validation pipes
β βββ filters/ # Exception filters
βββ config/ # Configuration files
βββ database/
β βββ entities/ # TypeORM entities
β βββ migrations/ # Database migrations
β βββ seeds/ # Database seeders
βββ utils/ # Utility functions
# Unit tests
npm run test
# Integration tests
npm run test:integration
# E2E tests
npm run test:e2e
# Test coverage
npm run test:cov
# Generate migration
npm run migration:generate -- -n MigrationName
# Run migrations
npm run migration:run
# Revert migration
npm run migration:revert
# Seed database
npm run seed
# Linting
npm run lint
# Format code
npm run format
# Type checking
npm run type-check
The platform uses JWT-based authentication with role-based access control:
- Fan/User - Basic platform access for music consumption
- Artist - Music upload, profile management, analytics access
- Band - Multi-member artist accounts with collaboration tools
- Label - Manage multiple artists and releases
- Admin - Platform administration and moderation
- Register/Login with email and password
- Receive JWT token upon successful authentication
- Include token in Authorization header:
Bearer <token>
- Token validates user identity and permissions
POST /auth/register
- User registrationPOST /auth/login
- User loginPOST /auth/refresh
- Refresh JWT token
GET /tracks
- List tracks with filtersPOST /tracks
- Upload new trackGET /albums/:id
- Get album detailsPOST /playlists
- Create playlist
GET /merchandise
- Browse productsPOST /merchandise
- Create product (artists only)PUT /merchandise/:id/inventory
- Update inventory
GET /stream/:trackId
- Stream audio trackPOST /play/:trackId
- Record play eventGET /charts
- Get music charts
GET /events
- List upcoming eventsPOST /events
- Create event (artists only)POST /events/:id/tickets
- Purchase tickets
We welcome contributions! Please see our Contributing Guidelines for details.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Make your changes
- Add tests for new functionality
- Ensure all tests pass (
npm run test
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
bug
- Something isn't workingenhancement
- New feature or requestdocumentation
- Improvements to documentationgood first issue
- Good for newcomershelp wanted
- Extra attention needed
- Proper indexing on frequently queried fields
- Connection pooling for concurrent requests
- Query optimization for large music catalogs
- Partitioning for large datasets (plays, analytics)
- Redis caching for frequently accessed data
- CDN integration for static assets
- Audio file caching for streaming optimization
- API response caching with TTL
- Multiple quality levels (128k, 320k, lossless)
- Progressive download for improved UX
- CDN distribution for global performance
- Bandwidth adaptation based on connection
- Password hashing with bcrypt
- JWT token encryption and expiration
- Input validation and sanitization
- SQL injection prevention with TypeORM
- XSS protection with proper encoding
- Rate limiting per endpoint
- CORS configuration
- Security headers (helmet.js)
- File upload validation and scanning
- Audio content protection (DRM ready)
- Health check endpoints
- Performance metrics collection
- Error tracking and alerting
- Database query monitoring
- API usage analytics
- Streaming statistics
- Sales and revenue tracking
- User engagement metrics
- Artist performance insights
- Geographic and demographic data
- Set up production database
- Configure environment variables
- Set up file storage (AWS S3, Google Cloud, etc.)
- Configure CDN for audio streaming
- Set up monitoring and logging
- Traditional Server - PM2 process management
- Container - Docker with orchestration
- Cloud Platform - AWS, Google Cloud, Azure
- Serverless - AWS Lambda, Vercel, etc.
The API supports versioning to maintain backward compatibility:
- Current version:
v1
- Base URL:
https://api.musicplatform.com/v1
- Version specified in URL path
- Documentation: docs.musicplatform.com
- Discord: Join our community
- Issues: GitHub Issues
- Email: support@musicplatform.com
This project is licensed under the MIT License - see the LICENSE file for details.
- NestJS team for the amazing framework
- TypeORM for excellent database integration
- The open-source community for inspiration and contributions
- Musicians and artists who inspire this platform
Built with β€οΈ for the music community