Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

116 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

MusicStream - Cloud-Native Music Streaming Platform

A modern, scalable music streaming application built with microservices architecture, featuring adaptive streaming, AI-powered recommendations, and real-time audio visualization.

🎡 Overview

MusicStream is a full-stack cloud-native music streaming platform that combines a React-based frontend with a microservices backend architecture. The platform offers personalized recommendations, adaptive audio quality, and immersive visualizations.

✨ Key Features

For Users

  • Authentication with Clerk (Sign In/Sign Up)
  • Browse and stream public songs and albums
  • AI-powered personalized recommendations via Recombee
  • Trending songs feed
  • Similar songs discovery
  • Real-time audio visualization (Bars, Wave, Circular)
  • Create and manage private playlists
  • Add/remove songs to/from playlists
  • Search songs and albums
  • Queue management + Shuffle + Repeat
  • Fullscreen visualizer mode with dynamic colors
  • View and edit user profile

For Artists

  • Upload songs (image + audio via Cloudinary)
  • Create public/private albums
  • Edit/remove songs and albums
  • Toggle visibility (public/private)
  • Artist dashboard with statistics
  • Track performance metrics

For Administrators

  • User management (list, block/unblock, delete, change roles)
  • Song management (toggle visible/hidden)
  • Album management (toggle visible/hidden)
  • Admin dashboard with tabs
  • Content moderation tools
  • System analytics

Audio Player Features

  • Play/Pause + Next/Previous
  • Seek bar with time display
  • Volume control
  • Queue management UI
  • Now Playing metadata
  • Audio Visualization (3 modes)
  • Adaptive streaming quality (network-aware)
  • Manual quality control (64/128/320 kbps)
  • Smart AI recommendations while listening
  • Playback analytics (play, complete, skip)

Visualizer Features

  • Dynamic color extraction from album art
  • Gradient backgrounds and immersive animations
  • Real-time frequency bars and waveforms
  • Auto-hide player controls
  • Keyboard shortcuts:
    • Space β†’ Play/Pause
    • Esc β†’ Exit fullscreen
  • Spinning vinyl animation
  • 3 Visualization Types:
    • Bars
    • Wave
    • Circular

Platform Capabilities

  • Smart Caching with Redis (5–10 min TTL)
  • RBAC Roles: User / Artist / Admin
  • AI personalized recommendations
  • Adaptive streaming (Cloudinary + Web APIs)
  • Microservices communication via API Gateway
  • CI/CD Pipeline with GitHub Actions
  • Auto-deployment to DigitalOcean Kubernetes
  • Zero-downtime deployments with auto-rollback

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Frontend (React + Vite)                   β”‚
β”‚          β€’ Adaptive Streaming β€’ Audio Visualization          β”‚
β”‚          β€’ Smart Recommendations β€’ Dynamic Theming           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚
                         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  API Gateway (Port 3000)                     β”‚
β”‚              β€’ Request Routing β€’ Health Checks               β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚                  β”‚                  β”‚
       β–Ό                  β–Ό                  β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ User Service β”‚  β”‚ Song Service β”‚  β”‚Album Service β”‚
β”‚  Port 3001   β”‚  β”‚  Port 3002   β”‚  β”‚  Port 3003   β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚                 β”‚                 β”‚
       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β–Ό                                 β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ MongoDB Atlasβ”‚                  β”‚ Redis Cloud  β”‚
β”‚ β€’ users_db   β”‚                  β”‚ β€’ Caching    β”‚
β”‚ β€’ songs_db   β”‚                  β”‚ β€’ TTL 5-10m  β”‚
β”‚ β€’ albums_db  β”‚                  β”‚              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

External Services:
- Clerk (Authentication)
- Cloudinary (Media Storage & Adaptive Streaming)
- Recombee (AI Recommendations)

CI/CD Pipeline:
GitHub Actions β†’ Build & Test β†’ Docker Build β†’ DigitalOcean Registry β†’ K8s Deploy

πŸ› οΈ Tech Stack

Frontend

  • React 18.2 with Vite 5
  • React Router v6.20
  • Zustand 4.4 (State Management)
  • TailwindCSS 3.3
  • Clerk 4.30 (Authentication)
  • Axios 1.6
  • Web Audio API
  • Lucide React 0.294

Backend

  • Node.js with Express
  • MongoDB with Mongoose
  • Redis for caching
  • Clerk SDK for authentication
  • Cloudinary for media storage
  • Recombee for recommendations
  • Multer for file uploads

DevOps & Infrastructure

  • Deployment: DigitalOcean Kubernetes (DOKS)
  • Container Registry: DigitalOcean Container Registry
  • Orchestration: Kubernetes with HPA (Horizontal Pod Autoscaling)
  • CI/CD: GitHub Actions
  • Monitoring: Prometheus + Grafana
  • SSL/TLS: cert-manager with Let's Encrypt
  • Ingress: NGINX Ingress Controller

πŸ“ Project Structure

