Deployment
Production deployment guide for your SaaS application with Vercel, Convex, and third-party integrations.
Deployment Overview
The boilerplate is designed for easy deployment with:
- Vercel - Frontend hosting and edge functions
- Convex - Backend and database hosting
- Stripe - Payment processing
- Resend - Email delivery
- Custom domains - Professional branding
Environment Setup
Production Environment Variables
Create a .env.production file with production values:
# App Configuration
NEXT_PUBLIC_APP_NAME="Your SaaS App"
NEXT_PUBLIC_APP_URL="https://yourdomain.com"
# Convex Backend (Production)
CONVEX_DEPLOYMENT=your-production-deployment
NEXT_PUBLIC_CONVEX_URL=https://your-deployment.convex.cloud
# Authentication
AUTH_SECRET=your-super-secure-secret # Use: openssl rand -base64 32
# Google OAuth (Production)
GOOGLE_CLIENT_ID=your-production-google-client-id
GOOGLE_CLIENT_SECRET=your-production-google-client-secret
# Stripe (Live Keys)
STRIPE_PUBLISHABLE_KEY=pk_live_...
STRIPE_SECRET_KEY=sk_live_...
STRIPE_WEBHOOK_SECRET=whsec_live_...
# Email (Production)
RESEND_API_KEY=your-production-resend-key
# Analytics (Optional)
NEXT_PUBLIC_GA_MEASUREMENT_ID=G-XXXXXXXXXX
# Feature Flags
NEXT_PUBLIC_ENABLE_BETA_FEATURES=false
# Node Environment
NODE_ENV=productionSecurity Considerations
- Strong secrets - Use
openssl rand -base64 32for sensitive keys - Environment isolation - Keep development and production separate
- Secret rotation - Regularly update API keys and secrets
- Access control - Limit who has access to production secrets
Convex Deployment
Production Backend
Deploy your Convex backend to production:
# Install Convex CLI
npm install -g convex
# Login to Convex
npx convex login
# Create production deployment
npx convex deploy --prod
# Push schema and functions
npx convex dev --prodEnvironment Configuration
Set production environment variables in Convex:
# Set environment variables
npx convex env set STRIPE_SECRET_KEY sk_live_... --prod
npx convex env set RESEND_API_KEY re_... --prod
npx convex env set GOOGLE_CLIENT_SECRET your-secret --prod
# Verify environment variables
npx convex env list --prodDatabase Migration
Migrate your development data to production (if needed):
# Export development data
npx convex export --output development-data.jsonl
# Import to production (be careful!)
npx convex import development-data.jsonl --prodVercel Deployment
Automatic Deployment
Connect your repository to Vercel for automatic deployments:
- Go to Vercel Dashboard
- Click “New Project”
- Import your Git repository
- Configure build settings:
- Framework Preset: Next.js
- Build Command:
npm run build - Output Directory:
.next - Install Command:
npm install
Environment Variables
Set environment variables in Vercel dashboard:
# Required variables
NEXT_PUBLIC_APP_NAME=Your SaaS App
NEXT_PUBLIC_APP_URL=https://yourdomain.com
NEXT_PUBLIC_CONVEX_URL=https://your-deployment.convex.cloud
AUTH_SECRET=your-super-secure-secret
GOOGLE_CLIENT_ID=your-production-google-client-id
GOOGLE_CLIENT_SECRET=your-production-google-client-secret
STRIPE_PUBLISHABLE_KEY=pk_live_...
STRIPE_SECRET_KEY=sk_live_...
STRIPE_WEBHOOK_SECRET=whsec_live_...
RESEND_API_KEY=your-production-resend-keyCustom Domain
Set up your custom domain in Vercel:
- Go to your project settings
- Navigate to “Domains”
- Add your custom domain
- Configure DNS records:
- Type: CNAME
- Name: www (or @)
- Value: your-project.vercel.app
Build Optimization
Optimize your build for production:
// next.config.mjs
/** @type {import('next').NextConfig} */
const nextConfig = {
// Enable static exports for better performance
output: 'export',
trailingSlash: true,
images: {
unoptimized: true,
},
// Compress images
images: {
formats: ['image/webp', 'image/avif'],
},
// Enable experimental features
experimental: {
optimizeCss: true,
optimizePackageImports: ['@radix-ui/react-icons'],
},
// Security headers
async headers() {
return [
{
source: '/(.*)',
headers: [
{
key: 'X-Frame-Options',
value: 'DENY',
},
{
key: 'X-Content-Type-Options',
value: 'nosniff',
},
{
key: 'Referrer-Policy',
value: 'origin-when-cross-origin',
},
],
},
];
},
};
export default nextConfig;Third-party Service Setup
Stripe Configuration
Set up Stripe for production:
- Switch to Live Mode in Stripe dashboard
- Create Products and Prices for your subscription plans
- Configure Webhooks:
- Endpoint:
https://yourdomain.com/api/webhooks/stripe - Events:
customer.subscription.*,invoice.*
- Endpoint:
- Update Price IDs in your configuration
- Test with real cards (use small amounts)
Google OAuth Setup
Configure Google OAuth for production:
- Go to Google Cloud Console
- Create a new project or select existing
- Enable Google+ API
- Create OAuth 2.0 credentials
- Add authorized redirect URIs:
https://yourdomain.com/api/auth/callback/google
- Update client ID and secret in environment variables
Resend Email Setup
Set up Resend for production emails:
- Create account at Resend
- Verify your domain for better deliverability
- Create API key with appropriate permissions
- Configure DKIM records for your domain
- Test email delivery in production
Monitoring & Analytics
Error Tracking
Set up error tracking with Sentry:
npm install @sentry/nextjs// sentry.client.config.js
import * as Sentry from '@sentry/nextjs';
Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
environment: process.env.NODE_ENV,
tracesSampleRate: 1.0,
});Performance Monitoring
Monitor application performance:
// app/layout.tsx
import { Analytics } from '@vercel/analytics/react';
import { SpeedInsights } from '@vercel/speed-insights/next';
export default function RootLayout({ children }) {
return (
<html>
<body>
{children}
<Analytics />
<SpeedInsights />
</body>
</html>
);
}Uptime Monitoring
Set up uptime monitoring:
- Vercel Analytics - Built-in monitoring
- UptimeRobot - External uptime monitoring
- Pingdom - Comprehensive monitoring solution
- Custom health checks - API endpoints for monitoring
Security Configuration
HTTPS & SSL
Ensure HTTPS is properly configured:
- Vercel automatically provides SSL certificates
- Redirect HTTP to HTTPS
- Use HSTS headers for security
- Configure CSP headers
Rate Limiting
Implement rate limiting for API routes:
// lib/rate-limit.ts
import { Ratelimit } from '@upstash/ratelimit';
import { Redis } from '@upstash/redis';
const redis = Redis.fromEnv();
export const ratelimit = new Ratelimit({
redis,
limiter: Ratelimit.slidingWindow(10, '10 s'),
});
// Usage in API routes
export default async function handler(req, res) {
const { success } = await ratelimit.limit(
req.headers['x-forwarded-for'] || '127.0.0.1'
);
if (!success) {
return res.status(429).json({ error: 'Too many requests' });
}
// Handle request
}Content Security Policy
Configure CSP headers:
// next.config.mjs
const cspHeader = `
default-src 'self';
script-src 'self' 'unsafe-eval' 'unsafe-inline' https://js.stripe.com;
style-src 'self' 'unsafe-inline';
img-src 'self' blob: data: https:;
font-src 'self';
object-src 'none';
base-uri 'self';
form-action 'self';
frame-ancestors 'none';
upgrade-insecure-requests;
`;
const nextConfig = {
async headers() {
return [
{
source: '/(.*)',
headers: [
{
key: 'Content-Security-Policy',
value: cspHeader.replace(/\n/g, ''),
},
],
},
];
},
};Performance Optimization
Caching Strategy
Implement appropriate caching:
// next.config.mjs
const nextConfig = {
async headers() {
return [
{
source: '/api/public/:path*',
headers: [
{
key: 'Cache-Control',
value: 'public, s-maxage=86400, stale-while-revalidate',
},
],
},
];
},
};Database Optimization
Optimize Convex queries for production:
- Use appropriate indexes
- Implement pagination
- Cache frequently accessed data
- Monitor query performance
Image Optimization
Optimize images for production:
// next.config.mjs
const nextConfig = {
images: {
domains: ['images.unsplash.com', 'avatars.githubusercontent.com'],
formats: ['image/webp', 'image/avif'],
minimumCacheTTL: 60,
},
};Backup & Recovery
Database Backups
Set up regular backups:
# Daily backup script
#!/bin/bash
DATE=$(date +%Y%m%d_%H%M%S)
npx convex export --output "backups/backup_${DATE}.jsonl" --prod
# Keep only last 30 days
find backups/ -name "backup_*.jsonl" -mtime +30 -deleteDisaster Recovery Plan
- Regular backups - Daily database exports
- Version control - All code in Git
- Infrastructure as code - Documented deployment process
- Recovery testing - Regular restore tests
- Monitoring alerts - Immediate notification of issues
Deployment Checklist
Pre-deployment
- All environment variables configured
- Stripe webhooks tested
- Email delivery tested
- Database migrations applied
- Security headers configured
- Performance optimizations applied
Post-deployment
- DNS records updated
- SSL certificate active
- Monitoring configured
- Error tracking active
- Backup system running
- User acceptance testing
- Performance benchmarks met
Go-live
- Custom domain active
- Production data migrated
- Payment processing tested
- User onboarding flow tested
- Support documentation updated
- Team notifications configured
Next: Learn about Advanced Topics and customization options.