Skip to content

rohank-dev/user-onboarding-approval-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

User Onboarding Approval System

Node.js React Docker Azure License GitHub Copilot

A production-ready, horizontally scalable user onboarding system with admin approval workflows, built with Node.js/Express backend and React frontend.

🎯 Built entirely with GitHub Copilot - See COPILOT_PROJECT_CREATION_GUIDE.md for the complete AI-assisted development process.

πŸ—οΈ Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Load Balancer β”‚    β”‚     Frontend     β”‚    β”‚      Backend API    β”‚
β”‚     (Nginx)     │◄────     (React)      │◄────   (Node.js/Express) β”‚
β”‚                 β”‚    β”‚                  β”‚    β”‚                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                       β”‚                        β”‚
         β–Ό                       β–Ό                        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                          Docker Network                             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚   Worker    β”‚  β”‚    Redis    β”‚  β”‚  Database   β”‚  β”‚ Monitoring β”‚ β”‚
β”‚  β”‚  Services   β”‚  β”‚   (Cache)   β”‚  β”‚ (Azure SQL) β”‚  β”‚ (Optional) β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🎯 Key Features

Full-Stack Application

  • πŸ” JWT Authentication with refresh tokens and role-based access
  • πŸ‘₯ Admin Approval Workflow for user registrations
  • πŸ“Š Real-time Dashboard with statistics and user management
  • πŸ“§ Email Notifications via Azure Service Bus integration
  • πŸ”„ Horizontal Scaling with load balancing and stateless design

Security & Performance

  • bcrypt Password Hashing (12 salt rounds)
  • Rate Limiting with configurable limits per endpoint
  • CORS Protection with configurable origins
  • Security Headers via Helmet.js and nginx
  • Input Validation with comprehensive schemas
  • SQL Injection Protection via parameterized queries

Production Ready

  • 🐳 Docker Containers with multi-stage builds
  • βš–οΈ Load Balancing with nginx upstream servers
  • πŸ“ˆ Horizontal Scaling tested with automated scripts
  • πŸ›‘οΈ Security Hardened containers with non-root users
  • πŸ” Azure Key Vault integration for secrets management
  • πŸ“Š Health Checks and monitoring integration

πŸ—οΈ Architecture

β”œβ”€β”€ app.js                    # Main Express application
β”œβ”€β”€ worker.js                # Queue worker service entry point
β”œβ”€β”€ healthcheck.js           # Docker health check
β”œβ”€β”€ config/
β”‚   └── database.js          # Azure SQL Database configuration
β”œβ”€β”€ controllers/
β”‚   └── userController.js    # User management logic
β”œβ”€β”€ middleware/
β”‚   └── index.js            # Authentication & security middleware
β”œβ”€β”€ routes/
β”‚   β”œβ”€β”€ auth.js             # Authentication endpoints
β”‚   β”œβ”€β”€ admin.js            # Admin-only endpoints
β”‚   β”œβ”€β”€ api.js              # General API endpoints
β”‚   └── index.js            # Home routes
β”œβ”€β”€ services/
β”‚   └── messageQueueService.js # Azure Service Bus integration
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ jwtUtils.js         # JWT token utilities
β”‚   └── passwordUtils.js    # Password hashing utilities
β”œβ”€β”€ workers/
β”‚   └── onboardingWorker.js # Background event processor
└── sql/
    └── schema.sql          # Database schema

πŸ“‹ API Endpoints

Authentication (/api/auth)

  • POST /register - User registration (creates PENDING user)
  • POST /login - User authentication (APPROVED users only)
  • GET /status - Get user onboarding status (authenticated)
  • GET /profile - Get user profile (authenticated)
  • POST /refresh-token - Refresh JWT tokens

Admin (/api/admin) - Admin Only

  • GET /pending-users - List users awaiting approval
  • GET /all-users - List all users with filtering
  • POST /approve/:userId - Approve pending user
  • POST /reject/:userId - Reject pending user with reason
  • GET /stats - Admin dashboard statistics