music-stream/
β”œβ”€β”€ .github/
β”‚   └── workflows/
β”‚       └── backend-cicd.yml          # CI/CD Pipeline
β”‚
β”œβ”€β”€ frontend-ui/                       # React frontend application
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/               # React components
β”‚   β”‚   β”œβ”€β”€ pages/                    # Page components
β”‚   β”‚   β”œβ”€β”€ services/                 # API services
β”‚   β”‚   β”œβ”€β”€ store/                    # Zustand stores
β”‚   β”‚   β”œβ”€β”€ hooks/                    # Custom hooks
β”‚   β”‚   └── contexts/                 # React contexts
β”‚   β”œβ”€β”€ Dockerfile
β”‚   └── package.json
β”‚
β”œβ”€β”€ backend-microservices/             # Microservices backend
β”‚   β”œβ”€β”€ user-service/                 # User management
β”‚   β”œβ”€β”€ song-service/                 # Song management & recommendations
β”‚   β”œβ”€β”€ album-service/                # Album/playlist management
β”‚   β”œβ”€β”€ api-gateway/                  # API gateway & routing
β”‚   β”œβ”€β”€ k8s/                          # Kubernetes manifests
β”‚   β”‚   β”œβ”€β”€ namespace.yaml
β”‚   β”‚   β”œβ”€β”€ secrets.yaml
β”‚   β”‚   β”œβ”€β”€ *-deployment.yaml
β”‚   β”‚   β”œβ”€β”€ prometheus.yaml
β”‚   β”‚   β”œβ”€β”€ grafana.yaml
β”‚   β”‚   β”œβ”€β”€ ingress.yaml
β”‚   β”‚   └── letsencrypt-issuer.yaml
β”‚   β”œβ”€β”€ scripts/
β”‚   β”‚   └── quick-setup.sh            # Quick setup script
β”‚   └── docker-compose.yml
β”‚
β”œβ”€β”€ docs/
β”‚   └── CICD-SETUP-GUIDE.md           # Complete CI/CD setup guide
β”‚
β”œβ”€β”€ .gitignore
└── README.md                          # This file

πŸš€ Quick Start

Prerequisites

  • Node.js 18+
  • Docker & Docker Compose
  • kubectl (for Kubernetes deployment)
  • doctl (DigitalOcean CLI)
  • MongoDB Atlas account
  • Redis Cloud account
  • Clerk account
  • Cloudinary account
  • Recombee account (optional)
  • DigitalOcean account (for production deployment)

Environment Setup

  1. Clone the repository:
git clone <repository-url>
cd music-stream
  1. Setup Frontend:
cd frontend-ui
cp .env.example .env
# Edit .env with your credentials
npm install
  1. Setup Backend:
cd backend-microservices
cp .env.example .env
# Edit .env with your credentials

Run with Docker Compose (Development)

cd backend-microservices
docker-compose up -d

Services will be available at:

Run Locally (Development)

Terminal 1 - Frontend:

cd frontend-ui
npm run dev

Terminal 2 - User Service:

cd backend-microservices/user-service
npm run dev

Terminal 3 - Song Service:

cd backend-microservices/song-service
npm run dev

Terminal 4 - Album Service:

cd backend-microservices/album-service
npm run dev

Terminal 5 - API Gateway:

cd backend-microservices/api-gateway
npm run dev

☸️ Production Deployment (Kubernetes)

Quick Setup with Script

cd backend-microservices

# Make script executable
chmod +x scripts/quick-setup.sh

# Run automated setup
./scripts/quick-setup.sh

The script will:

  • βœ… Check prerequisites (kubectl, doctl)
  • βœ… Authenticate with DigitalOcean
  • βœ… Connect to your Kubernetes cluster
  • βœ… Create namespace and secrets
  • βœ… Install Ingress Controller
  • βœ… Install cert-manager
  • βœ… Get LoadBalancer IP

Manual Deployment

See detailed instructions in CI/CD Setup Guide

CI/CD Pipeline

The project includes automated CI/CD pipeline that:

  1. Build & Test - Tests all microservices
  2. Docker Build - Builds and tags images
  3. Push to Registry - Pushes to DigitalOcean Registry
  4. Deploy to K8s - Deploys to Kubernetes cluster
  5. Auto Rollback - Rolls back on failure

Trigger Deployment:

git add .
git commit -m "feat: your changes"
git push origin main

Monitor Deployment:

  • Go to GitHub β†’ Actions tab
  • Watch the pipeline execution
  • Check deployment logs

πŸ”§ Configuration

Frontend Environment Variables

VITE_API_URL=http://localhost:3000
VITE_CLERK_PUBLISHABLE_KEY=your_clerk_publishable_key

Backend Environment Variables

# MongoDB
MONGO_URI=mongodb+srv://user:pass@cluster.mongodb.net

# Redis
REDIS_URL=redis://user:pass@redis-cloud.com:port

# Clerk
CLERK_SECRET_KEY=your_clerk_secret_key
CLERK_PUBLISHABLE_KEY=your_clerk_publishable_key

# Cloudinary
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret

