A production-ready, scalable backend for a social media platform built with Node.js, Express, MySQL, and modern backend architecture patterns.
- 🔐 Authentication & Authorization (JWT Access + Refresh Tokens)
- 👤 User Management (profile, avatar, password, account)
- 📝 Posts (CRUD + visibility control + image upload)
- ❤️ Likes System
- 💬 Comments System
- 👥 Follow/Unfollow System
- 📚 Saved Posts (Bookmarks)
- 📸 Stories (like Instagram stories)
- 🔔 Real-time Notifications (SSE - Server-Sent Events)
- ⚡ Event-driven architecture
- ⏱ Cron Jobs (background tasks)
- 📧 Email OTP Verification (SendGrid or fallback to console)
- 🛡 Rate Limiting & Validation (Zod)
- 📁 File Upload Support (Multer)
- 🌐 CORS Enabled
- Node.js
- Express.js
- MySQL
- JWT (Authentication)
- Zod (Validation)
- Multer (File Upload)
- SendGrid (Emails)
- SSE (Real-time notifications)
Create a .env file in the root directory:
PORT=5000
DB_NAME=social_media
HOST=localhost
USER=root
PASSWORD=
CORS_ORIGIN=http://localhost:5173
JWT_ACCESS_TOKEN_SECRET=your_access_secret
JWT_REFRESH_TOKEN_SECRET=your_refresh_secret
JWT_ACCESS_TOKEN_EXPIRY=1h
JWT_REFRESH_TOKEN_EXPIRY=7d
SEND_GRID_API_KEY=your_sendgrid_key
EMAIL_FROM=test@example.com
⚠️ If you do NOT provideSEND_GRID_API_KEY, OTP will be logged in the console.
# Clone repository
git clone https://github.com/imranmalakzai/social-media-platform-backend
# Navigate
cd project-folder
# Install dependencies
npm install
# Run development server
npm run dev
# Run production
npm startServer runs on:
http://localhost:5000
http://localhost:5000/api
POST /auth/register
POST /auth/login
POST /auth/logout
POST /auth/refresh-token
POST /auth/verify-email
POST /auth/forget-password
POST /auth/reset-password
GET /users/me
DELETE /users/me
PATCH /users/me/update-profile
PATCH /users/me/change-password
PATCH /users/me/change-avatar
PATCH /users/me/change-coverimage
GET /users
GET /users/:userId
GET /posts
GET /posts/:postId
POST /users/me/posts
GET /users/me/posts
GET /users/me/posts/:postId
PATCH /users/me/posts/:postId
PATCH /users/me/posts/:postId
PATCH /users/me/posts/:postId/visibility
GET /users/:userId/posts
GET /users/:userId/posts/:postId
POST /likes/post/:postId
GET /likes/post/:postId
POST /posts/:postId/comments
GET /posts/:postId/comments
GET /posts/:postId/comments/:commentId
DELETE /posts/:postId/comments/:commentId
PATCH /posts/:postId/comments/:commentId
POST /users/me/follow/:userId
DELETE /users/me/follow/:userId
GET /users/me/following
GET /users/me/followers
GET /users/:userId/followers
GET /users/:userId/following
GET /me/saved-posts
POST /me/saved-posts/:postId
DELETE /me/saved-posts/:postId
GET /me/saved-posts/:postId
POST /stories
GET /stories
GET /stories/:storyId
DELETE /stories/:storyId
GET /me/notifications/stream
GET /me/notifications
GET /me/notifications/:notificationId
PATCH /me/notifications/read-all
Example:
const eventSource = new EventSource(
"http://localhost:5000/api/me/notifications/stream",
{ withCredentials: true },
);
eventSource.onmessage = (event) => {
console.log(JSON.parse(event.data));
};- Uses Multer
- Supported in:
- Posts (image)
- Avatar
- Cover Image
- Stories
- JWT Authentication
- HTTP-only Cookies
- Rate Limiting
- Input Validation (Zod)
- Global Error Handler
- MVC Pattern
- Event-driven system (listeners)
- Modular routes & controllers
- Middleware-based architecture
Imran Malakzai
This project is designed as a real-world, scalable backend system and is suitable for:
- Learning advanced Node.js concepts
- Portfolio / GitHub showcase
- Production-level API design reference
🔥 If you like this