General (/api)

  • GET / - API information and endpoints
  • GET /test-auth - Test authentication
  • GET /test-admin - Test admin access

πŸ”§ Environment Configuration

Required Variables

See .env.example for the complete configuration reference.

# Database (Azure SQL)
DB_SERVER=your-server.database.windows.net
DB_DATABASE=UserOnboardingDB
DB_USERNAME=your-username
DB_PASSWORD=your-secure-password
DB_ENCRYPT=true

# JWT Security (Stateless Multi-Instance)
JWT_SECRET=your-super-secure-jwt-secret-key-minimum-32-characters
JWT_REFRESH_SECRET=your-super-secure-refresh-secret-key-minimum-32-characters
JWT_EXPIRES_IN=15m
JWT_REFRESH_EXPIRES_IN=7d
JWT_ALGORITHM=HS256
JWT_ISSUER=user-onboarding-system
JWT_AUDIENCE=user-onboarding-api

# Azure Service Bus (Message Queue)
AZURE_SERVICE_BUS_CONNECTION_STRING=Endpoint=sb://your-namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=your-key
ONBOARDING_QUEUE_NAME=onboarding-events

Multi-Instance Configuration

# Application Instance
NODE_ENV=production
PORT=3001
INSTANCE_ID=api-instance-1

# Stateless JWT Features
JWT_INCLUDE_INSTANCE_ID=true
JWT_INCLUDE_SESSION_ID=true
JWT_INCLUDE_USER_AGENT=true

# Message Queue Features
MESSAGE_QUEUE_ENABLED=true
MESSAGE_QUEUE_MAX_RETRIES=3
MESSAGE_QUEUE_BATCH_SIZE=10

Frontend Configuration

See frontend/.env for React app configuration:

# Frontend Environment (frontend/.env)
VITE_API_URL=http://localhost:3000
VITE_API_TIMEOUT=10000
VITE_APP_NAME=User Onboarding System

# Feature Flags
VITE_ENABLE_REGISTRATION=true
VITE_ENABLE_ADMIN_FEATURES=true
VITE_ENABLE_USER_STATUS=true

# Security Configuration
VITE_JWT_STORAGE_KEY=uo_auth_token
VITE_REFRESH_TOKEN_KEY=uo_refresh_token

πŸ—„οΈ Database Schema

Users Table

  • User credentials and profile information
  • Status tracking (PENDING/APPROVED/REJECTED)
  • Approval workflow metadata

Role Management

  • UserRoles table for role definitions
  • UserRoleAssignments for user-role mapping
  • Support for Admin, Manager, User roles

Audit & Events

  • AuditLog for tracking all changes
  • EventLog for message queue events
  • OnboardingRequests for approval history

πŸš€ Quick Start

Prerequisites

  1. Node.js (v16+) - Download
  2. Azure SQL Database - Setup Guide
  3. Azure Service Bus (Optional) - Setup Guide

Installation

# Install backend dependencies
npm install

# Install frontend dependencies
cd frontend && npm install && cd ..

# Set up environment variables
cp .env.example .env
cp frontend/.env.example frontend/.env
# Edit .env files with your configuration

# Set up database
# Run sql/schema.sql in your Azure SQL Database

# Start development server
npm run dev

# Or start production server
npm start

πŸ§ͺ Testing & Validation

Available Scripts

# Backend Scripts (package.json)
npm start                    # Production mode
npm run dev                  # Development with nodemon
npm test                     # Run tests (placeholder)

# Frontend Scripts (frontend/package.json)
cd frontend
npm start                    # Development server
npm run build                # Production build
npm run preview              # Preview production build

Automated Testing Scripts

The project includes comprehensive testing scripts for deployment validation:

# Complete system test (Linux/Mac)
chmod +x scripts/test-complete-deployment.sh
./scripts/test-complete-deployment.sh

