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.
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββββββ
β Load Balancer β β Frontend β β Backend API β
β (Nginx) ββββββ€ (React) ββββββ€ (Node.js/Express) β
β β β β β β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Docker Network β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ ββββββββββββββ β
β β Worker β β Redis β β Database β β Monitoring β β
β β Services β β (Cache) β β (Azure SQL) β β (Optional) β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ ββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- π 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
- 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
- π³ 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
βββ 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
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
GET /pending-users- List users awaiting approvalGET /all-users- List all users with filteringPOST /approve/:userId- Approve pending userPOST /reject/:userId- Reject pending user with reasonGET /stats- Admin dashboard statistics
GET /- API information and endpointsGET /test-auth- Test authenticationGET /test-admin- Test admin access
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# 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=10See 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- User credentials and profile information
- Status tracking (PENDING/APPROVED/REJECTED)
- Approval workflow metadata
- UserRoles table for role definitions
- UserRoleAssignments for user-role mapping
- Support for Admin, Manager, User roles
- AuditLog for tracking all changes
- EventLog for message queue events
- OnboardingRequests for approval history
- Node.js (v16+) - Download
- Azure SQL Database - Setup Guide
- Azure Service Bus (Optional) - Setup Guide
# 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# 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 buildThe 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]# 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# Start full production stack
docker-compose up -d
# Access the application
# Frontend: http://localhost:3001
# Backend: http://localhost/api
# Load Balancer: http://localhost# 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- Stage 1: Dependencies with build tools
- Stage 2: Application build and testing
- Stage 3: Production runtime with security hardening
- Stage 1: Node.js build environment
- Stage 2: Production nginx server with optimizations
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# 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- Algorithm: Least connections with health checks
- Failover: Automatic backend failure detection
- Rate Limiting: Per-endpoint rate limiting
- SSL Termination: Production HTTPS support
# 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β
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
β
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
// 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.
- Load Balancer:
GET /health - Backend API:
GET /api/health - Frontend:
GET /health
All containers include Docker health checks with:
- Automatic restart on failure
- Configurable intervals and timeouts
- Health status monitoring
# Start with Prometheus & Grafana
docker-compose --profile monitoring up -d
# Access Grafana: http://localhost:3000
# Access Prometheus: http://localhost:9090# 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 '{...}'curl -X POST http://localhost/api/auth/login \
-H "Content-Type: application/json" \
-d '{
"username": "john_doe",
"password": "SecurePass123!"
}'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"}'curl -X GET http://localhost/api/auth/status \
-H "Authorization: Bearer YOUR_JWT_TOKEN"curl -X POST http://localhost/api/auth/refresh-token \
-H "Content-Type: application/json" \
-d '{
"refreshToken": "YOUR_REFRESH_TOKEN"
}'- 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
- 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
- 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
- Health Check:
/healthendpoint for monitoring - Request Logging: Morgan HTTP request logs
- Event Logging: Database event tracking
- Audit Trail: Complete change history
- Error Handling: Structured error responses
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
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
# 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- API Server: Main application
- Worker Service: Background event processing
- Redis: Caching and sessions
- Nginx: Reverse proxy and load balancing
# Production build
docker-compose -f docker-compose.prod.yml up -d- 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
- 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
- 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
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
- Fork the repository
- Create feature branch (
git checkout -b feature/AmazingFeature) - Commit changes (
git commit -m 'Add AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Open Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
# 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- Check Azure SQL firewall rules - Add your IP address
- Verify connection string - Test with Azure Data Studio
- Check environment variables - Ensure
.envfile is properly configured - Test database health:
curl http://localhost/api/health
# 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- 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: Direct access at
http://localhost:3001(backend),http://localhost:3000(frontend) - Production: Load balancer at
http://localhost(all services)
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
- Load Balancer: