A backend REST API simulating a music streaming platform with role-based access control, cloud media storage, and audio streaming via CDN redirection.
| Link | |
|---|---|
| 🖥️ Frontend | youtify-frontend.vercel.app |
| 🔗 Backend API | https://your-render-url.onrender.com ← replace with your actual URL |
| Layer | Technology |
|---|---|
| Runtime | Node.js |
| Framework | Express.js v5 |
| Database | MongoDB (Mongoose ODM) |
| Authentication | JWT + bcryptjs |
| File Upload | Multer (memory storage) |
| Cloud Storage | ImageKit CDN |
| Cookie Handling | cookie-parser |
| Cross-Origin | CORS (configured for Vercel frontend) |
- JWT Authentication — Register, login, and protected route access via HTTP-only cookies
- Role-Based Access Control (RBAC) — Two roles:
artist(upload/create) anduser(read/stream) - Music Upload — Artists upload audio files via multipart form; files are streamed directly to ImageKit CDN (no disk writes)
- Album Management — Artists can create albums and associate tracks
- Audio Streaming — Stream endpoint resolves track by ID and redirects to CDN URL for playback
- Track Search — Case-insensitive regex search by title
- CORS Configured — Locked to frontend origin with credentials support
youtify/
├── server.js # Entry point — connects DB, starts server
├── package.json
└── src/
├── app.js # Express app — middleware + route mounting
├── db/
│ └── db.js # MongoDB connection
├── routes/
│ ├── auth.routes.js # /api/auth
│ └── music.routes.js # /api/music
├── controller/
│ ├── auth.controller.js # register, login, me
│ └── music.controller.js # upload, stream, search, albums
├── middleware/
│ └── auth.middleware.js # authMiddleware, authArtist, authUser
├── models/
│ ├── user.model.js # User schema (username, email, password, role)
│ ├── music.model.js # Music schema (uri, title, artist ref)
│ └── album.model.js # Album schema (title, musics[], artist ref)
└── services/
└── storage.service.js # ImageKit upload wrapper
| Method | Endpoint | Auth | Description |
|---|---|---|---|
POST |
/register |
None | Register a new user. Body: { username, email, password, role } |
POST |
/login |
None | Login. Returns JWT in HTTP-only cookie. Body: { username/email, password } |
GET |
/me |
Any logged-in user | Returns current user profile (no password) |
Register body example:
{
"username": "shiv",
"email": "shiv@example.com",
"password": "secret123",
"role": "artist"
}All music routes require a valid JWT cookie.
| Method | Endpoint | Role | Description |
|---|---|---|---|
POST |
/upload |
artist |
Upload audio file to ImageKit. Form-data: music (file) + title (string) |
POST |
/album |
artist |
Create an album. Body: { title, musicId } |
GET |
/ |
Any | Fetch all tracks with artist username |
GET |
/albums |
Any | Fetch all albums with artist info |
GET |
/stream/:id |
Any | Stream track by MongoDB ID (redirects to CDN URL) |
GET |
/search?title= |
Any | Case-insensitive title search |
| Role | Can Upload Music | Can Create Album | Can Stream/Search |
|---|---|---|---|
artist |
✅ | ✅ | ✅ |
user |
❌ (403) | ❌ (403) | ✅ |
| Unauthenticated | ❌ (401) | ❌ (401) | ❌ (401) |
- Node.js v18+
- MongoDB Atlas account (or local MongoDB)
- ImageKit account (free tier works)
1. Clone the repo
git clone https://github.com/ShivGrover45/youtify.git
cd youtify2. Install dependencies
npm install3. Configure environment variables
Create a .env file in the root:
MONGO_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret_key
IMAGEKIT_PRIVATE_KEY=your_imagekit_private_key4. Start the server
npm start
# Server runs on http://localhost:3000Audio files are never written to disk. Multer stores the file in memory as a Buffer, which is base64-encoded and sent directly to ImageKit. Only the resulting CDN URL is persisted in MongoDB.
The /stream/:id endpoint looks up the track's CDN URL from MongoDB and issues a 302 redirect to the ImageKit-hosted file. This offloads bandwidth entirely to the CDN.
JWT is stored in an HTTP-only, SameSite=none, Secure=true cookie — making it inaccessible to JavaScript and safe for cross-origin requests between the Vercel frontend and the deployed backend.
- Delete track endpoint (
DELETE /api/music/:id) - Pagination for
/api/music(currently returns all tracks) - Thumbnail upload support via ImageKit
- Playlist creation for listeners
- Rate limiting middleware
Shiv Grover — github.com/ShivGrover45