Deployment Guide

Deploy Litestore to production with various hosting providers

Deployment Overview

Litestore can be deployed to various hosting platforms. We recommend Vercel for the easiest deployment experience due to its native Next.js support, but provide comprehensive guides for other popular platforms including Railway, AWS, and DigitalOcean.

Deployment Checklist

Before deploying to production:

  • Environment variables configured
  • Database migrations run
  • SSL certificate set up
  • Domain configured
  • Monitoring and logging enabled
  • Backup strategy implemented
  • Performance optimization applied

Quick Deploy (Vercel)

One-Click Deploy

Deploy to Vercel with one click:

Deploy with Vercel

Manual Vercel Deployment

  1. Connect Repository

    • Import your Litestore project to Vercel
    • Connect your GitHub/GitLab repository
    • Vercel will auto-detect Next.js settings
  2. Configure Environment Variables Set these in your Vercel dashboard under Project Settings > Environment Variables:

    # Database
    DATABASE_URL=postgresql://...
    
    # Authentication
    NEXTAUTH_SECRET=your-32-character-secret-key
    NEXTAUTH_URL=https://your-app.vercel.app
    
    # AI Services (Optional)
    OPENAI_API_KEY=sk-your-openai-key
    
    # File Storage (Optional)
    CLOUDINARY_CLOUD_NAME=your-cloud-name
    CLOUDINARY_API_KEY=your-api-key
    CLOUDINARY_API_SECRET=your-secret
    
    # Payments (Optional)
    STRIPE_SECRET_KEY=sk_live_...
    STRIPE_WEBHOOK_SECRET=whsec_...
    STRIPE_PUBLISHABLE_KEY=pk_live_...
    
    # Email (Optional)
    SMTP_HOST=smtp.sendgrid.net
    SMTP_PORT=587
    SMTP_USER=apikey
    SMTP_PASS=your-sendgrid-key
  3. Database Setup

    • Use Vercel Postgres (recommended) or connect to external PostgreSQL
    • Run migrations: vercel env pull && npx prisma migrate deploy
    • For Vercel Postgres, the DATABASE_URL is automatically configured
  4. Build Settings Vercel automatically detects Next.js settings. You can customize in vercel.json:

    {
      "buildCommand": "npm run build",
      "devCommand": "npm run dev",
      "installCommand": "npm install",
      "framework": "nextjs",
      "functions": {
        "app/api/**/*.ts": {
          "maxDuration": 30
        }
      }
    }
  5. Deploy

    • Vercel automatically builds and deploys on git push
    • Preview deployments for every branch
    • Visit your deployment URL (usually your-project.vercel.app)

Docker Deployment

# docker-compose.yml
version: '3.8'

services:
  litestore:
    build: .
    ports:
      - "3000:3000"
    environment:
      - DATABASE_URL=postgresql://postgres:password@postgres:5432/litestore
      - NEXTAUTH_SECRET=your-secret-key
      - NEXTAUTH_URL=http://localhost:3000
    depends_on:
      - postgres
    volumes:
      - ./uploads:/app/uploads

  postgres:
    image: postgres:15
    environment:
      - POSTGRES_DB=litestore
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=password
    volumes:
      - postgres_data:/var/lib/postgresql/data
    ports:
      - "5432:5432"

volumes:
  postgres_data:
# Build and run
docker-compose up -d

# Run migrations
docker-compose exec litestore npx prisma migrate deploy

Docker Image

# Dockerfile
FROM node:18-alpine AS base

# Install dependencies only when needed
FROM base AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app

COPY package.json package-lock.json* ./
RUN npm ci --only=production && npm cache clean --force

# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

ENV NEXT_TELEMETRY_DISABLED 1

RUN npm run build

# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app

ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder /app/public ./public

# Set the correct permission for prerender cache
RUN mkdir .next
RUN chown nextjs:nodejs .next

# Automatically leverage output traces to reduce image size
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000

ENV PORT 3000

CMD ["node", "server.js"]
# Build and run
docker build -t litestore .
docker run -p 3000:3000 litestore

Railway Deployment

Automatic Setup

  1. Connect Repository

    • Link your GitHub repository to Railway
    • Railway auto-detects Next.js projects
  2. Database Provisioning

    • Railway automatically provisions PostgreSQL
    • Database URL is automatically configured
  3. Environment Variables

    NEXTAUTH_SECRET=your-secret-key
    NEXTAUTH_URL=${{RAILWAY_STATIC_URL}}
    OPENAI_API_KEY=sk-... # Optional
  4. Deploy

    • Automatic deployments on git push
    • Built-in monitoring and logs

AWS Deployment

Using Elastic Beanstalk

  1. Prepare Application

    # Create deployment package
    zip -r litestore-deploy.zip . -x "node_modules/*" ".git/*"
  2. EB Configuration

    # .platform/hooks/predeploy
    #!/bin/bash
    npm ci
    npx prisma generate
    npx prisma migrate deploy
    npm run build
  3. Deploy to EB

    eb create litestore-prod
    eb deploy

