This guide covers deploying VIJ Admin to production environments, including Vercel, Docker, and self-hosted infrastructure.
Deployment Options
Vercel One-click deployment with zero configuration
Docker Containerized deployment for any infrastructure
Self-Hosted Deploy on your own servers with full control
Deploy to Vercel
Vercel provides the easiest deployment path for Next.js applications.
Prepare your repository
Ensure your VIJ Admin code is in a Git repository (GitHub, GitLab, or Bitbucket): # If not already a git repo
git init
git add .
git commit -m "Initial commit"
# Push to GitHub
git remote add origin https://github.com/yourusername/vij-admin.git
git push -u origin main
Connect to Vercel
Go to vercel.com and sign in
Click Add New Project
Import your VIJ Admin repository
Select the repository and click Import
Configure environment variables
In the Vercel project settings, add environment variables: Required Variables :MONGODB_URI = your_mongodb_connection_string
NEXT_PUBLIC_BASE_URL = https://your-project.vercel.app
Optional Variables :GEMINI_API_KEY = your_gemini_api_key
Use MongoDB Atlas or another cloud MongoDB provider. Vercel cannot connect to localhost.
Deploy
Click Deploy and wait for the build to complete. Your VIJ Admin dashboard will be live at https://your-project.vercel.app
Configure custom domain (optional)
Go to Settings → Domains
Add your custom domain (e.g., vij.yourdomain.com)
Update DNS records as instructed
Update NEXT_PUBLIC_BASE_URL environment variable
NEXT_PUBLIC_BASE_URL = https://vij.yourdomain.com
Vercel Configuration
Create vercel.json for advanced configuration:
{
"buildCommand" : "npm run build" ,
"devCommand" : "npm run dev" ,
"installCommand" : "npm install" ,
"framework" : "nextjs" ,
"regions" : [ "iad1" ],
"env" : {
"MONGODB_URI" : "@mongodb-uri" ,
"GEMINI_API_KEY" : "@gemini-api-key"
}
}
Vercel Environment Variables
MongoDB Atlas connection string. Example :mongodb+srv://username:password@cluster.mongodb.net/vij?retryWrites = true & w = majority
Getting Started with MongoDB Atlas :
Create free account at mongodb.com/atlas
Create a cluster (free tier available)
Add Vercel IP addresses to IP whitelist (or use 0.0.0.0/0 for all IPs)
Create database user
Get connection string
Your Vercel deployment URL. # Auto-assigned Vercel URL
NEXT_PUBLIC_BASE_URL = https://your-project.vercel.app
# Custom domain
NEXT_PUBLIC_BASE_URL = https://vij.yourdomain.com
Vercel automatically redeploys on every push to your main branch. Use preview deployments for testing.
Docker Deployment
Deploy VIJ Admin using Docker for consistent, portable deployments.
Dockerfile
Create a Dockerfile in your project root:
# Build stage
FROM node:20-alpine AS builder
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install dependencies
RUN npm ci
# Copy source code
COPY . .
# Build Next.js app
RUN npm run build
# Production stage
FROM node:20-alpine AS runner
WORKDIR /app
# Set production environment
ENV NODE_ENV=production
# Create non-root user
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Copy built application
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
# Change ownership
RUN chown -R nextjs:nodejs /app
# Switch to non-root user
USER nextjs
# Expose port
EXPOSE 3000
# Set hostname
ENV HOSTNAME= "0.0.0.0"
# Start application
CMD [ "node" , "server.js" ]
Docker Compose
Create docker-compose.yml for local development or deployment:
version : '3.8'
services :
vij-admin :
build : .
ports :
- "3000:3000"
environment :
- MONGODB_URI=mongodb://mongo:27017/vij
- NEXT_PUBLIC_BASE_URL=http://localhost:3000
- GEMINI_API_KEY=${GEMINI_API_KEY}
depends_on :
- mongo
restart : unless-stopped
mongo :
image : mongo:7
ports :
- "27017:27017"
volumes :
- mongo-data:/data/db
restart : unless-stopped
volumes :
mongo-data :
Build and Run
Build Docker image
docker build -t vij-admin:latest .
Run with Docker Compose
# Create .env file
echo "GEMINI_API_KEY=your_key_here" > .env
# Start services
docker-compose up -d
View logs
# View all logs
docker-compose logs -f
# View VIJ Admin logs only
docker-compose logs -f vij-admin
Stop services
docker-compose down
# Remove volumes (deletes data)
docker-compose down -v
Production Docker Deployment
For production, use environment-specific compose files:
version : '3.8'
services :
vij-admin :
image : vij-admin:latest
ports :
- "3000:3000"
environment :
- MONGODB_URI=${MONGODB_URI}
- NEXT_PUBLIC_BASE_URL=${NEXT_PUBLIC_BASE_URL}
- GEMINI_API_KEY=${GEMINI_API_KEY}
restart : always
healthcheck :
test : [ "CMD" , "curl" , "-f" , "http://localhost:3000/api/logs" ]
interval : 30s
timeout : 10s
retries : 3
Deploy:
docker-compose -f docker-compose.prod.yml up -d
Self-Hosted Deployment
Deploy VIJ Admin on your own infrastructure.
Prerequisites
Node.js 18+ installed
MongoDB 5.0+ running
Nginx or Apache for reverse proxy (recommended)
PM2 or systemd for process management
Deployment Steps
Prepare the server
# Update system
sudo apt update && sudo apt upgrade -y
# Install Node.js 20
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
# Install MongoDB
# See: https://www.mongodb.com/docs/manual/installation/
# Install PM2
sudo npm install -g pm2
Clone and build
# Clone repository
git clone https://github.com/asengupta07/vij-admin.git
cd vij-admin
# Install dependencies
npm ci --production
# Create environment file
cat > .env.local << EOF
MONGODB_URI=mongodb://localhost:27017/vij
NEXT_PUBLIC_BASE_URL=https://vij.yourdomain.com
GEMINI_API_KEY=your_api_key
EOF
# Build application
npm run build
Start with PM2
# Start application
pm2 start npm --name "vij-admin" -- start
# Save PM2 configuration
pm2 save
# Setup PM2 to start on boot
pm2 startup
VIJ Admin is now running on port 3000
Configure Nginx reverse proxy
Create Nginx configuration: /etc/nginx/sites-available/vij-admin
server {
listen 80 ;
server_name vij.yourdomain.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1 ;
proxy_set_header Upgrade $ http_upgrade ;
proxy_set_header Connection 'upgrade' ;
proxy_set_header Host $ host ;
proxy_cache_bypass $ http_upgrade ;
proxy_set_header X-Real-IP $ remote_addr ;
proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for ;
proxy_set_header X-Forwarded-Proto $ scheme ;
}
}
Enable site: sudo ln -s /etc/nginx/sites-available/vij-admin /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
Setup SSL with Certbot
# Install Certbot
sudo apt install certbot python3-certbot-nginx
# Get SSL certificate
sudo certbot --nginx -d vij.yourdomain.com
# Auto-renewal is configured automatically
Your VIJ Admin is now accessible at https://vij.yourdomain.com
PM2 Configuration
Create ecosystem.config.js:
module . exports = {
apps: [{
name: 'vij-admin' ,
script: 'npm' ,
args: 'start' ,
cwd: '/path/to/vij-admin' ,
instances: 2 ,
exec_mode: 'cluster' ,
env: {
NODE_ENV: 'production' ,
PORT: 3000
},
error_file: '/var/log/vij-admin/error.log' ,
out_file: '/var/log/vij-admin/out.log' ,
log_date_format: 'YYYY-MM-DD HH:mm:ss Z' ,
merge_logs: true ,
autorestart: true ,
max_memory_restart: '1G'
}]
};
Start with configuration:
pm2 start ecosystem.config.js
Systemd Service (Alternative to PM2)
Create systemd service file:
/etc/systemd/system/vij-admin.service
[Unit]
Description =VIJ Admin Dashboard
After =network.target mongodb.service
[Service]
Type =simple
User =www-data
WorkingDirectory =/var/www/vij-admin
Environment = NODE_ENV =production
EnvironmentFile =/var/www/vij-admin/.env.local
ExecStart =/usr/bin/npm start
Restart =always
RestartSec =10
[Install]
WantedBy =multi-user.target
Enable and start:
sudo systemctl enable vij-admin
sudo systemctl start vij-admin
sudo systemctl status vij-admin
Kubernetes Deployment
Deploy VIJ Admin on Kubernetes clusters.
Kubernetes Manifests
apiVersion : apps/v1
kind : Deployment
metadata :
name : vij-admin
labels :
app : vij-admin
spec :
replicas : 3
selector :
matchLabels :
app : vij-admin
template :
metadata :
labels :
app : vij-admin
spec :
containers :
- name : vij-admin
image : vij-admin:latest
ports :
- containerPort : 3000
env :
- name : MONGODB_URI
valueFrom :
secretKeyRef :
name : vij-secrets
key : mongodb-uri
- name : NEXT_PUBLIC_BASE_URL
value : "https://vij.yourdomain.com"
- name : GEMINI_API_KEY
valueFrom :
secretKeyRef :
name : vij-secrets
key : gemini-api-key
resources :
requests :
memory : "256Mi"
cpu : "250m"
limits :
memory : "512Mi"
cpu : "500m"
livenessProbe :
httpGet :
path : /api/logs
port : 3000
initialDelaySeconds : 30
periodSeconds : 10
readinessProbe :
httpGet :
path : /api/logs
port : 3000
initialDelaySeconds : 10
periodSeconds : 5
---
apiVersion : v1
kind : Service
metadata :
name : vij-admin
spec :
type : LoadBalancer
ports :
- port : 80
targetPort : 3000
selector :
app : vij-admin
apiVersion : v1
kind : Secret
metadata :
name : vij-secrets
type : Opaque
stringData :
mongodb-uri : "mongodb+srv://user:pass@cluster.mongodb.net/vij"
gemini-api-key : "your_api_key_here"
Deploy to Kubernetes:
kubectl apply -f k8s/secrets.yaml
kubectl apply -f k8s/deployment.yaml
Post-Deployment
Health Checks
Verify your deployment is healthy:
# Check API endpoint
curl https://vij.yourdomain.com/api/logs
# Should return method not allowed (GET)
# {"error":"Method not allowed"}
# Test POST endpoint
curl -X POST https://vij.yourdomain.com/api/logs \
-H "Content-Type: application/json" \
-d '{
"message": "Test",
"name": "Error",
"stack": "Error: Test",
"severity": "info",
"timestamp": "2024-01-01T00:00:00Z",
"appId": "test",
"environment": "production",
"metadata": {},
"context": {}
}'
# Should return success
Monitoring
Set up monitoring for your VIJ Admin instance:
Uptime Monitoring
Application Monitoring
Database Monitoring
Use services like UptimeRobot or Pingdom: Monitor URL : https://vij.yourdomain.comCheck interval : 5 minutesAlert on : Status code != 200
Backup Strategy
Implement regular backups:
#!/bin/bash
# Backup MongoDB
mongodump --uri= " $MONGODB_URI " --out= "/backups/$( date +%Y%m%d)"
# Compress backup
tar -czf "/backups/vij-$( date +%Y%m%d).tar.gz" "/backups/$( date +%Y%m%d)"
# Remove old backups (keep 30 days)
find /backups -name "vij-*.tar.gz" -mtime +30 -delete
# Upload to S3 (optional)
aws s3 cp "/backups/vij-$( date +%Y%m%d).tar.gz" s3://your-bucket/backups/
Schedule with cron:
# Run daily at 2 AM
0 2 * * * /path/to/backup.sh
Security Considerations
Add authentication middleware to protect your VIJ instance: import { NextResponse } from 'next/server' ;
import type { NextRequest } from 'next/server' ;
export function middleware ( request : NextRequest ) {
const basicAuth = request . headers . get ( 'authorization' );
if ( basicAuth ) {
const authValue = basicAuth . split ( ' ' )[ 1 ];
const [ user , pwd ] = atob ( authValue ). split ( ':' );
if ( user === 'admin' && pwd === process . env . ADMIN_PASSWORD ) {
return NextResponse . next ();
}
}
return new NextResponse ( 'Authentication required' , {
status: 401 ,
headers: {
'WWW-Authenticate' : 'Basic realm="Secure Area"'
}
});
}
export const config = {
matcher: [ '/logs/:path*' , '/groups/:path*' , '/' ]
};
Force HTTPS in production: # Nginx - redirect HTTP to HTTPS
server {
listen 80 ;
server_name vij.yourdomain.com;
return 301 https://$ server_name $ request_uri ;
}
Use MongoDB authentication
Whitelist IP addresses
Use SSL/TLS for connections
Enable audit logging
# MongoDB connection with SSL
MONGODB_URI = mongodb+srv://user:pass@cluster.mongodb.net/vij? ssl = true & authSource = admin
Environment variable security
Never commit .env.local to version control
Use secret management (AWS Secrets Manager, Vault)
Rotate API keys regularly
Use environment-specific keys
Scaling
Horizontal Scaling
VIJ Admin can be horizontally scaled:
# Kubernetes - increase replicas
replicas : 5
# Docker Swarm
docker service scale vij-admin=5
# PM2 cluster mode
pm2 start ecosystem.config.js -i max
Database Optimization
For high-traffic deployments:
// Add connection pooling
MONGODB_URI = mongodb : //host/vij?maxPoolSize=50&minPoolSize=10
// Enable read preference
MONGODB_URI = mongodb : //host/vij?readPreference=secondaryPreferred
// Use replica sets
MONGODB_URI = mongodb : //host1,host2,host3/vij?replicaSet=rs0
Next Steps