# Horizontal scaling test
./scripts/test-horizontal-scaling.sh [backends] [workers] [duration] [requests]
# Example: ./scripts/test-horizontal-scaling.sh 5 3 60 20

# Windows equivalents
scripts\test-complete-deployment.bat
scripts\test-horizontal-scaling.bat [backends] [workers] [duration] [requests]

Health Check Validation

# Service health checks
curl http://localhost/health              # Load balancer
curl http://localhost/api/health          # Backend API  
curl http://localhost:3001/health         # Frontend (nginx)

# Database connectivity test
curl http://localhost/api/health          # Includes DB status

Docker Deployment

Production with Load Balancer

# Start full production stack
docker-compose up -d

# Access the application
# Frontend: http://localhost:3001
# Backend: http://localhost/api
# Load Balancer: http://localhost

Development Mode

# Start with local database
docker-compose --profile local-dev up -d

# Or individual services
docker build -t user-onboarding-api .
docker run -p 3000:3000 --env-file .env user-onboarding-api

🐳 Docker Architecture

Multi-Stage Dockerfiles

Backend (Node.js)

  • Stage 1: Dependencies with build tools
  • Stage 2: Application build and testing
  • Stage 3: Production runtime with security hardening

Frontend (React)

  • Stage 1: Node.js build environment
  • Stage 2: Production nginx server with optimizations

Service Architecture

services:
  load-balancer:    # Nginx with upstream load balancing
  backend:          # Scalable Node.js API servers
  frontend:         # React app with nginx
  worker:           # Background job processing
  redis:            # Session storage and caching

βš–οΈ Horizontal Scaling

Automatic Scaling

# Scale backend to 5 instances
docker-compose up -d --scale backend=5

# Scale workers to 3 instances  
docker-compose up -d --scale worker=3

# Use predefined scaling configuration
docker-compose -f docker-compose.yml -f docker-compose.scale.yml up -d

Load Balancer Features

  • Algorithm: Least connections with health checks
  • Failover: Automatic backend failure detection
  • Rate Limiting: Per-endpoint rate limiting
  • SSL Termination: Production HTTPS support

Scaling Tests

# Run automated scaling tests (Linux/Mac)
./scripts/test-horizontal-scaling.sh 5 3 60 20

# Run on Windows
.\scripts\test-horizontal-scaling.bat 5 3 60 20

Stateless JWT Features

βœ… Unique Token IDs (JTI): Each token has a unique identifier for tracking
βœ… Instance Tracking: Tokens include instance ID for multi-instance support
βœ… Session Management: Session IDs for coordinated logout across instances
βœ… Security Claims: User agent, IP address validation for enhanced security
βœ… Token Blacklisting: Revocation support with automatic cleanup
βœ… Refresh Token Support: Separate secrets and validation for refresh tokens

Statelessness Verification

βœ… JWT Tokens: No server-side sessions, stateless validation
βœ… Database State: All persistent state in Azure SQL Database
βœ… Redis Cache: Shared cache across instances for performance
βœ… Environment Config: All configuration via environment variables
βœ… Multi-Instance Ready: Load balancer distributes across multiple instances

πŸ” Secrets Management

Azure Key Vault Integration

// Automatic secret loading from Key Vault
const secrets = await keyVaultService.getSecrets([
  'db-password', 'jwt-secret', 'smtp-credentials'
]);

Features:

  • Centralized secret storage
  • Automatic secret rotation
  • Managed identity authentication
  • Fallback to environment variables
  • Audit logging and monitoring

See docs/AZURE_KEY_VAULT.md for setup guide.

πŸ“Š Monitoring & Health Checks

Service Health Endpoints

  • Load Balancer: GET /health
  • Backend API: GET /api/health
  • Frontend: GET /health

Container Health Checks

