π Deployment Guide
Complete guide for deploying MongoDB Minute to production.
Pre-Deployment Checklistβ
Before deploying, ensure:
- All tests passing
- Environment variables documented
- MongoDB indexes created
-
.gitignoreincludes.env.local - Production build succeeds (
npm run build) - Database connection tested
- Authentication working
- Workflow system tested
Environment Variablesβ
Required environment variables for production:
MongoDB Configurationβ
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/?retryWrites=true&w=majority
MONGODB_DB=mongodb_minute
Authenticationβ
JWT_SECRET=your-secure-random-secret-key
JWT_EXPIRES_IN=7d
MAGIC_LINK_EXPIRES_IN=15m
Email Service (Gmail SMTP)β
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_USER=your-email@gmail.com
EMAIL_PASS=your-app-password
EMAIL_FROM=noreply@mongodb.com
Applicationβ
NODE_ENV=production
NEXT_PUBLIC_BASE_URL=https://your-domain.com
Vercel Deploymentβ
Initial Setupβ
-
Connect Repository
- Go to Vercel Dashboard
- Click "Add New Project"
- Import your GitHub repository
- Select the repository
-
Configure Build Settings
- Framework Preset: Next.js
- Root Directory:
./(or your app directory) - Build Command:
npm run build - Output Directory:
.next
-
Add Environment Variables
- Go to Project Settings β Environment Variables
- Add all required variables (see above)
- Set for Production, Preview, and Development
-
Deploy
- Click "Deploy"
- Wait for build to complete
- Verify deployment URL
Custom Domainβ
- Go to Project Settings β Domains
- Add your custom domain
- Follow DNS configuration instructions
- Wait for SSL certificate provisioning
Environment-Specific Variablesβ
Set different values for:
- Production: Live environment
- Preview: Pull request previews
- Development: Local development
MongoDB Atlas Setupβ
Database Configurationβ
-
Create Cluster
- Log in to MongoDB Atlas
- Create new cluster (or use existing)
- Choose region closest to your deployment
-
Create Database User
- Go to Database Access
- Create user with read/write permissions
- Save credentials securely
-
Network Access
- Go to Network Access
- Add IP address or allow all (0.0.0.0/0) for Vercel
- Vercel IPs change, so consider allowing all
-
Get Connection String
- Go to Clusters β Connect
- Choose "Connect your application"
- Copy connection string
- Replace
<password>with your database user password
Create Indexesβ
Run these indexes for optimal performance:
// Unique slug for URL routing
db.episodes.createIndex({ slug: 1 }, { unique: true })
// Query optimization for admin list
db.episodes.createIndex({ status: 1, episodeNumber: 1 })
// Public filtering by category
db.episodes.createIndex({ category: 1 })
// Latest episodes query
db.episodes.createIndex({ status: 1, createdAt: -1 })
// Workflow stage queries
db.episodes.createIndex({ "workflow.currentStage": 1 })
// Review queue queries
db.episodes.createIndex({
"workflow.currentStage": 1,
"workflow.submittedForReview.timestamp": 1
})
// User email lookup
db.users.createIndex({ email: 1 }, { unique: true })
Email Service Configurationβ
Gmail SMTP Setupβ
-
Enable 2-Factor Authentication
- Required for app passwords
-
Generate App Password
- Go to Google Account β Security
- Enable 2-Step Verification
- Generate App Password
- Use this password in
EMAIL_PASS
-
Test Email Sending
- Verify magic link emails are sent
- Check spam folder if needed
Alternative Email Servicesβ
Consider using:
- SendGrid: More reliable for production
- AWS SES: Cost-effective at scale
- Mailgun: Developer-friendly API
Update lib/email.js accordingly.
Security Considerationsβ
Production Securityβ
-
Environment Variables
- Never commit
.env.local - Use Vercel environment variables
- Rotate secrets regularly
- Never commit
-
JWT Secret
- Use strong, random secret
- Minimum 32 characters
- Different for each environment
-
HTTPS
- Vercel provides SSL automatically
- Verify certificate is active
- Force HTTPS redirects
-
CORS
- Configure allowed origins
- Restrict API access if needed
-
Rate Limiting
- Consider adding rate limiting
- Protect against abuse
- Use Vercel Edge Middleware
Performance Optimizationβ
Build Optimizationβ
-
Enable Turbopack (Next.js 16+)
- Already enabled in config
- Faster builds and HMR
-
Image Optimization
- Use Next.js Image component
- Configure image domains
- Enable lazy loading
-
Database Connection
- Connection pooling enabled
- Reuse connections
- Monitor connection count
Caching Strategyβ
-
Static Generation
- Consider ISR for public pages
- Revalidate published episodes
- Cache at CDN level
-
API Caching
- Cache public episode lists
- Don't cache admin endpoints
- Use appropriate cache headers
Monitoring & Analyticsβ
Vercel Analyticsβ
- Enable Vercel Analytics
- Track page views
- Monitor performance metrics
Error Trackingβ
Consider integrating:
- Sentry: Error tracking
- LogRocket: Session replay
- Vercel Logs: Built-in logging
Database Monitoringβ
- Use MongoDB Atlas monitoring
- Set up alerts for:
- High connection count
- Slow queries
- Storage limits
Post-Deploymentβ
Verification Stepsβ
-
Test Authentication
- Request magic link
- Verify email delivery
- Complete login flow
-
Test Workflow
- Create test episode
- Submit for review
- Approve episode
- Verify workflow history
-
Test Public Site
- Browse episodes
- Test search/filter
- Verify episode detail pages
- Check social links
-
Test Admin Features
- Access dashboard
- Create/edit episodes
- Generate QR codes
- Update settings
DNS Configurationβ
If using custom domain:
-
Add DNS Records
- CNAME:
wwwβcname.vercel-dns.com - A Record:
@β Vercel IP (if needed)
- CNAME:
-
Verify SSL
- Wait for certificate provisioning
- Test HTTPS connection
- Verify certificate validity
Troubleshootingβ
Build Failuresβ
Issue: Build fails on Vercel
Solutions:
- Check build logs for errors
- Verify Node.js version (18+)
- Ensure all dependencies are in
package.json - Check environment variables are set
Database Connection Issuesβ
Issue: Cannot connect to MongoDB
Solutions:
- Verify
MONGODB_URIis correct - Check network access in Atlas
- Verify database user permissions
- Test connection string locally
Email Not Sendingβ
Issue: Magic links not received
Solutions:
- Verify Gmail app password
- Check spam folder
- Verify
EMAIL_FROMaddress - Test email service configuration
- Consider using alternative service
Authentication Issuesβ
Issue: Login not working
Solutions:
- Verify JWT secret is set
- Check cookie settings
- Verify email domain restriction
- Check middleware configuration
Rollback Procedureβ
If deployment has issues:
-
Vercel Rollback
- Go to Deployments
- Find previous successful deployment
- Click "Promote to Production"
-
Database Rollback
- Restore from backup if needed
- Use MongoDB Atlas point-in-time restore
-
Environment Variables
- Revert to previous values
- Verify configuration
Maintenanceβ
Regular Tasksβ
-
Update Dependencies
- Check for security updates
- Test updates in staging
- Deploy updates regularly
-
Database Maintenance
- Monitor storage usage
- Archive old episodes if needed
- Optimize indexes
-
Backup Strategy
- Enable MongoDB Atlas backups
- Regular database exports
- Document restore procedures
Next Stepsβ
- Review Project Summary for architecture
- Check API Reference for integration
- Explore Admin Features for usage