Overview
AI Studio is built with Next.js 16 and designed for deployment on Vercel with Supabase for database and storage. Background jobs are handled by Trigger.dev for AI processing tasks.Prerequisites
Before deploying, you’ll need accounts for:- Vercel - Hosting and deployment
- Supabase - PostgreSQL database and storage
- Trigger.dev - Background job processing
- Fal.ai - AI image generation (get API key)
- Resend - Email delivery (get API key)
Environment Variables
AI Studio requires the following environment variables. Reference the.env.example file in the repository:
Database (Supabase)
Use the Transaction pooler connection string from Supabase Dashboard → Settings → Database for serverless environments.
Supabase Storage & Auth
Authentication (Better Auth)
App Configuration
AI Services (Fal.ai)
Email (Resend)
Background Jobs (Trigger.dev)
Database Setup
1. Create Supabase Project
- Go to Supabase Dashboard
- Create a new project
- Wait for database provisioning (2-3 minutes)
2. Configure Connection Pooling
For serverless deployments (Vercel), use the Transaction pooler:- Navigate to Settings → Database
- Copy the “Transaction” connection string
- Use port
6543(not5432)
3. Push Database Schema
The database schema is defined inlib/db/schema.ts using Drizzle ORM:
Vercel Deployment
Initial Setup
-
Import Repository
- Go to Vercel Dashboard
- Click “Add New” → “Project”
- Import your GitHub repository
-
Configure Build Settings
- Framework Preset: Next.js
- Build Command:
pnpm build - Output Directory:
.next(auto-detected) - Install Command:
pnpm install
-
Add Environment Variables
- Copy all variables from
.env.example - Paste into Vercel → Settings → Environment Variables
- Apply to Production, Preview, and Development environments
- Copy all variables from
Next.js Build Configuration: The
next.config.ts sets typescript.ignoreBuildErrors: true. Remove this in production for strict type checking.Image Configuration
AI Studio uses Next.js Image optimization with remote patterns configured innext.config.ts:
Deploy
Trigger.dev Setup
AI Studio uses Trigger.dev v4 for background processing of:- Image generation (
trigger/process-image.ts) - Image inpainting (
trigger/inpaint-image.ts) - Video clip generation (
trigger/generate-video-clip.ts) - Video transitions (
trigger/generate-transition-clip.ts) - Video compilation (
trigger/compile-video.ts) - Video orchestration (
trigger/video-orchestrator.ts)
1. Create Trigger.dev Project
- Go to Trigger.dev Cloud
- Create a new project
- Note your project ID (already set in
trigger.config.ts)
2. Get Production API Key
- Navigate to your project settings
- Go to API Keys tab
- Copy the Production secret key (
tr_prod_...) - Add to Vercel environment variables as
TRIGGER_SECRET_KEY
3. Deploy Trigger Tasks
After deploying to Vercel, deploy your Trigger.dev tasks:- Bundles all tasks in the
trigger/directory - Uploads to Trigger.dev
- Makes them available for production use
Post-Deployment Checklist
- Verify environment variables in Vercel dashboard
- Run database migrations:
pnpm db:push(or use migrations) - Deploy Trigger.dev tasks:
pnpm trigger:deploy - Test authentication flow (sign up, sign in)
- Test image upload to Supabase storage
- Test AI image generation (verify Fal.ai integration)
- Test email sending (verify Resend integration)
- Test background job processing (check Trigger.dev dashboard)
- Set up domain and SSL (Vercel automatic)
- Configure OAuth providers in Better Auth (if using)
Monitoring
Vercel Analytics
Enable in Vercel Dashboard → Analytics for:- Traffic monitoring
- Performance metrics
- Error tracking
Trigger.dev Monitoring
View background jobs in Trigger.dev Dashboard:- Task runs and status
- Retry attempts
- Error logs
- Performance metrics
Supabase Logs
Monitor database and storage in Supabase Dashboard:- Query performance
- Storage usage
- API requests
Troubleshooting
Build Failures
TypeScript Errors The project hastypescript.ignoreBuildErrors: true in next.config.ts. For production:
pnpm:
Database Connection Issues
Connection Pooling Use the Transaction pooler (port 6543) for Vercel:Trigger.dev Not Processing
- Verify
TRIGGER_SECRET_KEYis set in Vercel - Check you deployed tasks:
pnpm trigger:deploy - View logs in Trigger.dev dashboard
- Ensure you’re using the production key (
tr_prod_...)
Scaling Considerations
Database
- Supabase free tier: Up to 500MB database
- Upgrade to Pro for larger databases and better performance
- Consider connection pooling for high traffic
Compute
Trigger.dev configuration intrigger.config.ts:
Storage
- Supabase free tier: 1GB storage
- Upgrade for more capacity
- Consider CDN for image delivery
Continuous Deployment
Vercel automatically deploys:- Production: Pushes to
mainbranch - Preview: Pull requests and other branches
Security Best Practices
- Environment Variables: Never commit
.env.localto git - API Keys: Rotate keys periodically
- Database: Use strong passwords
- Better Auth Secret: Minimum 32 characters, cryptographically random
- CORS: Configure allowed origins in API routes if needed
- Rate Limiting: Consider adding rate limits to AI processing endpoints
Next Steps
- Testing Guide - Learn about the testing approach
- Contributing Guide - Start contributing to the project
- API Reference - Explore the API endpoints