Skip to main content

Deployment Guide

Complete deployment instructions for the NS Internship Portal.

Deployment Architecture

Pre-Deployment Checklist

  • All dependencies installed and tested
  • Environment variables configured
  • Database migrations run successfully
  • Tests passing (npm test)
  • Linting passing (npm run lint)
  • Build successful (npm run build)
  • Git repository up to date
  • All secrets stored securely
  • SSL certificate configured
  • Backups verified
  • Monitoring configured
  • Error tracking enabled (optional)

Environment Setup

Production Environment

Create .env.production.local:

# Application
NODE_ENV=production
NEXT_PUBLIC_BASE_URL=https://internships.nssoftwaresolutions.in

# Supabase (Production)
NEXT_PUBLIC_SUPABASE_URL=https://prod.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=prod-anon-key
SUPABASE_SERVICE_ROLE_KEY=prod-service-key

# JWT (CRITICAL - Generate with: openssl rand -base64 32)
JWT_SECRET=your-super-secret-production-jwt

# Email (Production Resend)
EMAIL_HOST=smtp.resend.com
EMAIL_PORT=587
EMAIL_USER=resend
EMAIL_PASS=re_prod-api-key
EMAIL_FROM=noreply@internships.nssoftwaresolutions.in
CONTACT_EMAIL=info.nssoftwaresolutions@gmail.com

# Payment (Razorpay Production)
RAZORPAY_KEY_ID=rzp_live_your-key
RAZORPAY_KEY_SECRET=prod-secret

# Storage (Cloudinary Production)
CLOUDINARY_CLOUD_NAME=prod-cloud-name
CLOUDINARY_API_KEY=prod-api-key
CLOUDINARY_API_SECRET=prod-api-secret

# Google OAuth
GOOGLE_CLIENT_ID=prod-client-id.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=prod-client-secret

# Jobs
SERPAPI_KEY=prod-serpapi-key
CRON_SECRET=prod-cron-secret

# GST Rate
GST_RATE=0.18

Staging Environment

Create .env.staging.local:

# Application
NODE_ENV=staging
NEXT_PUBLIC_BASE_URL=https://staging.internships.nssoftwaresolutions.in

# Use staging credentials for all services
# ... (similar to production but with staging keys)

Vercel Deployment

Initial Setup

  1. Connect Repository

    vercel link
  2. Configure Project

    • Select framework: Next.js
    • Root directory: ./
    • Build command: npm run build
    • Output directory: .next
  3. Add Environment Variables

    • Add all production environment variables in Vercel dashboard
    • Settings → Environment Variables
  4. Configure Cron Jobs

    The platform uses 4 cron jobs for automated tasks. Ensure vercel.json contains:

    {
    "crons": [
    {
    "path": "/api/cron/process-emails",
    "schedule": "0 6 * * *"
    },
    {
    "path": "/api/cron/inactive-students",
    "schedule": "0 9 * * *"
    },
    {
    "path": "/api/cron/deadline-reminders",
    "schedule": "0 8 * * *"
    },
    {
    "path": "/api/cron/job-alerts",
    "schedule": "0 9 * * 1"
    }
    ]
    }

    Important Notes:

    • Cron jobs are protected by CRON_SECRET environment variable
    • /api/cron/jobs (SerpAPI + RSS job fetching) exists but is not scheduled - trigger manually via admin panel
    • Cron execution requires Vercel Pro plan for reliable scheduling

Deploy

Automatic Deployment:

  • Push to main branch → Automatic deployment
  • Push to other branches → Preview deployment

Manual Deployment:

# Deploy to production
vercel --prod

# Deploy to staging
vercel

Database Deployment

Supabase Setup

  1. Create Project

    • Go to supabase.com
    • Create new project
    • Note the project URL and keys
  2. Run Migrations

    # Using Supabase CLI
    supabase link --project-ref your-ref
    supabase db push

    OR manually in SQL editor:

    -- Run all migration files in order
    -- See supabase/ directory
  3. Verify Setup

    • Check all tables created
    • Verify RLS policies enabled
    • Test connection

Database Backup

Automated Backups:

  • Supabase provides daily backups
  • 30-day retention
  • Point-in-time recovery

Manual Backup:

# Export database
pg_dump postgresql://[SUPABASE_CONNECTION_STRING] > backup.sql

# Restore database
psql postgresql://[NEW_DATABASE_URL] < backup.sql

DNS & SSL Configuration

