Production Deployment

Production Deployment

Complete guide to deploying NextReady applications to production with Vercel, environment configuration, and monitoring setup.

Zero-config deployment
Automatic scaling
Global CDN

Deployment Features

Vercel Integration
Seamless deployment with zero configuration
  • Automatic GitHub integration
  • Preview deployments for PRs
  • Edge function support
  • Global CDN distribution
Environment Management
Secure configuration for all environments
  • Environment variable encryption
  • Preview environment isolation
  • Production secrets management
  • Branch-specific configurations
Database Deployment
Production-ready database setup
  • Neon PostgreSQL scaling
  • Connection pooling optimization
  • Migration deployment pipeline
  • Backup and recovery strategies
Monitoring & Analytics
Production monitoring and performance tracking
  • Real-time error tracking
  • Performance metrics
  • Usage analytics
  • Uptime monitoring

Deployment Process

1
Repository Setup
Connect your GitHub repository to Vercel
Push your code to GitHub
Connect GitHub account to Vercel
Import your NextReady repository
Configure build settings
2
Environment Configuration
Set up production environment variables
Add all required environment variables
Configure database connection strings
Set up OAuth provider credentials
Enable external service integrations
3
Database Setup
Prepare production database
Create production Neon database
Run database migrations
Configure connection pooling
Set up backup strategies
4
Go Live
Deploy to production
Deploy from main branch
Verify all functionality
Configure custom domain
Set up monitoring and alerts

Configuration & Setup

Vercel Configuration
Optimize your Vercel deployment with custom configuration
// vercel.json - Vercel Configuration
{
  "buildCommand": "npm run build",
  "outputDirectory": ".next",
  "installCommand": "npm install",
  "devCommand": "npm run dev",
  "env": {
    "NEXTAUTH_URL": "https://your-domain.vercel.app"
  },
  "build": {
    "env": {
      "DATABASE_URL": "@database-url",
      "NEXTAUTH_SECRET": "@nextauth-secret",
      "RESEND_API_KEY": "@resend-api-key"
    }
  },
  "functions": {
    "app/api/**": {
      "maxDuration": 30
    }
  },
  "regions": ["iad1"],
  "framework": "nextjs"
}

Pre-deployment Checklist

Security & Configuration
  • All environment variables configured
  • Database migrations tested
  • OAuth providers configured
  • HTTPS certificates in place
  • External service quotas verified
Performance & Monitoring
  • Build optimization completed
  • Assets compressed and optimized
  • Error tracking configured
  • Health checks implemented
  • Performance monitoring enabled

Deployment Automation

Automated Deployment Script
Comprehensive deployment automation with pre-checks, optimization, and verification
// scripts/deploy.js - Deployment Automation
const { execSync } = require('child_process');
const fs = require('fs');
const chalk = require('chalk');

class DeploymentManager {
  constructor() {
    this.environment = process.env.NODE_ENV || 'production';
    this.branch = process.env.VERCEL_GIT_COMMIT_REF || 'main';
  }

  async run() {
    console.log(chalk.blue.bold('šŸš€ NextReady Deployment Pipeline\n'));
    
    try {
      await this.preDeploymentChecks();
      await this.buildOptimization();
      await this.databasePreparation();
      await this.verifyDeployment();
      
      console.log(chalk.green.bold('\nāœ… Deployment completed successfully!'));
    } catch (error) {
      console.error(chalk.red('Deployment failed:'), error.message);
      process.exit(1);
    }
  }

  async preDeploymentChecks() {
    console.log(chalk.yellow('šŸ” Pre-deployment checks...'));
    
    // Validate environment variables
    const requiredEnvVars = [
      'DATABASE_URL',
      'NEXTAUTH_SECRET',
      'NEXTAUTH_URL'
    ];
    
    const missingVars = requiredEnvVars.filter(varName => !process.env[varName]);
    
    if (missingVars.length > 0) {
      throw new Error(`Missing environment variables: ${missingVars.join(', ')}`);
    }
    
    console.log(chalk.green('āœ… Environment variables validated'));
    
    // Test database connection
    try {
      execSync('npm run db:test', { stdio: 'pipe' });
      console.log(chalk.green('āœ… Database connection verified'));
    } catch (error) {
      throw new Error('Database connection failed');
    }
    
    // Run linting and type checking
    try {
      execSync('npm run lint', { stdio: 'pipe' });
      console.log(chalk.green('āœ… Linting passed'));
      
      execSync('npm run type-check', { stdio: 'pipe' });
      console.log(chalk.green('āœ… Type checking passed'));
    } catch (error) {
      throw new Error('Code quality checks failed');
    }
  }

  async buildOptimization() {
    console.log(chalk.yellow('\n⚔ Build optimization...'));
    
    // Clear previous builds
    try {
      execSync('rm -rf .next', { stdio: 'pipe' });
      console.log(chalk.green('āœ… Previous build cleared'));
    } catch (error) {
      // Ignore if .next doesn't exist
    }
    
    // Generate Prisma client
    execSync('npx prisma generate', { stdio: 'inherit' });
    console.log(chalk.green('āœ… Prisma client generated'));
    
    // Build application
    execSync('npm run build', { stdio: 'inherit' });
    console.log(chalk.green('āœ… Application built successfully'));
  }

  async databasePreparation() {
    console.log(chalk.yellow('\nšŸ—„ļø  Database preparation...'));
    
    if (this.branch === 'main' && this.environment === 'production') {
      // Production database migrations
      try {
        execSync('npx prisma migrate deploy', { stdio: 'inherit' });
        console.log(chalk.green('āœ… Production migrations applied'));
      } catch (error) {
        throw new Error('Database migration failed');
      }
    } else {
      // Development/preview environment
      try {
        execSync('npx prisma db push', { stdio: 'inherit' });
        console.log(chalk.green('āœ… Preview database schema updated'));
      } catch (error) {
        console.log(chalk.yellow('āš ļø  Database schema update failed, continuing...'));
      }
    }
  }

  async verifyDeployment() {
    console.log(chalk.yellow('\nāœ… Deployment verification...'));
    
    // This would run after deployment
    const deploymentUrl = process.env.VERCEL_URL ? 
      `https://${process.env.VERCEL_URL}` : 
      'http://localhost:3000';
    
    console.log(chalk.cyan(`Deployment URL: ${deploymentUrl}`));
    
    // Add health check logic here
    console.log(chalk.green('āœ… Deployment ready for verification'));
  }
}

if (require.main === module) {
  new DeploymentManager().run().catch(console.error);
}

module.exports = DeploymentManager;

Deployment Best Practices

Post-deployment Tasks

Monitor Performance
  • • Check application startup time
  • • Monitor API response times
  • • Verify database performance
  • • Test user authentication flows
Configure Domain
  • • Add custom domain in Vercel
  • • Configure DNS records
  • • Verify SSL certificate
  • • Update OAuth redirect URLs
Security Review
  • • Review security headers
  • • Test authentication flows
  • • Verify rate limiting
  • • Check error handling

šŸŽ‰ Ready for Production!

Your NextReady application is ready for production deployment. Follow the guide above to deploy securely and reliably.