Skip to main content

Overview

Supabase provides the database, authentication, file storage, and real-time capabilities for Zarna. Website: supabase.com

Features 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

  1. Go to supabase.com
  2. Click “New Project”
  3. Configure:
    • Name: Zarna Production (or Development)
    • Database Password: Generate strong password
    • Region: Choose closest to users
  4. Wait 2-3 minutes for initialization

2. Get API Keys

From Supabase Dashboard → Settings → API:
From Settings → API → JWT Settings:
Security:
  • Use service_role key in backend only (bypasses RLS)
  • Use anon key in frontend (respects RLS)
  • Never expose service_role key to frontend

3. Database Setup

Option A: Run Migration Scripts

Option B: Use Supabase CLI

Database Schema

Core Tables

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 documents
  • avatars - User profile pictures
  • logos - Company logos
  • reports - Generated reports

Storage Policies

Real-time Subscriptions

Enable Real-time

Subscribe to Changes

Database Functions

Custom Functions

Create SQL functions for complex operations:
Usage:

Environment Variables

Backend

Frontend

Best Practices

Never rely on application-level security alone. RLS provides defense in depth.
Supabase has built-in connection pooling. For high traffic, use Supavisor.
Use Supabase Dashboard → Database → Query Performance to identify slow queries.
Supabase automatically backs up daily. Download manual backups for critical changes.

Troubleshooting

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)
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)
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

Resources