queue-it-monorepo
v1.0.2
Published
Production-ready virtual waiting room system with MERN + Next.js + AWS
Readme
Queue-it Style Virtual Waiting Room System
A production-ready virtual waiting room system built with MERN stack, Next.js, and AWS infrastructure.
🏗️ Architecture
- Frontend: Next.js 14 (client app) + React + Vite (admin UI)
- Backend: Node.js 20 + Express + TypeScript
- Database: MongoDB Atlas (persistent data) + Redis/ElastiCache (sessions & queue state)
- Infrastructure: AWS ECS Fargate + ElastiCache + CloudFront + S3
- Realtime: Socket.IO with Redis adapter + SSE fallback
🚀 Quick Start
Prerequisites
- Node.js 20+
- pnpm 8+
- Docker & Docker Compose
- AWS CLI (for deployment)
Local Development
Clone and install dependencies:
git clone <repository> cd queue-it-monorepo pnpm install:allSet up environment variables:
# Root environment (for docker compose and shared config) cp env.example .env # Admin API environment cd apps/admin-api cp env.example .env # Admin UI environment cd ../admin-ui cp env.example .env # Client App environment cd ../client-app cp env.example .env # Queue SDK environment (if developing the package) cd ../../packages/queue-sdk cp env.example .env # Return to root cd ../..Start development environment:
pnpm devThis starts:
- MongoDB on port 27017
- Redis on port 6379
- Admin API on port 4000
- Admin UI on port 5173
- Client App on port 3000
Access applications:
- Admin UI: http://localhost:5173
- Client App: http://localhost:3000
- Admin API: http://localhost:4000
🔧 Environment Configuration
Root Environment (.env)
The root env.example file contains shared configuration for the entire system:
# Database Configuration
MONGODB_URI=mongodb://admin:password@localhost:27017/queueit?authSource=admin
# Redis Configuration
REDIS_URL=redis://:redispassword@localhost:6379
REDIS_PASSWORD=redispassword
# JWT and HMAC Secrets (CHANGE THESE IN PRODUCTION!)
JWT_SECRET=local-jwt-secret-change-in-production
HMAC_SECRET=local-hmac-secret-change-in-production
# Cookie Configuration
COOKIE_DOMAIN=localhost
COOKIE_SECURE=false
# CORS Configuration
CORS_ORIGIN=http://localhost:3000,http://localhost:5173
# Server Configuration
PORT=4000
NODE_ENV=development
# Rate Limiting
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX=100
# Logging
LOG_LEVEL=debug
# Metrics
METRICS_ENABLED=true
METRICS_PORT=9090
# Admin API URLs (for frontend apps)
ADMIN_API_URL=http://localhost:4000
WS_URL=ws://localhost:4000
# Queue Configuration
DEFAULT_QUEUE_ID=limited-sneakersAdmin API Environment (apps/admin-api/.env)
Contains backend-specific configuration:
# Same as root env.example - copy from there
# Database, Redis, JWT, CORS, etc.Admin UI Environment (apps/admin-ui/.env)
Contains frontend admin interface configuration:
# Vite Configuration
VITE_ADMIN_API_URL=http://localhost:4000
VITE_WS_URL=ws://localhost:4000
# Development Server
VITE_DEV_SERVER_PORT=5173
VITE_DEV_SERVER_HOST=localhost
# Build Configuration
VITE_BUILD_OUTPUT_DIR=dist
VITE_BUILD_SOURCEMAP=true
# Feature Flags
VITE_ENABLE_ANALYTICS=false
VITE_ENABLE_DEBUG=trueClient App Environment (apps/client-app/.env)
Contains public-facing app configuration:
# Next.js Configuration
NEXT_PUBLIC_ADMIN_API_URL=http://localhost:4000
NEXT_PUBLIC_WS_URL=ws://localhost:4000
# Development Server
NEXT_PUBLIC_DEV_SERVER_PORT=3000
NEXT_PUBLIC_DEV_SERVER_HOST=localhost
# Build Configuration
NEXT_PUBLIC_BUILD_OUTPUT_DIR=.next
NEXT_PUBLIC_BUILD_SOURCEMAP=true
# Feature Flags
NEXT_PUBLIC_ENABLE_ANALYTICS=false
NEXT_PUBLIC_ENABLE_DEBUG=true
# Queue Configuration
NEXT_PUBLIC_DEFAULT_QUEUE_ID=limited-sneakersQueue SDK Environment (packages/queue-sdk/.env)
Contains SDK development configuration:
# API Configuration
QUEUE_API_URL=http://localhost:4000
QUEUE_WS_URL=ws://localhost:4000
# Authentication
QUEUE_AUTH_ENABLED=true
QUEUE_AUTH_COOKIE_NAME=queue-auth
# Queue Configuration
QUEUE_DEFAULT_TIMEOUT=30000
QUEUE_MAX_RETRIES=3
# Development
QUEUE_DEBUG_ENABLED=true
QUEUE_LOG_LEVEL=infoEnvironment Setup Checklist
- Copy all env.example files to their respective
.envfiles - Update database credentials (MongoDB and Redis passwords)
- Generate secure secrets for JWT and HMAC (use strong random strings)
- Configure CORS origins for your development domains
- Set cookie domain to match your local development setup
- Verify API URLs point to correct local development ports
Production Environment Variables
For production deployment, ensure:
- Strong secrets: Use cryptographically secure random strings
- Secure cookies: Set
COOKIE_SECURE=trueand proper domain - Restricted CORS: Only allow production domains
- Environment: Set
NODE_ENV=production - Logging: Set
LOG_LEVEL=infoorwarn
🐳 Docker Compose Services
- mongodb: MongoDB 7.0 with persistent volume
- redis: Redis 7.2 with persistence
- admin-api: Express API with hot-reload
- admin-ui: Vite dev server
- client-app: Next.js dev server
🏗️ Infrastructure (Terraform)
Prerequisites
- Terraform 1.5+
- AWS CLI configured
- S3 bucket for Terraform state (optional)
Deployment
Configure AWS credentials:
aws configureInitialize Terraform:
cd terraform terraform initConfigure variables:
cp terraform.tfvars.example terraform.tfvars # Edit with your domain, AWS region, etc.Deploy infrastructure:
terraform plan terraform apply
Infrastructure Components
- VPC: 3 AZs with public/private subnets
- ECS: Fargate cluster with admin-api and worker services
- ElastiCache: Redis cluster for sessions and queue state
- ALB: Application Load Balancer with HTTPS termination
- CloudFront: CDN for static assets
- S3: Static hosting and asset storage
- Secrets Manager: Secure credential storage
- Route53: DNS management (optional)
🔄 CI/CD (GitHub Actions)
Workflows
- CI: Lint, typecheck, and test on PRs
- Build & Push: Build Docker images and push to ECR
- Deploy Infrastructure: Terraform plan/apply
- Deploy Apps: Update ECS services
- Deploy Static: Build and deploy frontend apps
GitHub OIDC Setup
Create IAM role for GitHub Actions:
# Use the provided Terraform configuration cd terraform terraform apply -target=module.iamConfigure GitHub repository secrets:
AWS_REGION: Your AWS regionAWS_ROLE_ARN: ARN of the IAM role created above
Update workflow files with your AWS account details
🔐 Security Features
- Secrets Management: AWS Secrets Manager for all sensitive data
- IAM: Least-privilege access with OIDC authentication
- Network Security: VPC with private subnets, security groups
- TLS: ACM certificates with ALB and CloudFront
- Redis Security: AUTH enabled with security groups
📊 Monitoring & Operations
CloudWatch Alarms
- Redis CPU/Memory utilization
- ECS service health
- ALB target health
Prometheus Metrics
- Queue metrics endpoint:
/metrics - Health check:
/healthz
Scaling
- ECS: Auto-scaling based on CPU/Memory
- ElastiCache: Manual scaling with zero-downtime
- ALB: Target group health checks
🧪 Testing
# Run all tests
pnpm test:all
# Run specific app tests
cd apps/admin-api && pnpm test
cd apps/admin-ui && pnpm test
cd apps/client-app && pnpm test
cd packages/queue-sdk && pnpm test📁 Project Structure
├── apps/
│ ├── admin-api/ # Express API server
│ ├── admin-ui/ # React admin dashboard
│ └── client-app/ # Next.js client application
├── packages/
│ └── queue-sdk/ # Shared types and utilities
├── terraform/ # Infrastructure as Code
├── .github/ # GitHub Actions workflows
├── docker compose.yml # Local development
└── README.md # This file🔄 Zero-Downtime Deployments
Application Updates
- Build new Docker image
- Update ECS task definition
- Perform rolling update with health checks
Infrastructure Updates
- Terraform plan to review changes
- Apply changes during maintenance window
- Use blue-green deployment for major changes
Secret Rotation
- Create new secrets in AWS Secrets Manager
- Update ECS task definitions
- Deploy with new secret ARNs
- Remove old secrets after verification
🚨 Troubleshooting
Common Issues
Redis Connection Failed
- Check security groups and subnet configuration
- Verify Redis AUTH credentials in Secrets Manager
ECS Tasks Not Starting
- Check task definition and IAM roles
- Verify secrets and environment variables
Terraform State Lock
- Check DynamoDB lock table (if enabled)
- Force unlock if necessary:
terraform force-unlock <lock-id>
Support
- Check CloudWatch logs for application errors
- Review ECS task logs for container issues
- Monitor ElastiCache metrics for Redis performance
📝 License
MIT License - see LICENSE file for details
🤝 Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
📞 Support
For issues and questions:
- Create a GitHub issue
- Check the troubleshooting section
- Review CloudWatch logs and metrics
