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
-
Connect Repository
vercel link -
Configure Project
- Select framework: Next.js
- Root directory: ./
- Build command: npm run build
- Output directory: .next
-
Add Environment Variables
- Add all production environment variables in Vercel dashboard
- Settings → Environment Variables
-
Configure Cron Jobs
The platform uses 4 cron jobs for automated tasks. Ensure
vercel.jsoncontains:{"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_SECRETenvironment 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
- Cron jobs are protected by
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
-
Create Project
- Go to supabase.com
- Create new project
- Note the project URL and keys
-
Run Migrations
# Using Supabase CLIsupabase link --project-ref your-refsupabase db pushOR manually in SQL editor:
-- Run all migration files in order-- See supabase/ directory -
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
-
Point Domain to Vercel
- Add CNAME record:
internships.nssoftwaresolutions.in→cname.vercel.com - Or add A records for Vercel IP addresses
- Add CNAME record:
-
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
- Create Sentry project at sentry.io
- Add SENTRY_AUTH_TOKEN to env
- 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/imagefor 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:
- Go to Deployments
- Find previous successful deployment
- Click "..." → "Redeploy"
CLI:
# List deployments
vercel list
# Redeploy specific version
vercel rollback
Database Rollback
Supabase:
- Go to Backups
- Select restore point
- 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)
| System | RTO | Criticality |
|---|---|---|
| Application | 15 minutes | High |
| Database | 1 hour | Critical |
| 4 hours | Medium | |
| Storage | 24 hours | Low |
Recovery Procedures
Application Failure:
- Check Vercel deployment status
- Redeploy previous version
- Verify all systems online
Database Failure:
- Trigger backup restore in Supabase
- Wait for restoration (1-2 hours)
- Update connection string if needed
- Verify data integrity
Email Failure:
- Check Resend service status
- Verify API credentials
- 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
- Vercel Docs: https://vercel.com/docs
- Supabase Docs: https://supabase.io/docs
- Next.js Docs: https://nextjs.org/docs
- Status Page: https://status.vercel.com