# Recombee (Optional)
RECOMBEE_DATABASE_ID=your_database_id
RECOMBEE_PRIVATE_TOKEN=your_private_token
RECOMBEE_REGION=us-west

GitHub Secrets (for CI/CD)

Add these secrets in GitHub Repository Settings:

DIGITALOCEAN_ACCESS_TOKEN
MONGODB_USERS_URI
MONGODB_SONGS_URI
MONGODB_ALBUMS_URI
REDIS_URL
CLERK_SECRET_KEY
CLERK_PUBLISHABLE_KEY
CLOUDINARY_CLOUD_NAME
CLOUDINARY_API_KEY
CLOUDINARY_API_SECRET
RECOMBEE_DATABASE_ID (optional)
RECOMBEE_PRIVATE_TOKEN (optional)
RECOMBEE_REGION (optional)

πŸ“Š API Documentation

Authentication

All authenticated requests require Clerk JWT token in headers:

Authorization: Bearer <token>

Main Endpoints

Songs:

  • GET /api/songs - List all public songs
  • GET /api/songs/trending - Get trending songs
  • GET /api/songs/:id/similar - Get similar songs
  • GET /api/songs/recommendations/for-you - Personalized recommendations
  • POST /api/songs - Upload song (Artist)
  • POST /api/songs/:id/track/play - Track play interaction

Albums:

  • GET /api/albums - List all public albums
  • GET /api/albums/:id - Get album with songs
  • POST /api/albums - Create album/playlist
  • POST /api/albums/:id/songs - Add song to album

Admin:

  • GET /api/admin/users - List all users
  • PATCH /api/admin/users/:id/block - Block/unblock user
  • GET /api/admin/songs - List all songs
  • PATCH /api/admin/songs/:id/visible - Toggle visibility

For complete API documentation, see Backend README.

πŸ“ˆ Monitoring & Health Checks

Service Health

Each service exposes a /health endpoint:

curl http://localhost:3001/health  # User Service
curl http://localhost:3002/health  # Song Service
curl http://localhost:3003/health  # Album Service

Aggregated Health

API Gateway provides consolidated health status:

curl http://localhost:3000/health/services

Production Monitoring

Access Grafana dashboard:

URL: https://grafana.YOUR_IP.nip.io
Username: admin
Password: admin123

View metrics:

  • Request rates
  • Response times
  • Error rates
  • Resource usage (CPU, Memory)
  • Pod status

πŸ” Security

  • JWT-based authentication via Clerk
  • Role-based access control (RBAC)
  • CORS configured for trusted origins
  • Secrets managed via Kubernetes Secrets
  • HTTPS enforced in production
  • Input validation and sanitization
  • Non-root containers
  • Security contexts in Kubernetes

πŸš€ DevOps Features

Horizontal Pod Autoscaling (HPA)

  • Auto-scales based on CPU/Memory usage
  • Min replicas: 1
  • Max replicas: 8-15 (depends on service)
  • Target CPU: 70%
  • Target Memory: 75-80%

Rolling Updates

  • Zero-downtime deployments
  • maxSurge: 1-2 pods
  • maxUnavailable: 0
  • Gradual rollout

Health Probes

  • Liveness: Restart unhealthy pods
  • Readiness: Remove pod from service if not ready
  • Startup: Give pod time to start

Monitoring Stack

  • Prometheus: Metrics collection
  • Grafana: Visualization dashboards
  • Real-time metrics and alerts

πŸ“š Documentation

πŸ”„ Development Workflow

Local Development

# 1. Make changes to code
# 2. Test locally with docker-compose
docker-compose up -d

# 3. Verify changes
curl http://localhost:3000/health/services

Deploy to Production

# 1. Commit changes
git add .
git commit -m "feat: your feature"

# 2. Push to trigger CI/CD
git push origin main

# 3. Monitor deployment
# - Check GitHub Actions
# - Watch kubectl get pods -n music-stream -w

Rollback if Needed

# Manual rollback
kubectl rollout undo deployment/song-service -n music-stream

# Or CI/CD auto-rollback on failure

πŸ› Troubleshooting

Check Pod Status

kubectl get pods -n music-stream
kubectl describe pod <pod-name> -n music-stream
kubectl logs <pod-name> -n music-stream

Check Service Endpoints

kubectl get svc -n music-stream
kubectl get ingress -n music-stream

View Events

kubectl get events -n music-stream --sort-by='.lastTimestamp'

Common Issues

ImagePullBackOff: Check registry credentials

kubectl delete secret regcred -n music-stream
# Recreate secret with correct credentials

CrashLoopBackOff: Check pod logs

kubectl logs <pod-name> -n music-stream --previous

Service Unavailable: Check ingress and service

kubectl describe ingress music-stream-ingress -n music-stream

πŸ“ Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'feat: add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open Pull Request

πŸ“„ License

MIT License

About

Cloud-native music streaming platform built with React, Node.js microservices, and Kubernetes. Features AI-powered recommendations, adaptive streaming, and smart caching.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages