Overview
AI Studio is built on Next.js 16 with the App Router, leveraging React Server Components and Server Actions for optimal performance and developer experience. The platform processes real estate images and videos through AI models orchestrated by background jobs.Technology Stack
Frontend
- Next.js 16.1.1 - React framework with App Router
- React 19.2.3 - UI library with Server Components
- Tailwind CSS 4 - Utility-first styling
- shadcn/ui - Component library built on Radix UI
- Tanstack Table - Data tables and virtualization
Backend
- Better Auth - Authentication with email/password, workspace management, and admin features
- Drizzle ORM - Type-safe database queries
- PostgreSQL - Primary database (Supabase)
- Trigger.dev v4 - Background job orchestration
- Fal.ai - AI model APIs (Nano Banana Pro, Kling Video)
Infrastructure
- Supabase - Database and file storage
- Stripe - Payment processing
- Resend - Email delivery
- Vercel - Deployment and hosting
Architecture Patterns
Multi-Tenant Workspace Model
Every user belongs to a workspace, which serves as the billing and organizational boundary:Project Hierarchy
Data Flow
Image Processing Flow
Implementation:- Upload - Client uploads to Supabase Storage via signed URL
- Database Record - Server action creates
imageGenerationrecord - Background Job - Trigger.dev task
process-imageprocesses the image - AI Processing - Fal.ai Nano Banana Pro enhances the image
- Storage - Result saved to Supabase Storage
- Status Update - Database updated to
completedorfailed
trigger/process-image.ts:30 for implementation.
Video Generation Flow
Implementation:- Setup - User creates video project and adds clips
- Orchestration -
video-orchestrator.ts:29coordinates all tasks - Clip Generation - Each clip processed by Kling Video API (parallel)
- Transitions - Seamless transitions generated between clips
- Compilation - FFmpeg concatenates clips with music overlay
- Delivery - Final video uploaded to Supabase
trigger/video-orchestrator.ts:39 for full workflow.
File Organization
App Router Structure
Library Organization
Background Jobs
Server Actions Pattern
AI Studio uses Next.js Server Actions for all mutations. Server Actions provide:- Type Safety - Full TypeScript support end-to-end
- Security - Server-side validation and authorization
- Progressive Enhancement - Works without JavaScript
- Optimistic Updates - Immediate UI feedback
Real-Time Updates
Background job progress is tracked using Trigger.dev’s metadata system:Payment Integration
Dual Payment Model
- Stripe - Credit card payments (international customers)
- Invoice - B2B invoicing via Fiken API (Norwegian customers)
Environment Variables
Required configuration (see.env.example):
Development Workflow
Deployment
The application is designed for deployment on Vercel:- Frontend - Vercel Edge Network
- Database - Supabase (PostgreSQL)
- Background Jobs - Trigger.dev Cloud
- Storage - Supabase Storage
Performance Optimizations
Database Indexes
All foreign keys and frequently queried fields have indexes:Image Optimization
- Next.js Image component for automatic optimization
- Supabase CDN for fast global delivery
- WebP/JPEG format support
Parallel Processing
Video clips generate in parallel using Trigger.dev batch operations:Security
Authentication & Authorization
- Better Auth - Secure password hashing (bcrypt)
- Session-based auth - HttpOnly cookies
- Row-level security - All queries filter by
workspaceId - Admin impersonation - Audit logging for support
Data Validation
- Server Actions - All inputs validated server-side
- Drizzle ORM - Type-safe queries prevent SQL injection
- Zod schemas - Runtime validation for API inputs
File Upload Security
- Signed URLs - Time-limited upload tokens
- Content-Type validation - Only images/videos accepted
- Size limits - Enforced at storage layer