A full-stack social media API built with NestJS, supporting MySQL for core data and MongoDB for notifications, with real-time notification delivery using WebSockets.
- User authentication & authorization
- Posts, comments, likes, follows, tags, and profiles
- File uploads with Cloudinary
- Notifications stored in MongoDB
- Real-time notifications via WebSockets (Socket.IO)
- Message queuing with Bull/Redis
- Modular, scalable codebase
- Backend: NestJS, TypeORM
- Databases: MySQL (main data), MongoDB (notifications)
- Real-time: WebSockets (Socket.IO)
- Queue System: Bull/Redis
- Cloud Storage: Cloudinary
pnpm installThe project includes Docker configuration for easy setup and consistent environments.
-
Prerequisites:
- Docker
- Docker Compose (included with Docker Desktop)
-
Starting the application:
# Start all services
docker-compose up
# Run in background
docker-compose up -d
# Build and start (after code changes)
docker-compose up --buildThis will start the following services:
- NestJS application (API)
- MySQL database
- MongoDB
- Redis (for Bull queue)
- NATS (message broker)
- Stopping the application:
docker-compose down
# To remove volumes as well (will delete data)
docker-compose down -vCreate a .env file in the root directory:
# MySQL Database
DB_USERNAME=your_mysql_user
DB_PASSWORD=your_mysql_password
DB_NAME=social_media
DB_HOST=localhost
# MongoDB Database
MG_DBNAME=social_media_mongo
MG_HOST=localhost
# Cloudinary
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret
# Redis (for Bull Queue)
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
# Bull Board Admin
ADMIN_USER=admin
ADMIN_PASSWORD=securepasswordWhen using Docker, the database hosts will be the service names:
DB_HOST=mysql
MG_HOST=mongodb
REDIS_HOST=redis
# development
pnpm run start
# watch mode
pnpm run start:dev
# production mode
pnpm run start:prod# Development mode
docker-compose up- API: http://localhost:3000
- API Documentation: http://localhost:3000/api
- Bull Board (Queue Monitor): http://localhost:3000/admin/queues
- Default credentials: admin/password (configurable in .env)
- The API uses Socket.IO for real-time notifications.
- Clients should connect with authentication:
import { io } from "socket.io-client";
const socket = io('http://localhost:3000/notifications', {
auth: { token: 'YOUR_JWT_TOKEN' }
});
socket.on('notification', (notification) => {
// handle new notification
});
socket.on('unread_count', (data) => {
// update notification badge with data.count
});# View container logs
docker-compose logs -f api
# Access shell in container
docker-compose exec api sh
# Run tests
docker-compose exec api pnpm test
# Rebuild a specific service
docker-compose up -d --no-deps --build api# unit tests
pnpm run test
# e2e tests
pnpm run test:e2e
# test coverage
pnpm run test:cov- Configure production environment variables
- Run with production compose file:
docker-compose -f docker-compose.prod.yml up -dFor cloud deployments, see NestJS deployment docs.
MIT