Skip to main content

Deployment Guide

Complete guide for deploying Dashtray to production.

Overview

Dashtray is deployed using:
  • Backend: Convex (serverless functions and database)
  • Frontend: Cloudflare Pages (SSR + static assets)
  • Payments: DodoPayments (merchant of record)
  • Email: Resend (transactional emails)

Prerequisites

Environment Setup

1. Convex Environment Variables

Set these in Convex using npx convex env set KEY value:
# Application URL
npx convex env set SITE_URL https://dashtray.com

# Authentication
npx convex env set BETTER_AUTH_SECRET $(openssl rand -base64 32)

# Encryption
npx convex env set MASTER_ENCRYPTION_KEY $(openssl rand -hex 32)

# Email (Resend)
npx convex env set RESEND_API_KEY re_your_api_key
npx convex env set RESET_EMAIL_FROM noreply@dashtray.com

# OAuth (Optional)
npx convex env set GOOGLE_CLIENT_ID your_google_client_id
npx convex env set GOOGLE_CLIENT_SECRET your_google_client_secret
npx convex env set GITHUB_CLIENT_ID your_github_client_id
npx convex env set GITHUB_CLIENT_SECRET your_github_client_secret

# DodoPayments
npx convex env set DODO_PAYMENTS_API_KEY dp_your_api_key
npx convex env set DODO_PAYMENTS_ENVIRONMENT production
npx convex env set DODO_PAYMENTS_WEBHOOK_SECRET whsec_your_secret

2. SvelteKit Environment Variables

Create .env.production:
# Convex (auto-generated after deployment)
PUBLIC_CONVEX_URL=https://your-deployment.convex.cloud
PUBLIC_CONVEX_SITE_URL=https://your-deployment.convex.site

# Application URL (must match Convex SITE_URL)
SITE_URL=https://dashtray.com

3. Cloudflare Environment Variables

Set in Cloudflare Pages dashboard:
  • PUBLIC_CONVEX_URL: Your Convex deployment URL
  • PUBLIC_CONVEX_SITE_URL: Your Convex site URL
  • SITE_URL: Your application URL

Deployment Steps

Step 1: Deploy Convex Backend

# Install dependencies
pnpm install

# Deploy to production
npx convex deploy --prod

# Note the deployment URL
# Example: https://happy-animal-123.convex.cloud
After deployment, Convex will output:
  • Deployment URL (use for PUBLIC_CONVEX_URL)
  • Site URL (use for PUBLIC_CONVEX_SITE_URL)

Step 2: Configure OAuth Providers (Optional)

Google OAuth

  1. Go to Google Cloud Console
  2. Create a new project or select existing
  3. Enable Google+ API
  4. Create OAuth 2.0 credentials
  5. Add authorized redirect URI:
    https://your-deployment.convex.site/api/auth/callback/google
    
  6. Copy Client ID and Secret to Convex env

GitHub OAuth

  1. Go to GitHub Settings → Developer settings
  2. Create new OAuth App
  3. Set Authorization callback URL:
    https://your-deployment.convex.site/api/auth/callback/github
    
  4. Copy Client ID and Secret to Convex env

Step 3: Configure DodoPayments

  1. Log in to DodoPayments Dashboard
  2. Get your API key from Settings → API Keys
  3. Set up webhook endpoint:
    https://your-deployment.convex.site/api/webhooks/dodo
    
  4. Copy webhook secret
  5. Set environment variables in Convex

Step 4: Configure Resend

  1. Log in to Resend Dashboard
  2. Get your API key from Settings → API Keys
  3. Verify your sending domain
  4. Set environment variables in Convex

Step 5: Build SvelteKit Application

# Build for production
pnpm build

# Output will be in .svelte-kit/cloudflare

Step 6: Deploy to Cloudflare Pages

Option A: Using Wrangler CLI

# Install Wrangler
pnpm add -g wrangler

# Login to Cloudflare
wrangler login

