Overview
Supabase provides the database, authentication, file storage, and real-time capabilities for Zarna. Website: supabase.comFeatures Used
PostgreSQL Database
Managed PostgreSQL with automatic backups
Authentication
Built-in auth with JWT tokens
Storage
S3-compatible file storage
Row Level Security
Firm-level data isolation
Real-time
WebSocket subscriptions (coming soon)
Edge Functions
Serverless functions (future use)
Setup
1. Create Project
- Go to supabase.com
- Click “New Project”
- Configure:
- Name: Zarna Production (or Development)
- Database Password: Generate strong password
- Region: Choose closest to users
- Wait 2-3 minutes for initialization
2. Get API Keys
From Supabase Dashboard → Settings → API:3. Database Setup
Option A: Run Migration Scripts
Option B: Use Supabase CLI
Database Schema
Core Tables
- Companies
- Contacts
- Deals
- Files
Row Level Security (RLS)
Enable RLS on All Tables
Create Policies
Testing RLS
Backend Integration
Python Client
Frontend Client
Storage
File Upload
Storage Buckets
Create storage buckets in Supabase Dashboard → Storage:documents- Company documentsavatars- User profile pictureslogos- Company logosreports- Generated reports
Storage Policies
Real-time Subscriptions
Enable Real-time
Subscribe to Changes
Database Functions
Custom Functions
Create SQL functions for complex operations:Environment Variables
Backend
Frontend
Best Practices
Always use RLS policies
Always use RLS policies
Never rely on application-level security alone. RLS provides defense in depth.
Index frequently queried columns
Index frequently queried columns
Use connection pooling
Use connection pooling
Supabase has built-in connection pooling. For high traffic, use Supavisor.
Monitor query performance
Monitor query performance
Use Supabase Dashboard → Database → Query Performance to identify slow queries.
Regular backups
Regular backups
Supabase automatically backs up daily. Download manual backups for critical changes.
Troubleshooting
Connection error
Connection error
Cause: Invalid URL or keySolution:
- Verify SUPABASE_URL format:
https://project-id.supabase.co - Check key is correct (service_role for backend, anon for frontend)
- Ensure project is not paused (free tier)
RLS blocking queries
RLS blocking queries
Cause: RLS policy too restrictiveSolution:
- Test queries in SQL Editor with
auth.uid()set - Check firm_id is correctly set
- Verify user has permission
- Use service_role key to bypass RLS (backend only)
Slow queries
Slow queries
Cause: Missing indexes or inefficient queriesSolution:
- Add indexes on frequently filtered columns
- Use EXPLAIN ANALYZE to debug
- Check Query Performance in dashboard
- Consider materialized views for complex aggregations
Next Steps
Database Schema
Explore the complete database schema
Backend Overview
See how backend uses Supabase
Authentication
JWT authentication with Supabase
API Reference
Explore the API
