This guide will walk you through deploying the ConstructAI platform entirely on Supabase using their Edge Functions for both frontend hosting and backend services - a unified, powerful deployment solution.
- Supabase Account
- Supabase CLI installed
- Docker (for local development)
- Basic command line knowledge
- Go to supabase.com/dashboard
- Click "New Project"
- Fill in project details:
- Name:
ConstructAI Platform - Database Password: Use a strong password (save this!)
- Region: Choose closest to your users
- Name:
- Click "Create new project"
- Wait 2-3 minutes for setup to complete
- Copy your Project Reference ID from the URL (you'll need this)
# Install Supabase CLI
npm install -g supabase
# Login to your Supabase account
supabase login
# Navigate to your project directory
cd construction-ai-platform
# Link to your Supabase project
supabase link --project-ref your-project-ref-id- Run the database setup:
# Push the schema to your Supabase project
supabase db push
# Or manually: Copy content from supabase-schema.sql and run in SQL Editor- Verify tables were created in Table Editor
# Create storage buckets via Supabase CLI
supabase storage create documents --public=false
supabase storage create bim-models --public=falseOr manually in dashboard:
- Go to Storage in Supabase dashboard
- Create bucket: "documents" (Public:
false, File size limit:500MB) - Create bucket: "bim-models" (Public:
false, File size limit:1GB)
# Deploy all Edge Functions at once
supabase functions deploy
# Or deploy individually
supabase functions deploy nextjs-app
supabase functions deploy file-upload
supabase functions deploy chat-handler# Set up environment variables for Edge Functions
supabase secrets set SUPABASE_URL="https://your-project-ref.supabase.co"
supabase secrets set SUPABASE_SERVICE_ROLE_KEY="your-service-role-key"
supabase secrets set NEXTAUTH_SECRET="your-long-random-secret"Your application will be available at:
- Main App:
https://your-project-ref.supabase.co/functions/v1/nextjs-app - File Upload:
https://your-project-ref.supabase.co/functions/v1/file-upload - Chat API:
https://your-project-ref.supabase.co/functions/v1/chat-handler
- Go to Authentication > Settings in Supabase dashboard
- Site URL:
https://your-project-ref.supabase.co/functions/v1/nextjs-app - Redirect URLs: Add your Edge Function URL
- Enable Email provider
- Configure SMTP (optional) for email functionality
- Visit your Edge Function URL
- Try logging in with demo credentials:
- Email:
john@constructai.com - Password:
demo123
- Email:
-- Run this in SQL Editor to enable real-time for chat
alter publication supabase_realtime add table chat_messages;
alter publication supabase_realtime add table documents;
alter publication supabase_realtime add table projects;- Open multiple browser tabs to your app
- Test chat functionality
- Verify file upload notifications
- Check project updates sync
Update your .env.local with production values:
NEXT_PUBLIC_SUPABASE_URL=https://your-project-ref.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key
NEXTAUTH_URL=https://your-project-ref.supabase.co/functions/v1/nextjs-app
NEXTAUTH_SECRET=your-production-secret# Enable database optimizations
supabase db optimize
# Configure Edge Function regions (optional)
supabase functions deploy --region us-east-1,eu-west-1# Update your functions
git add .
git commit -m "Update: description of changes"
# Redeploy functions
supabase functions deploy
# Or deploy specific function
supabase functions deploy nextjs-app# Create a new migration
supabase migration new add_new_feature
# Edit the migration file in supabase/migrations/
# Then apply it
supabase db push- Go to Logs in Supabase dashboard
- Monitor Edge Function performance
- Check database usage and optimization suggestions
- Review real-time connection metrics
# Start local Supabase (requires Docker)
supabase start
# This will give you local URLs:
# API URL: http://localhost:54321
# DB URL: postgresql://postgres:postgres@localhost:54322/postgres
# Studio URL: http://localhost:54323# Run Next.js development server
npm run dev
# Run local Edge Functions
supabase functions serve
# Test functions locally
supabase functions serve --env-file .env.localEdge Function Deployment Fails
- Check your Supabase CLI is updated:
supabase --version - Verify you're linked to the correct project:
supabase status - Check function logs:
supabase functions logs nextjs-app
Database Connection Issues
- Verify your project is active in Supabase dashboard
- Check RLS policies allow data access
- Ensure environment variables are set correctly
Authentication Problems
- Verify Edge Function URL in auth settings
- Check NEXTAUTH_SECRET is set in Supabase secrets
- Ensure redirect URLs match your function URLs
File Upload Issues
- Check storage buckets exist and have correct permissions
- Verify file size limits are appropriate
- Check Edge Function has proper CORS headers
- Supabase Docs: supabase.com/docs
- Edge Functions Guide: supabase.com/docs/guides/functions
- CLI Reference: supabase.com/docs/reference/cli
- Database Performance: Monitor in Supabase dashboard
- Edge Function Logs: Real-time logging and debugging
- Real-time Connections: Track WebSocket usage
- Storage Usage: Monitor file upload and storage usage
-- Add custom analytics tracking
create table analytics_events (
id uuid default uuid_generate_v4() primary key,
event_name text not null,
user_id uuid references auth.users(id),
properties jsonb default '{}',
created_at timestamp with time zone default now()
);- RLS policies are properly configured
- Edge Function environment variables are set
- File upload limits are appropriate
- Authentication flows work correctly
- HTTPS is enabled (automatic with Supabase)
- User authentication works via Edge Functions
- Real-time chat functions properly
- File uploads process correctly via Edge Functions
- Database operations succeed
- All pages load from Edge Function
- Edge Function logs are accessible
- Database performance is optimized
- Real-time subscriptions work
- Error tracking is in place
┌─────────────────┐ ┌─────────────────────────────────────┐
│ │ │ SUPABASE │
│ USERS │ │ │
│ │ │ ┌─────────────┐ ┌─────────────┐ │
│ • Web Browsers │◄───┤ │ Edge │ │ PostgreSQL │ │
│ • Mobile Apps │ │ │ Functions │ │ Database │ │
│ • API Clients │ │ │ │ │ │ │
│ │ │ │ • nextjs-app│ │ • Tables │ │
└─────────────────┘ │ │ • file-upload│ │ • RLS │ │
│ │ • chat-handler│ │ • Real-time │ │
│ └─────────────┘ └─────────────┘ │
│ │
│ ┌─────────────┐ ┌─────────────┐ │
│ │ Storage │ │ Auth │ │
│ │ Buckets │ │ System │ │
│ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────┘
Your ConstructAI platform is now fully deployed on Supabase!
✅ Frontend: Served via Supabase Edge Functions ✅ Backend: PostgreSQL with real-time subscriptions ✅ Authentication: Supabase Auth with Edge Function integration ✅ File Storage: Supabase Storage buckets ✅ Real-time: WebSocket connections for chat and updates
Access your deployed application at:
https://your-project-ref.supabase.co/functions/v1/nextjs-app
This unified Supabase deployment provides enterprise-grade performance, security, and scalability for your construction AI platform! 🏗️✨