# Deploy
wrangler pages deploy .svelte-kit/cloudflare --project-name=dashtray

Option B: Using Cloudflare Dashboard

  1. Go to Cloudflare Dashboard
  2. Navigate to Pages
  3. Click “Create a project”
  4. Connect your Git repository (GitHub, GitLab, etc.)
  5. Configure build settings:
    • Build command: pnpm build
    • Build output directory: .svelte-kit/cloudflare
    • Root directory: /
  6. Add environment variables (see Step 3 above)
  7. Click “Save and Deploy”

Step 7: Configure Custom Domain (Optional)

  1. In Cloudflare Pages, go to your project
  2. Click “Custom domains”
  3. Click “Set up a custom domain”
  4. Enter your domain (e.g., dashtray.com)
  5. Follow DNS configuration instructions
  6. Wait for SSL certificate provisioning (automatic)

Step 8: Verify Deployment

  1. Test authentication:
    • Sign up with email
    • Verify email works
    • Test OAuth (if configured)
  2. Test integrations:
    • Connect Stripe
    • Verify metrics sync
    • Check dashboard displays
  3. Test webhooks:
    • Trigger DodoPayments webhook (test subscription)
    • Check webhook logs in Convex
  4. Test alerts:
    • Create an alert
    • Verify it triggers correctly
    • Check notifications
  5. Test AI:
    • Set up AI key
    • Ask a question
    • Verify response

CI/CD Setup

GitHub Actions

Create .github/workflows/deploy.yml:
name: Deploy to Production

on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3

      - uses: pnpm/action-setup@v2
        with:
          version: 8

      - uses: actions/setup-node@v3
        with:
          node-version: 18
          cache: 'pnpm'

      - name: Install dependencies
        run: pnpm install

      - name: Run tests
        run: pnpm test

      - name: Deploy Convex
        run: npx convex deploy --prod
        env:
          CONVEX_DEPLOY_KEY: ${{ secrets.CONVEX_DEPLOY_KEY }}

      - name: Build SvelteKit
        run: pnpm build
        env:
          PUBLIC_CONVEX_URL: ${{ secrets.PUBLIC_CONVEX_URL }}
          PUBLIC_CONVEX_SITE_URL: ${{ secrets.PUBLIC_CONVEX_SITE_URL }}
          SITE_URL: ${{ secrets.SITE_URL }}

      - name: Deploy to Cloudflare Pages
        run: wrangler pages deploy .svelte-kit/cloudflare --project-name=dashtray
        env:
          CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}

      - name: Run smoke tests
        run: pnpm test:smoke
        env:
          TEST_URL: https://dashtray.com

Required Secrets

Add these to GitHub repository secrets:
  • CONVEX_DEPLOY_KEY: Get from Convex dashboard
  • PUBLIC_CONVEX_URL: Your Convex deployment URL
  • PUBLIC_CONVEX_SITE_URL: Your Convex site URL
  • SITE_URL: Your application URL
  • CLOUDFLARE_API_TOKEN: Get from Cloudflare dashboard

Monitoring

Convex Monitoring

  1. Go to Convex Dashboard
  2. Select your deployment
  3. Monitor:
    • Function execution times
    • Database query performance
    • Error rates
    • Cron job status

Cloudflare Analytics

  1. Go to Cloudflare Pages dashboard
  2. View analytics:
    • Page views
    • Unique visitors
    • Bandwidth usage
    • Error rates

Error Tracking (Optional)

Sentry Setup

pnpm add @sentry/sveltekit
// src/hooks.client.ts
import * as Sentry from '@sentry/sveltekit';

Sentry.init({
  dsn: 'your-sentry-dsn',
  environment: 'production',
  tracesSampleRate: 0.1
});

Uptime Monitoring

Use services like: Monitor endpoints:
  • https://dashtray.com (homepage)
  • https://dashtray.com/api/health (health check)

Backup Strategy

Convex Backups

Convex automatically backs up your data:
  • Continuous backups
  • Point-in-time recovery
  • 30-day retention