Using ECS with Fargate

# task-definition.json
{
  "family": "litestore",
  "taskRoleArn": "arn:aws:iam::123456789012:role/ecsTaskExecutionRole",
  "executionRoleArn": "arn:aws:iam::123456789012:role/ecsTaskExecutionRole",
  "networkMode": "awsvpc",
  "requiresCompatibilities": ["FARGATE"],
  "cpu": "256",
  "memory": "512",
  "containerDefinitions": [
    {
      "name": "litestore",
      "image": "your-registry/litestore:latest",
      "essential": true,
      "portMappings": [
        {
          "containerPort": 3000,
          "protocol": "tcp"
        }
      ],
      "environment": [
        {"name": "DATABASE_URL", "value": "postgresql://..."},
        {"name": "NEXTAUTH_SECRET", "value": "your-secret"},
        {"name": "NODE_ENV", "value": "production"}
      ],
      "logConfiguration": {
        "logDriver": "awslogs",
        "options": {
          "awslogs-group": "/ecs/litestore",
          "awslogs-region": "us-east-1",
          "awslogs-stream-prefix": "ecs"
        }
      }
    }
  ]
}

DigitalOcean Deployment

App Platform

  1. Connect Repository

    • Link GitHub repository
    • Auto-detects Next.js
  2. Environment Setup

    # App Specs
    INSTANCE: Basic ($12/month)
    REGION: NYC1
    
    # Environment Variables
    DATABASE_URL=${db.DATABASE_URL}
    NEXTAUTH_SECRET=your-secret-key
    NEXTAUTH_URL=${APP_URL}
  3. Database

    • Create DigitalOcean Managed Database
    • Connect to application
  4. Deploy

    • Automatic deployments
    • Built-in monitoring

Droplet with Docker

# On your Droplet
git clone https://github.com/your-org/litestore.git
cd litestore

# Create .env file
nano .env.local

# Run with Docker Compose
docker-compose up -d

Environment Configuration

Production Environment Variables

For production deployments, ensure these additional variables are set:

# Core Application
NODE_ENV=production
NEXT_PUBLIC_APP_URL=https://yourdomain.com

# Database
DATABASE_URL=postgresql://user:pass@prod-host:5432/litestore

# Authentication
NEXTAUTH_SECRET=your-32-char-secret-key
NEXTAUTH_URL=https://yourdomain.com

# Security
NEXTAUTH_SECRET=your-32-character-secret-key

# AI Services
OPENAI_API_KEY=sk-your-production-key

# File Storage
CLOUDINARY_CLOUD_NAME=your-prod-cloud
CLOUDINARY_API_KEY=your-prod-api-key
CLOUDINARY_API_SECRET=your-prod-secret

# Payment Processing
STRIPE_SECRET_KEY=sk_live_your-live-secret
STRIPE_PUBLISHABLE_KEY=pk_live_your-live-public
STRIPE_WEBHOOK_SECRET=whsec_your-live-webhook-secret

# Email Service
SMTP_HOST=smtp.sendgrid.net
SMTP_PORT=587
SMTP_USER=apikey
SMTP_PASS=your-production-sendgrid-key

# Analytics & Monitoring
GOOGLE_ANALYTICS_ID=GA_MEASUREMENT_ID
SENTRY_DSN=https://your-sentry-dsn@sentry.io/project-id
MIXPANEL_TOKEN=your-production-mixpanel-token

# Redis (Optional but recommended for production)
REDIS_URL=redis://your-redis-instance:6379

Database Migration for Production

# Core
NODE_ENV=production
NEXTAUTH_URL=https://yourdomain.com
DATABASE_URL=postgresql://user:pass@host:5432/db

# Security
NEXTAUTH_SECRET=your-32-char-secret

# AI (Optional)
OPENAI_API_KEY=sk-your-key

# Payments (Optional)
STRIPE_SECRET_KEY=sk_live_...
STRIPE_WEBHOOK_SECRET=whsec_...

# Email (Optional)
SMTP_HOST=smtp.sendgrid.net
SMTP_PORT=587
SMTP_USER=apikey
SMTP_PASS=your-sendgrid-key

# Analytics (Optional)
GOOGLE_ANALYTICS_ID=GA-...
MIXPANEL_TOKEN=your-token

# File Storage (Optional)
CLOUDINARY_CLOUD_NAME=your-cloud
CLOUDINARY_API_KEY=your-key
CLOUDINARY_API_SECRET=your-secret

# Monitoring (Optional)
SENTRY_DSN=https://...

Database Migration

For production deployments:

# Generate Prisma client
npx prisma generate

# Run migrations
npx prisma migrate deploy