Domain Setup

  1. Point Domain to Vercel

    • Add CNAME record: internships.nssoftwaresolutions.incname.vercel.com
    • Or add A records for Vercel IP addresses
  2. Verify Domain

    • Vercel dashboard → Project → Domains
    • Click "Verify" on your domain
    • SSL certificate auto-generates

SSL Certificate

  • Automatic: Vercel manages SSL via Let's Encrypt
  • Renewal: Automatic before expiration
  • Status: Check in Vercel dashboard → Deployments → SSL

Monitoring & Alerts

Vercel Monitoring

  • Performance: Vercel Speed Insights dashboard
  • Errors: Automatic error reporting
  • Uptime: Monitor.vercel.com

Application Monitoring

Optional: Sentry Setup

  1. Create Sentry project at sentry.io
  2. Add SENTRY_AUTH_TOKEN to env
  3. Errors automatically tracked

Email Monitoring

# Check email usage
curl -H "Cookie: auth-token=YOUR_TOKEN" \
https://internships.nssoftwaresolutions.in/api/admin/email-stats

Performance Optimization

Build Optimization

# Analyze bundle size
npm install -D webpack-bundle-analyzer

# Build with analysis
npm run build -- --analyze

Image Optimization

  • Use next/image for all images
  • Automatic optimization
  • WebP format for modern browsers

Database Optimization

-- Analyze query performance
EXPLAIN ANALYZE SELECT * FROM enrollments WHERE student_id = 'uuid';

-- Add missing indexes
CREATE INDEX idx_enrollments_student_status
ON enrollments(student_id, status);

Logging & Troubleshooting

View Deployment Logs

# Vercel CLI
vercel logs --prod

# Stream logs
vercel logs --prod --follow

Common Issues

Issue: Deployment fails with "out of memory"

Solution: Increase build memory or optimize bundle

# Check bundle size
npm run build -- --analyze

Issue: Cron jobs not running

Solution: Verify vercel.json and check cron status

# List cron jobs
vercel env list

# Check execution history in Vercel dashboard

Issue: Database connection fails

Solution: Verify DATABASE_URL and firewall rules

# Test connection
psql $DATABASE_URL -c "SELECT 1"

Issue: Email not sending

Solution: Check SMTP credentials and rate limits

# Test SMTP
curl telnet smtp.resend.com:587

Rollback Procedures

Rollback to Previous Deployment

Vercel Dashboard:

  1. Go to Deployments
  2. Find previous successful deployment
  3. Click "..." → "Redeploy"

CLI:

# List deployments
vercel list

# Redeploy specific version
vercel rollback

Database Rollback

Supabase:

  1. Go to Backups
  2. Select restore point
  3. Click "Restore"

Manual Restore:

# Restore from SQL backup
psql postgresql://[URL] < backup.sql

Post-Deployment

Verification Steps

  • Homepage loads correctly
  • Student can register and login
  • Admin panel accessible
  • API endpoints respond
  • Database queries work
  • Email sending works
  • Cron jobs execute
  • File uploads work
  • Payments process (test mode)
  • Analytics tracking works

Smoke Tests

# Run smoke tests after deployment
npm run test:smoke

Monitor Performance

# Check Core Web Vitals
curl https://internships.nssoftwaresolutions.in/api/health

Scaling Considerations

Horizontal Scaling

  • Vercel automatically scales with auto-scaling
  • Database replicas for read-heavy workloads
  • CDN caching for static assets

Vertical Scaling

  • Upgrade Vercel Pro plan
  • Increase Supabase resources
  • Upgrade SMTP service

Optimization

  • Enable database query caching
  • Implement CDN for static assets
  • Use edge functions for low-latency APIs
  • Optimize images and code splitting

Disaster Recovery

Recovery Time Objectives (RTO)

SystemRTOCriticality
Application15 minutesHigh
Database1 hourCritical
Email4 hoursMedium
Storage24 hoursLow

Recovery Procedures

Application Failure:

  1. Check Vercel deployment status
  2. Redeploy previous version
  3. Verify all systems online

Database Failure:

  1. Trigger backup restore in Supabase
  2. Wait for restoration (1-2 hours)
  3. Update connection string if needed
  4. Verify data integrity

Email Failure:

  1. Check Resend service status
  2. Verify API credentials
  3. Switch to backup SMTP if available

Maintenance

Regular Tasks

Daily:

  • Monitor error logs
  • Check email queue
  • Verify uptime

Weekly:

  • Review analytics
  • Check security logs
  • Test backups

Monthly:

  • Update dependencies
  • Security audit
  • Performance review
  • Disaster recovery drill

Quarterly:

  • Penetration testing
  • Database optimization
  • Capacity planning
  • Compliance audit

Support & Documentation