To export data:
npx convex export --path ./backup

Environment Variables Backup

Store encrypted backups of environment variables:
# Export Convex env vars
npx convex env list > convex-env-backup.txt

# Encrypt backup
gpg -c convex-env-backup.txt

# Store encrypted file securely

Rollback Procedure

Rollback Convex

# List deployments
npx convex deployments list

# Rollback to previous deployment
npx convex deployments rollback <deployment-id>

Rollback Cloudflare Pages

  1. Go to Cloudflare Pages dashboard
  2. Click on your project
  3. Go to “Deployments”
  4. Find previous successful deployment
  5. Click “Rollback to this deployment”

Scaling Considerations

Convex Scaling

Convex scales automatically:
  • No configuration needed
  • Handles traffic spikes
  • Global edge network

Cloudflare Pages Scaling

Cloudflare Pages scales automatically:
  • Global CDN
  • Unlimited bandwidth
  • DDoS protection

Database Optimization

  1. Add indexes: For frequently queried fields
  2. Paginate results: Don’t fetch all data at once
  3. Cache responses: Use Convex’s built-in caching
  4. Optimize queries: Use indexes effectively

Security Checklist

  • HTTPS enabled (automatic with Cloudflare)
  • Environment variables set correctly
  • Master encryption key is secure and backed up
  • OAuth credentials are production keys
  • DodoPayments webhook secret is set
  • Resend API key is production key
  • CORS configured correctly
  • CSP headers configured
  • Rate limiting enabled
  • Error messages don’t leak sensitive info

Performance Optimization

Frontend

  1. Enable caching: Cloudflare automatically caches static assets
  2. Optimize images: Use WebP format, lazy loading
  3. Code splitting: SvelteKit does this automatically
  4. Minimize JavaScript: Remove unused dependencies

Backend

  1. Optimize queries: Use indexes, limit results
  2. Batch operations: Group related mutations
  3. Cache frequently accessed data: Use Convex caching
  4. Monitor slow queries: Use Convex dashboard

Troubleshooting

Deployment Fails

Convex deployment fails:
# Check for syntax errors
pnpm check

# Check Convex logs
npx convex logs
Cloudflare deployment fails:
# Check build output
pnpm build

# Check for missing environment variables

Application Errors

500 errors:
  1. Check Convex logs: npx convex logs
  2. Check Cloudflare Pages logs
  3. Verify environment variables
  4. Check for missing dependencies
Authentication not working:
  1. Verify BETTER_AUTH_SECRET is set
  2. Check OAuth redirect URIs
  3. Verify SITE_URL matches actual URL
Webhooks not working:
  1. Verify webhook URL is correct
  2. Check webhook secret matches
  3. Review webhook logs in DodoPayments dashboard
  4. Check Convex logs for errors

Maintenance

Regular Tasks

Weekly:
  • Review error logs
  • Check uptime metrics
  • Monitor database size
Monthly:
  • Review and optimize slow queries
  • Check for dependency updates
  • Review security advisories
Quarterly:
  • Rotate encryption keys (if needed)
  • Review and update documentation
  • Conduct security audit

Updates

Dependency updates:
# Check for updates
pnpm outdated

# Update dependencies
pnpm update

# Test thoroughly
pnpm test

# Deploy
npx convex deploy --prod
pnpm build
wrangler pages deploy .svelte-kit/cloudflare

Cost Estimation

Convex

  • Free tier: 1M function calls/month
  • Pro: $25/month + usage
  • Estimated: $50-200/month depending on traffic

Cloudflare Pages

  • Free tier: Unlimited requests, 500 builds/month
  • Pro: $20/month + usage
  • Estimated: $0-50/month

DodoPayments

  • Commission: 5% + payment processing fees
  • No monthly fee

Resend

  • Free tier: 3,000 emails/month
  • Pro: $20/month for 50,000 emails
  • Estimated: $0-20/month
Total estimated monthly cost: $50-270/month

Need Help?