Skip to main content

Supabase Setup Guide

Overview

This guide covers the complete Supabase setup for the Remind Tools monorepo, including database schema, Row Level Security policies, and Flutter integration.

Table of Contents

  1. Local Development Setup
  2. Database Schema
  3. Environment Configuration
  4. Flutter Integration
  5. Running Migrations
  6. Testing

Local Development Setup

Prerequisites

  • Node.js 18+ installed
  • Docker Desktop running
  • Flutter SDK installed

Install Supabase CLI

Initialize Local Supabase

Database Schema

The database schema is organized into versioned migrations in /supabase/migrations/:

Core Tables

  1. profiles - User profiles extending Supabase auth
  2. trips - User trips with AI suggestions
  3. places - Points of interest with PostGIS support
  4. itineraries - Daily planning for trips
  5. trip_collaborators - Trip sharing functionality
  6. audit_log - Data change tracking

Key Features

  • PostGIS extension for geospatial queries
  • Row Level Security (RLS) for multi-tenant isolation
  • Full-text search indexes on trips and places
  • Materialized views for performance optimization
  • Automatic profile creation on user signup

Environment Configuration

1. Create Environment File

Copy the example file and fill in your credentials:

2. Edit .env.development

3. Verify .gitignore

Ensure environment files are not committed:

Flutter Integration

1. Bootstrap Workspace

2. Initialize Supabase in Your App

The Supabase client is configured in /packages/core/lib/infrastructure/database/supabase_client.dart In your main app file:

3. Using the Supabase Client

Running Migrations

Apply All Migrations

Create New Migration

Push to Remote

Testing

1. Test RLS Policies

2. Test Helper Functions

3. Integration Tests

Create test files in /test/ directories:

Domain Entities

The domain entities are defined in /packages/data_models/lib/src/trips/entities/:
  • Profile - User profile with preferences
  • Trip - Trip with status tracking and budget
  • Place - Points of interest with location data
  • Itinerary - Daily activities and planning
Each entity includes:
  • Immutable properties with Equatable
  • Convenient helper methods
  • CopyWith pattern for updates
  • Validation logic

Security Best Practices

  1. Never commit credentials - Use environment files
  2. Use RLS policies - All tables have Row Level Security enabled
  3. Validate input - Use domain entities with validation
  4. Audit changes - audit_log table tracks important changes
  5. Use service role carefully - Only for admin operations

Troubleshooting

Common Issues

  1. Supabase not starting
    • Ensure Docker Desktop is running
    • Check port conflicts (54321, 54322, 54323)
    • Run supabase stop then supabase start
  2. Migration errors
    • Check SQL syntax in migration files
    • Ensure proper order of migrations
    • Review PostgreSQL logs: supabase db logs
  3. Authentication issues
    • Verify environment variables are loaded
    • Check Supabase auth settings
    • Ensure RLS policies are correct
  4. Flutter connection issues
    • Verify SUPABASE_URL and SUPABASE_ANON_KEY
    • Check network connectivity
    • Review Flutter console logs

Next Steps

  1. Implement repository pattern - Create repository interfaces in domain layer
  2. Add data sources - Implement remote and local data sources
  3. Create use cases - Business logic for trip management
  4. Build UI - Create Flutter widgets using BLoC pattern
  5. Add tests - Unit, widget, and integration tests

Resources