All containers include Docker health checks with:

  • Automatic restart on failure
  • Configurable intervals and timeouts
  • Health status monitoring

Optional Monitoring Stack

# Start with Prometheus & Grafana
docker-compose --profile monitoring up -d

# Access Grafana: http://localhost:3000
# Access Prometheus: http://localhost:9090

πŸ“ Usage Examples

User Registration

# Via load balancer (production)
curl -X POST http://localhost/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "username": "john_doe",
    "email": "[email protected]",
    "password": "SecurePass123!",
    "firstName": "John",
    "lastName": "Doe"
  }'

# Direct to backend (development)
curl -X POST http://localhost:3001/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{...}'

User Login (After Approval)

curl -X POST http://localhost/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "username": "john_doe",
    "password": "SecurePass123!"
  }'

Admin: Approve User

curl -X POST http://localhost/api/admin/approve/1 \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"reason": "All requirements met"}'

Check Status

curl -X GET http://localhost/api/auth/status \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Token Refresh

curl -X POST http://localhost/api/auth/refresh-token \
  -H "Content-Type: application/json" \
  -d '{
    "refreshToken": "YOUR_REFRESH_TOKEN"
  }'

πŸ”’ Security Features

Authentication & Authorization

  • Enhanced JWT Tokens: Stateless with unique IDs, instance tracking, session management
  • Dual Token System: Short-lived access tokens (15min) + refresh tokens (7 days)
  • Token Blacklisting: Revocation support with automatic cleanup
  • Password Security: bcrypt hashing (12 salt rounds), strong requirements
  • Role-Based Access: Middleware enforcement with Admin, Manager, User roles
  • Multi-Instance Security: Session coordination across horizontally scaled instances

Input Validation & Protection

  • Joi Schema Validation: Comprehensive input validation for all endpoints
  • SQL Injection Protection: Parameterized queries with mssql library
  • XSS Protection: Helmet.js security headers and input sanitization
  • Rate Limiting: Configurable limits per endpoint type (auth, admin, general)
  • CORS Configuration: Strict origin validation and preflight handling

Infrastructure Security

  • Docker Security: Non-root containers, multi-stage builds, minimal attack surface
  • Secrets Management: Azure Key Vault integration with environment fallback
  • Network Security: Load balancer SSL termination, internal network isolation
  • Audit Logging: Complete change tracking and security event monitoring

πŸ“Š Monitoring & Logging

  • Health Check: /health endpoint for monitoring
  • Request Logging: Morgan HTTP request logs
  • Event Logging: Database event tracking
  • Audit Trail: Complete change history
  • Error Handling: Structured error responses

πŸ”„ Message Queue Integration

Azure Service Bus Implementation

The system uses Azure Service Bus for decoupled workflow processing with automatic fallback to local queues for development.

Published Events:

  • User Registration: New user signup events
  • Approval/Rejection: Admin decision notifications
  • Password Reset: Security-related password change requests
  • Audit Events: System security and compliance events
  • Session Events: Login/logout tracking across instances

Queue Processing Features:

  • Automatic Retry: Configurable retry attempts with exponential backoff
  • Dead Letter Queue: Failed message handling for manual review
  • Batch Processing: Efficient message batching for high throughput
  • Local Fallback: Development mode with in-memory queue simulation
  • Message Persistence: Durable message storage with TTL support

Worker Service Architecture

Background worker service (workers/onboardingWorker.js) processes events for:

  • Email Notifications: User status updates and admin alerts
  • Audit Logging: Security events and compliance tracking
  • Workspace Setup: Automated resource provisioning
  • External Integrations: Third-party system notifications
  • Analytics Events: Usage tracking and reporting data

Queue Configuration

# Message Queue Settings
MESSAGE_QUEUE_ENABLED=true
MESSAGE_QUEUE_MAX_RETRIES=3
MESSAGE_QUEUE_RETRY_DELAY=5000
MESSAGE_QUEUE_BATCH_SIZE=10
ONBOARDING_QUEUE_NAME=onboarding-events

