Storage Architecture
ClypAI’s storage system consists of two main components:PostgreSQL Database
Stores user accounts, organizations, authentication, connections, and metadata
Supabase Storage
Handles video files, thumbnails, and other binary assets
PostgreSQL Database
Overview
ClypAI uses PostgreSQL as the primary relational database, managed through Better Auth’s database hooks and connection pooling. Key Features:- Connection pooling with
pglibrary - Automatic schema management via Better Auth
- Support for organizations and multi-tenancy
- Encrypted connections via SSL
Database Configuration
Set Up PostgreSQL Instance
You can use any PostgreSQL provider:
- Supabase Database
- Neon
- Vercel Postgres
- Self-hosted PostgreSQL
Configure Connection String
Add your database connection string to The connection string format:
.env:Initialize Database
Better Auth will automatically create required tables on first run:
user- User accounts and profilessession- Active user sessionsaccount- OAuth provider connectionsverification- Email verification tokensorganization- Organization/workspace datamember- Organization members and rolesinvitation- Pending invitationswaitlist- Waitlist entries (if enabled)
Database Schema
Better Auth manages the core authentication and organization tables. ClypAI extends this schema with additional tables for:- Projects: Video editing projects and clips
- Connections: Social media platform connections
- Brand Kits: Saved brand assets and templates
- Workers: Background job processing status
- Metrics: Usage tracking and analytics
Database hooks in Better Auth automatically create an organization for each new user with a unique slug generated using ULID.
Connection Pooling
ClypAI uses thepg library’s connection pooling:
- Reuses database connections for better performance
- Handles connection lifecycle automatically
- Supports high concurrent request loads
- Automatic reconnection on failures
Database Backups
Supabase Storage
Overview
Supabase Storage provides S3-compatible object storage for video files and assets. While the database connection is configured, Supabase Storage integration is available for file management. Storage Use Cases:- Source video files uploaded by users
- Rendered/processed video clips
- Thumbnail images and preview frames
- Brand kit assets (logos, fonts, overlays)
- Temporary files during processing
Supabase Setup
Create Supabase Project
- Go to supabase.com
- Create a new project
- Note your project URL and anon key
Storage Buckets Configuration
Recommended bucket settings:Videos Bucket
Videos Bucket
Bucket Name:
videosSettings:- Public: No (private)
- File size limit: 500 MB
- Allowed MIME types:
video/*
Thumbnails Bucket
Thumbnails Bucket
Bucket Name:
thumbnailsSettings:- Public: Yes (with CDN)
- File size limit: 5 MB
- Allowed MIME types:
image/jpeg,image/png,image/webp
Brand Kits Bucket
Brand Kits Bucket
Bucket Name:
brand-kitsSettings:- Public: No (private)
- File size limit: 10 MB
- Allowed MIME types:
image/*,font/*,application/json
File Upload Implementation
Typical file upload flow:Storage Optimization
File Naming Conventions
Recommended file path structure:Edge Config (Feature Flags)
Overview
ClypAI uses Vercel Edge Config for feature flags and runtime configuration:whitelist- Enable/disable whitelist modemaintenance- Put app in maintenance modecoming-soon- Show coming soon page
Configuration
Using Feature Flags
Flags are defined insrc/lib/flags.ts:
Storage Monitoring
Metrics to Track
Database Metrics
- Active connections
- Query performance
- Database size
- Table growth rate
Storage Metrics
- Total storage used
- Bandwidth consumption
- File count per bucket
- Average file size
Setting Up Alerts
Configure alerts for:- Database connection pool exhaustion
- Storage quota approaching limit (>80%)
- Slow query performance (>1s)
- Failed backup jobs
Troubleshooting
Database Connection Issues
Error: “Connection refused” or “Timeout” Solutions:- Verify
DATABASE_URLis correct - Check database firewall allows your IP
- Ensure SSL mode is configured correctly
- Verify database is running and accessible
Storage Upload Failures
Error: Upload fails or times out Solutions:- Check file size is within bucket limits
- Verify MIME type is allowed
- Ensure user has proper RLS policies
- Check network connection and Supabase status
RLS Policy Errors
Error: “Row level security policy violation” Solutions:- Verify user is authenticated
- Check policy matches user’s organization
- Use service role key for admin operations
- Review and update RLS policies
Best Practices
Security
Security
- Always use environment variables for credentials
- Enable Row Level Security (RLS) on all Supabase tables
- Use signed URLs for private files
- Rotate service role keys regularly
- Enable SSL for database connections
Performance
Performance
- Use connection pooling for database
- Implement CDN for public assets
- Compress files before storage
- Set appropriate cache headers
- Use database indexes on frequently queried columns
Cost Optimization
Cost Optimization
- Delete temporary files after processing
- Implement storage lifecycle policies
- Compress videos to reduce storage size
- Use thumbnail generation instead of storing full images
- Monitor and set storage quotas per organization
Backup & Recovery
Backup & Recovery
- Enable automated database backups
- Test restore procedures regularly
- Keep separate backups of critical data
- Document recovery procedures
- Set backup retention policies
Next Steps
Back to Integrations
Return to the integrations overview