# (Optional) Seed data
npx prisma db seed

SSL & Security

HTTPS Configuration

Most hosting platforms provide automatic SSL:

  • Vercel: Automatic SSL certificates
  • Railway: Automatic SSL certificates
  • AWS: Use AWS Certificate Manager
  • DigitalOcean: Automatic SSL on App Platform

Security Headers

Litestore includes security headers via Next.js configuration:

// next.config.js
module.exports = {
  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'
          }
        ]
      }
    ]
  }
}

Performance Optimization

Build Optimization

// next.config.js
module.exports = {
  swcMinify: true,
  compiler: {
    removeConsole: process.env.NODE_ENV === 'production'
  },
  experimental: {
    optimizeCss: true,
    scrollRestoration: true
  }
}

Database Optimization

-- Add production indexes
CREATE INDEX CONCURRENTLY idx_products_category ON products(category_id);
CREATE INDEX CONCURRENTLY idx_creator_content_creator ON creator_content(creator_id);
CREATE INDEX CONCURRENTLY idx_reviews_product ON reviews(product_id);
CREATE INDEX CONCURRENTLY idx_orders_user ON orders(user_id);

CDN Setup

Configure CDN for static assets:

// next.config.js
module.exports = {
  images: {
    domains: ['your-cdn.com'],
    loader: 'cloudinary',
    path: 'https://your-cdn.com/_next/image'
  }
}

Monitoring & Maintenance

Application Monitoring

// lib/monitoring.ts
import * as Sentry from "@sentry/nextjs";

Sentry.init({
  dsn: process.env.SENTRY_DSN,
  tracesSampleRate: 1.0,
  environment: process.env.NODE_ENV
});

Database Monitoring

Monitor database performance:

-- Query performance
SELECT
  schemaname,
  tablename,
  attname,
  n_distinct,
  correlation
FROM pg_stats
WHERE schemaname = 'public';

-- Slow queries
SELECT
  query,
  calls,
  total_time,
  mean_time,
  rows
FROM pg_stat_statements
ORDER BY mean_time DESC
LIMIT 10;

Backup Strategy

# Database backup script
#!/bin/bash
DATE=$(date +%Y%m%d_%H%M%S)
pg_dump $DATABASE_URL > backup_$DATE.sql

# Upload to cloud storage
aws s3 cp backup_$DATE.sql s3://your-backups/

# Clean old backups (keep last 30 days)
find . -name "backup_*.sql" -mtime +30 -delete

Scaling Considerations

Horizontal Scaling

For high-traffic deployments:

  1. Load Balancer: Distribute traffic across multiple instances
  2. Redis Caching: Cache frequently accessed data
  3. CDN: Serve static assets globally
  4. Database Read Replicas: Offload read queries

Database Scaling

-- Connection pooling
ALTER SYSTEM SET max_connections = 200;

-- Shared buffers (25% of RAM)
ALTER SYSTEM SET shared_buffers = '512MB';

-- Work memory
ALTER SYSTEM SET work_mem = '4MB';

Performance Monitoring

Monitor key metrics:

  • Response Time: < 200ms for API endpoints
  • Throughput: Handle 1000+ concurrent users
  • Error Rate: < 0.1% error rate
  • Database Performance: Query response time < 50ms

Troubleshooting

Common Deployment Issues

Build Failures

# Clear build cache
rm -rf .next
rm -rf node_modules/.cache

# Check Node.js version
node --version # Should be 18+

# Reinstall dependencies
rm -rf node_modules package-lock.json
npm install

Database Connection Issues

# Test database connection
npx prisma db push --preview-feature

# Check migration status
npx prisma migrate status

# Reset database (development only)
npx prisma migrate reset

Environment Variable Issues

# List all environment variables
env | grep -E "(DATABASE|NEXTAUTH|STRIPE)"

# Check for missing variables
node -e "console.log(process.env.DATABASE_URL ? 'DB OK' : 'DB MISSING')"

Rollback Strategy

Prepare for quick rollbacks:

# Tag releases
git tag v1.2.3
git push origin v1.2.3

# Rollback commands
git reset --hard v1.2.2
git push --force-with-lease

# Database rollback
npx prisma migrate resolve --rolled-back 20231201120000_add_new_feature

Support & Resources

Professional Services

Need help with deployment?

  • Custom Deployment: We can deploy Litestore on your infrastructure
  • Migration Services: Move from existing platforms
  • Performance Optimization: Scale your deployment
  • Security Audits: Enterprise security reviews

Community Resources

  • GitHub Issues: Report deployment problems
  • Discord Community: Get help from other users
  • Documentation: Check deployment guides for updates
  • Professional Support: Contact us for enterprise deployments

Deployment Success

Successful deployment is just the beginning. Monitor your application, gather user feedback, and iterate on your configuration for optimal performance.

On this page