🐳 Docker Support

Multi-service Setup

  • API Server: Main application
  • Worker Service: Background event processing
  • Redis: Caching and sessions
  • Nginx: Reverse proxy and load balancing

Production Deployment

# Production build
docker-compose -f docker-compose.prod.yml up -d

πŸ“ˆ Scalability

  • Stateless Design: JWT tokens eliminate session storage needs
  • Database Connection Pooling: Efficient Azure SQL connectivity
  • Message Queue: Decoupled event processing
  • Container Ready: Kubernetes/Docker Swarm compatible
  • Horizontal Scaling: Load balancer ready

πŸ“Š Project Status

βœ… Completed Features

  • User Registration & Approval Workflow: Full implementation with PENDING/APPROVED/REJECTED states
  • JWT Authentication System: Stateless multi-instance support with refresh tokens
  • Role-Based Access Control: Admin, Manager, User roles with middleware enforcement
  • React Frontend: Complete admin UI for user management and approval workflow
  • Docker Containerization: Multi-stage builds, load balancing, horizontal scaling
  • Azure SQL Integration: Database schema, connection pooling, health checks
  • Message Queue System: Azure Service Bus integration with local fallback
  • Security Implementation: Input validation, password hashing, rate limiting, CORS
  • Monitoring & Health Checks: Service health endpoints, Docker health checks
  • Secrets Management: Azure Key Vault integration with environment fallback
  • Comprehensive Documentation: API docs, deployment guides, environment configuration

πŸ”„ Recently Enhanced

  • Stateless JWT Features: Unique token IDs, instance tracking, session management
  • Enhanced Security: Token blacklisting, user agent validation, IP tracking
  • Message Queue Integration: Event-driven architecture for workflow decoupling
  • Horizontal Scaling: Load balancer configuration, automated scaling tests

🎯 Production Ready

The application is fully production-ready with:

  • Security Hardened: All OWASP recommendations implemented
  • Horizontally Scalable: Tested with multiple backend instances
  • Monitoring Ready: Health checks, logging, audit trails
  • Cloud Native: Azure SQL, Service Bus, Key Vault integration
  • DevOps Ready: Complete Docker setup, environment management

🀝 Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/AmazingFeature)
  3. Commit changes (git commit -m 'Add AmazingFeature')
  4. Push to branch (git push origin feature/AmazingFeature)
  5. Open Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ”§ Troubleshooting

Common Issues

Installation Problems

# If npm install fails, clear cache and retry
npm cache clean --force
rm -rf node_modules package-lock.json
npm install

# For frontend issues
cd frontend
npm cache clean --force  
rm -rf node_modules package-lock.json
npm install

Database Connection Issues

  1. Check Azure SQL firewall rules - Add your IP address
  2. Verify connection string - Test with Azure Data Studio
  3. Check environment variables - Ensure .env file is properly configured
  4. Test database health: curl http://localhost/api/health

Docker Issues

# If containers fail to start
docker-compose down -v
docker system prune -f
docker-compose up -d

# Check container logs
docker-compose logs backend
docker-compose logs frontend
docker-compose logs worker

Load Balancer Issues

  • Port conflicts: Ensure ports 80, 3001 are available
  • Backend not responding: Check backend health at http://localhost:3001/api/health
  • Frontend 404 errors: Verify nginx routing in nginx/load-balancer.conf

Development vs Production URLs

  • Development: Direct access at http://localhost:3001 (backend), http://localhost:3000 (frontend)
  • Production: Load balancer at http://localhost (all services)

πŸ†˜ Support

For support and questions:

  • Create an issue in the repository
  • Check the API documentation (via load balancer)
  • Review health check endpoints:
    • Load Balancer: http://localhost/health
    • Backend API: http://localhost/api/health
    • Frontend: http://localhost:3001/health

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published