A full-featured social media and real-time chat backend API built with Node.js, Express, TypeScript, and Socket.IO. This API powers a modern social networking platform with features like user authentication, posts, reactions, comments, real-time messaging, notifications, and more.
Chatty Backend is a comprehensive REST API and WebSocket server that provides the backend infrastructure for a social media application. It handles:
- User Management: Registration, authentication, profile management
- Social Features: Posts, reactions (likes), comments, and follower/following relationships
- Real-time Chat: One-on-one messaging with Socket.IO
- Notifications: Real-time notifications for user interactions
- Media Management: Image uploads and storage with Cloudinary integration
- Email Services: Email notifications via SendGrid
- Job Queues: Background job processing with Bull/BullMQ
- Monitoring: API performance monitoring and health checks
- User registration and login with JWT authentication
- Secure session management with encrypted cookies
- Password reset and email verification
- User profiles with customizable avatars
- Create, read, update, and delete posts
- React to posts (likes, love, happy, sad, angry, etc.)
- Comment on posts with nested threading support
- Follow/unfollow other users
- View follower and following lists
- One-on-one chat functionality
- WebSocket-based real-time message delivery
- Message history and conversation lists
- Typing indicators and read receipts
- Real-time notifications for:
- New followers
- Post reactions
- Comments on posts
- New messages
- Mark notifications as read/unread
- Delete notifications
- Upload profile pictures and post images
- Cloudinary integration for cloud storage
- Image optimization and transformation
- Base64 and URL-based uploads
- Runtime: Node.js with TypeScript
- Framework: Express.js
- Database: MongoDB with Mongoose ODM
- Cache/Session Store: Redis
- Real-time: Socket.IO with Redis adapter
- Authentication: JWT (jsonwebtoken)
- Password Hashing: bcryptjs
- Security Headers: Helmet
- CORS: Cross-origin resource sharing
- Session Management: cookie-session
- HTTP Parameter Pollution Protection: hpp
- Request Compression: compression
- Email: SendGrid and Nodemailer
- Cloud Storage: Cloudinary
- Job Queues: Bull and BullMQ with Redis
- Linting: ESLint with TypeScript support
- Formatting: Prettier
- Testing: Jest with ts-jest
- API Monitoring: swagger-stats
- Process Management: PM2
- Logging: Bunyan
- Deployment: AWS (EC2, Load Balancer, Route53, ElastiCache, S3, CodeDeploy)
- IaC: Terraform configurations included
src/
├── app.ts # Application entry point
├── config.ts # Configuration management
├── setupServer.ts # Express server setup
├── setupDatabase.ts # MongoDB connection setup
├── routes.ts # Main route configuration
├── features/ # Feature modules
│ ├── auth/ # Authentication & authorization
│ ├── user/ # User management
│ ├── post/ # Post management
│ ├── reactions/ # Post reactions
│ ├── comments/ # Post comments
│ ├── followers/ # Follow/unfollow functionality
│ ├── chat/ # Real-time messaging
│ ├── notifications/ # User notifications
│ └── images/ # Image uploads
├── shared/ # Shared utilities and helpers
└── mocks/ # Test mocks
Each feature module typically contains:
controllers/- Request handlersroutes/- Route definitionsmodels/- Database schemasschemes/- Validation schemasservices/- Business logicinterfaces/- TypeScript interfaces
- Node.js (v18 or higher recommended)
- MongoDB
- Redis
- Cloudinary account (for image storage)
- SendGrid account (for email services)
- Clone the repository:
git clone <repository-url>
cd chat-api- Install dependencies:
npm install- Set up environment variables:
cp .env.development.example .envEdit .env with your configuration:
DATABASE_URL=mongodb://localhost:27017/chatty_db
JWT_TOKEN=your_jwt_secret
NODE_ENV=development
SECRET_KEY_ONE=your_secret_key_1
SECRET_KEY_TWO=your_secret_key_2
CLIENT_URL=http://localhost:3000
REDIS_HOST=redis://localhost:6379
CLOUD_NAME=your_cloudinary_name
CLOUD_API_KEY=your_cloudinary_key
CLOUD_API_SECRET=your_cloudinary_secret
SENDGRID_API_KEY=your_sendgrid_key
SENDGRID_SENDER=your_email@example.com- Build the project:
npm run build- Start the development server:
npm run devThe API will be available at http://localhost:5080
npm run dev- Start development server with hot reloadnpm run build- Build TypeScript to JavaScriptnpm start- Start production server with PM2npm test- Run tests with coveragenpm run lint:check- Check code for linting errorsnpm run lint:fix- Fix linting errorsnpm run prettier:check- Check code formattingnpm run prettier:fix- Fix code formattingnpm run redis- Start Redis Commander web UI for database managementnpm run seeds:dev- Seed database with test data
POST /api/v1/signup- Register a new userPOST /api/v1/signin- Login userGET /api/v1/signout- Logout user
GET /api/v1/user/all/:page- Get all users (paginated)GET /api/v1/user/profile- Get current user profileGET /api/v1/user/profile/:userId- Get user profile by IDPUT /api/v1/user/profile- Update user profile
GET /api/v1/post/all/:page- Get all posts (paginated)GET /api/v1/post/:postId- Get single postPOST /api/v1/post- Create a new postPUT /api/v1/post/:postId- Update postDELETE /api/v1/post/:postId- Delete post
GET /api/v1/post/reactions/:postId- Get post reactionsPOST /api/v1/post/reaction- Add reaction to postDELETE /api/v1/post/reaction/:postId/:reaction- Remove reaction
GET /api/v1/post/comments/:postId- Get post commentsPOST /api/v1/post/comment- Add comment to postPUT /api/v1/post/comment/:commentId- Update commentDELETE /api/v1/post/comment/:postId/:commentId- Delete comment
GET /api/v1/user/following- Get users you followGET /api/v1/user/followers/:userId- Get user's followersPUT /api/v1/user/follow/:followerId- Follow/unfollow user
GET /api/v1/chat/message/conversation-list- Get conversation listGET /api/v1/chat/message/user/:receiverId- Get messages with userPOST /api/v1/chat/message- Send messageDELETE /api/v1/chat/message/:messageId- Delete message
GET /api/v1/notifications- Get all notificationsPUT /api/v1/notification/:notificationId- Mark as readDELETE /api/v1/notification/:notificationId- Delete notification
GET /api/v1/images/:userId- Get user imagesPOST /api/v1/images/profile- Upload profile imagePOST /api/v1/images/background- Upload background imageDELETE /api/v1/images/:imageId- Delete image
GET /health- Health check endpointGET /env- Environment informationGET /fibo/:num- Fibonacci calculator (for testing)GET /queues- Bull Board queue monitoring UI
The application uses Socket.IO for real-time features:
message- New message receivedmessage read- Message marked as readtyping- User is typing
notification- New notification receivednotification read- Notification marked as read
post created- New post createdpost updated- Post updatedpost deleted- Post deleted
user online- User came onlineuser offline- User went offline
Run the test suite:
npm testThe project uses Jest for testing with coverage reporting. Test files are located alongside the source files with .test.ts extension.
- API Stats: Available at
/api-stats(provided by swagger-stats) - Queue Dashboard: Available at
/queues(Bull Board) - Health Check: Available at
/health
The project includes Terraform configurations for AWS deployment:
- VPC and networking setup
- EC2 instances with Auto Scaling Groups
- Application Load Balancer
- ElastiCache for Redis
- Route53 for DNS
- S3 for storage
- CodeDeploy for CI/CD
See the deployment/ directory for infrastructure as code.
- JWT-based authentication
- Encrypted session cookies
- Password hashing with bcrypt
- HTTP security headers (Helmet)
- CORS protection
- HPP (HTTP Parameter Pollution) protection
- Request validation and sanitization
- Rate limiting via API gateway
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and linting
- Submit a pull request
ISC
DevGbolade
For issues, questions, or contributions, please open an issue on GitHub.