Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

ย 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

User Management System with Admin Panel ๐Ÿ‘ฅ

A backend system for managing users, profiles, and notifications with real-time capabilities.

Features โœจ

  • 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

Tech Stack ๐Ÿ’ป

  • Backend: Node.js, Express
  • Database: MongoDB
  • Queue: Redis + Bull
  • Auth: JWT Tokens
  • Real-time: WebSocket

Project Structure ๐Ÿ“‚

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

Setup Guide ๐Ÿ› ๏ธ

Prerequisites

  • Node.js & npm
  • MongoDB
  • Redis Server

Environment Variables

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:6379

Environment Variables Description:

  • MONGO_URL: MongoDB connection URL
  • JWT_SECRET: Secret key for JWT tokens
  • ADMIN_SECRET: Special code to create admin users
  • REDIS_URL: Redis server connection URL

Installation

npm install

Running the System

Start server and worker in separate terminals:

Terminal 1 (Main Server):

node index.js

Terminal 2 (Notification Worker):

node worker/notificationQueue.js

API Endpoints ๐Ÿ“ก

Authentication Routes ๐Ÿ”

1. User Signup

POST /api/auth/signup

Request Body:

{
    "email": "user@example.com",
    "password": "password123"
}

Response:

{
    "message": "User created successfully",
    "user": {
        "_id": "65a1b2c3d4e5f6g7h8i9j0k",
        "email": "user@example.com",
        "role": "user"
    },
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}

2. Admin Signup

POST /api/auth/signup-admin

Headers:

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..."
}

3. User Login

POST /api/auth/login

Request Body:

{
    "email": "user@example.com",
    "password": "password123"
}

Response:

{
    "message": "Login successful",
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "user": {
        "_id": "65a1b2c3d4e5f6g7h8i9j0k",
        "email": "user@example.com",
        "role": "user"
    }
}

Profile Management ๐Ÿ‘ค

PATCH /api/profile

Requires 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"
        }
    }
}

Notifications ๐Ÿ””

POST /api/notification

Requires Auth Token

Request Body:

  1. Critical Notification (Admin Only)
{
    "recipients": ["65a1b2c3d4e5f6g7h8i9j0k", "65b2c3d4e5f6g7h8i9j0k1l"],
    "content": "Server maintenance at 2 AM",
    "isCritical": true
}
  1. Critical Notification (Admin Only)
{
    "recipients": ["65a1b2c3d4e5f6g7h8i9j0k", "65b2c3d4e5f6g7h8i9j0k1l"],
    "content": "New feature update!",
    "isCritical": false
}

Response Types:

  1. 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"
    }
}
  1. Normal Notification (Available Users):
{
    "success": true,
    "message": "Notification delivered to Available Users",
    "data": {
        "content": "New feature update!",
        "status": "delivered"
    }
}
  1. Normal Notification (Unavailable Users):
{
    "success": true,
    "message": "Notification queued for unavailable users",
    "data": {
        "content": "Weekly meeting reminder",
        "status": "queued"
    }
}
  1. Error Case:
{
    "success": false,
    "message": "Failed to process notification",
    "error": "Receiver not found"
}

WebSocket Connection ๐Ÿ”Œ

const ws = new WebSocket('ws://localhost:3000?token=eyJhbGci...');

ws.onmessage = (event) => {
    console.log('Received:', JSON.parse(event.data));
};

System Architecture ๐Ÿ—๏ธ

System Architecture

Hosting ๐Ÿš€

Future Improvements ๐Ÿ”ฎ

  • Add Push Notifications/SMS or Email
  • Implement notification history
  • Dashboard for monitoring queues

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages