A backend system for managing users, profiles, and notifications with real-time capabilities.
- User signup/login (email + password)
- Profile management (name, bio, availability slots)
- Notifications system with critical/normal priority
- Admin privileges for special operations
- Real-time notifications using WebSocket
- Redis-based queue for offline users
- Workers for Scheduled Jobs
- Backend: Node.js, Express
- Database: MongoDB
- Queue: Redis + Bull
- Auth: JWT Tokens
- Real-time: WebSocket
backend/
โโโ worker/
โ โโโ notificationQueue.js
โ
โโโ routes/
โ โโโ authRoute.js
โ โโโ profileRoute.js
โ โโโ notificationRoute.js
โ
โโโ config/
โ โโโ db.js
โ
โโโ docs/
โ โโโ architecture.png
โ
โโโ controllers/
โ โโโ authController.js
โ โโโ profileController.js
โ โโโ notificationController.js
โ
โโโ helper/
โ โโโ checkAvailability.js
โ
โโโ models/
โ โโโ user.js
โ โโโ profile.js
โ โโโ notification.js
โ
โโโ ws/
โ โโโ websocket.js
โ
โโโ models/
โ โโโ User.js
โ โโโ Profile.js
โ โโโ Notification.js
โ
โโโ validator.js
โโโ index.js
- Node.js & npm
- MongoDB
- Redis Server
Create .env file in root directory:
MONGO_URL=mongodb://localhost:27017/user-management
JWT_SECRET=your_jwt_secret_here
ADMIN_SECRET=super_secret_admin_code
REDIS_URL=redis://localhost:6379Environment Variables Description:
MONGO_URL: MongoDB connection URLJWT_SECRET: Secret key for JWT tokensADMIN_SECRET: Special code to create admin usersREDIS_URL: Redis server connection URL
npm installStart server and worker in separate terminals:
Terminal 1 (Main Server):
node index.jsTerminal 2 (Notification Worker):
node worker/notificationQueue.jsPOST /api/auth/signupRequest Body:
{
"email": "user@example.com",
"password": "password123"
}Response:
{
"message": "User created successfully",
"user": {
"_id": "65a1b2c3d4e5f6g7h8i9j0k",
"email": "user@example.com",
"role": "user"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}POST /api/auth/signup-adminHeaders:
admin: your_admin_secret
Request Body:
{
"email": "admin@company.com",
"password": "admin123"
}Response:
{
"message": "User created successfully",
"user": {
"_id": "65a1b2c3d4e5f6g7h8i9j0k",
"email": "admin@company.com",
"role": "admin"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}POST /api/auth/loginRequest Body:
{
"email": "user@example.com",
"password": "password123"
}Response:
{
"message": "Login successful",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"_id": "65a1b2c3d4e5f6g7h8i9j0k",
"email": "user@example.com",
"role": "user"
}
}PATCH /api/profileRequires Auth Token
Request Body:
{
"name": "Demo1",
"number": "9876543210",
"bio": "Project Head",
"availability": {
"startTime": "09:00",
"endTime": "10:00"
}
}Note: Times are converted to UTC before saving in DB
Response:
{
"message": "Profile updated successfully",
"profile": {
"userId": "65a1b2c3d4e5f6g7h8i9j0k",
"name": "Demo1",
"availability": {
"startTime": "03:30",
"endTime": "4:30"
}
}
}POST /api/notificationRequires Auth Token
Request Body:
- Critical Notification (Admin Only)
{
"recipients": ["65a1b2c3d4e5f6g7h8i9j0k", "65b2c3d4e5f6g7h8i9j0k1l"],
"content": "Server maintenance at 2 AM",
"isCritical": true
}- Critical Notification (Admin Only)
{
"recipients": ["65a1b2c3d4e5f6g7h8i9j0k", "65b2c3d4e5f6g7h8i9j0k1l"],
"content": "New feature update!",
"isCritical": false
}Response Types:
- Critical Notification (Admin Only):
{
"success": true,
"message": "Notification delivered to Online and Queued for Offline",
"data": {
"content": "Server maintenance at 2 AM",
"status": "delivered Instantly"
}
}- Normal Notification (Available Users):
{
"success": true,
"message": "Notification delivered to Available Users",
"data": {
"content": "New feature update!",
"status": "delivered"
}
}- Normal Notification (Unavailable Users):
{
"success": true,
"message": "Notification queued for unavailable users",
"data": {
"content": "Weekly meeting reminder",
"status": "queued"
}
}- Error Case:
{
"success": false,
"message": "Failed to process notification",
"error": "Receiver not found"
}const ws = new WebSocket('ws://localhost:3000?token=eyJhbGci...');
ws.onmessage = (event) => {
console.log('Received:', JSON.parse(event.data));
};- Hosted on Render (free tier)
- Worker process runs as separate background service
- Live URL: your-render-app.onrender.com
- Add Push Notifications/SMS or Email
- Implement notification history
- Dashboard for monitoring queues
