Skip to main content

Overview

ClassroomIO uses Supabase as its database and authentication backend. You can use either a local Supabase instance or a cloud-hosted project.

Prerequisites

  • Supabase CLI installed
  • Docker (for local Supabase)
  • Git (to clone the repository)

Option 1: Local Supabase Setup

Install Supabase CLI

# macOS
brew install supabase/tap/supabase

# Windows (via scoop)
scoop bucket add supabase https://github.com/supabase/scoop-bucket.git
scoop install supabase

# Linux
brew install supabase/tap/supabase

Initialize Supabase

  1. Navigate to your ClassroomIO source directory:
cd /path/to/classroomio
  1. The project already includes a supabase directory with configuration. Start Supabase:
supabase start
This will:
  • Start a local Supabase instance using Docker
  • Run all migrations
  • Set up the database schema
  • Start the following services:
    • PostgreSQL database (port 54322)
    • API server (port 54321)
    • Studio UI (port 54323)
    • Inbucket (email testing - port 54324)
  1. Note the output - you’ll need these credentials:
API URL: http://localhost:54321
DB URL: postgresql://postgres:postgres@localhost:54322/postgres
anon key: eyJh...
service_role key: eyJh...
Studio URL: http://localhost:54323

Access Supabase Studio

Open your browser to http://localhost:54323 to access the Supabase Studio dashboard where you can:
  • View and edit database tables
  • Manage authentication
  • Test SQL queries
  • Monitor API usage

Option 2: Supabase Cloud

Create a Project

  1. Go to supabase.com and sign in
  2. Click “New Project”
  3. Fill in:
    • Name: ClassroomIO (or your preferred name)
    • Database Password: Use a strong password
    • Region: Choose closest to your users
  4. Click “Create new project”

Run Migrations

  1. Link your local project to the cloud project:
supabase link --project-ref your-project-ref
  1. Push migrations to your cloud database:
supabase db push
  1. Verify migrations:
supabase db diff

Get API Credentials

  1. Go to Settings > API in your Supabase dashboard
  2. Copy the following:
    • Project URL (PUBLIC_SUPABASE_URL)
    • anon/public key (PUBLIC_SUPABASE_ANON_KEY)
    • service_role key (PRIVATE_SUPABASE_SERVICE_ROLE)

Database Configuration

Configuration File

The supabase/config.toml file contains important settings:
project_id = "classroomio"

[api]
enabled = true
port = 54321
schemas = ["public", "storage", "graphql_public"]
max_rows = 1000

[db]
port = 54322
major_version = 15

[studio]
enabled = true
port = 54323

[auth]
site_url = "http://localhost:3000"
enable_signup = true
jwt_expiry = 3600

[storage]
file_size_limit = "50MiB"

Key Settings

api.max_rows
number
Maximum rows returned from API queriesDefault: 1000
auth.site_url
string
Base URL for email redirectsProduction: Set to your actual domain
storage.file_size_limit
string
Maximum file upload sizeDefault: 50MiB

Running Migrations

ClassroomIO includes multiple database migrations in supabase/migrations/. These handle:
  • Course and lesson management
  • User authentication and profiles
  • Organization and team features
  • Custom domains
  • AI grading
  • Analytics
  • Multi-language support
  • And more…

Apply All Migrations

# Local
supabase db reset

# Cloud (after linking)
supabase db push

Create New Migration

If you need to modify the schema:
supabase migration new your_migration_name
Edit the created file in supabase/migrations/, then apply:
supabase db reset

Check Migration Status

supabase migration list

Seeding Data

ClassroomIO includes a seed file (supabase/seed.sql) with test data:
  • 3 test users (admin, teacher, student)
  • Sample organizations
  • Demo courses with lessons
  • Example exercises and quizzes

Apply Seed Data

supabase db reset
This will run migrations and seed data.

Test Accounts

After seeding, you can log in with:
EmailPasswordRole
[email protected]passwordAdmin
[email protected]passwordTeacher
[email protected]passwordStudent
These are test accounts with known passwords. Never use seed data in production!

Row Level Security (RLS)

ClassroomIO uses Supabase’s Row Level Security for data protection. Migrations include RLS policies for:
  • Courses: Users can only access courses they’re enrolled in or teaching
  • Profiles: Users can view their own profile and update allowed fields
  • Organizations: Members can view organization data based on role
  • Submissions: Students see their own submissions, teachers see all

Verify RLS Policies

In Supabase Studio:
  1. Go to Authentication > Policies
  2. Check each table has appropriate policies
  3. Test with different user roles

Storage Buckets

The seed data creates an avatars bucket for user profile pictures.

Configure Storage

INSERT INTO storage.buckets (id, name, public)
VALUES ('avatars', 'avatars', true);

Storage Policies

Set up policies for who can upload/download:
-- Allow authenticated users to upload avatars
CREATE POLICY "Avatar upload"
ON storage.objects FOR INSERT
TO authenticated
WITH CHECK (bucket_id = 'avatars');

-- Allow public read access
CREATE POLICY "Avatar access"
ON storage.objects FOR SELECT
TO public
USING (bucket_id = 'avatars');

Edge Functions

ClassroomIO includes Supabase Edge Functions in supabase/functions/:
  • notify: Handles notifications
  • grades-tmp: Temporary grading function

Deploy Edge Functions

# Deploy all functions
supabase functions deploy

# Deploy specific function
supabase functions deploy notify

Test Functions Locally

supabase functions serve notify

Authentication Setup

Email Authentication

Enabled by default in config.toml:
[auth.email]
enable_signup = true
enable_confirmations = false  # Set true in production
double_confirm_changes = true

OAuth Providers

To enable social login (Google, GitHub, etc.):
  1. In Supabase Dashboard: Authentication > Providers
  2. Enable desired providers
  3. Add client ID and secret
  4. Configure redirect URLs

Email Templates

Customize email templates in Authentication > Email Templates:
  • Confirmation email
  • Password reset
  • Magic link
  • Email change

Environment Variables

After setting up Supabase, add these to your .env:
.env
# Local Supabase
PUBLIC_SUPABASE_URL=http://localhost:54321
PUBLIC_SUPABASE_ANON_KEY=eyJhbG...
PRIVATE_SUPABASE_SERVICE_ROLE=eyJhbG...

# Cloud Supabase
PUBLIC_SUPABASE_URL=https://your-project.supabase.co
PUBLIC_SUPABASE_ANON_KEY=your-anon-key
PRIVATE_SUPABASE_SERVICE_ROLE=your-service-role-key

Database Backups

Local Backups

supabase db dump -f backup.sql

Cloud Backups

Supabase Cloud provides automatic daily backups (Pro plan and above). Manual backup:
  1. Go to Database > Backups
  2. Click “Create backup”

Monitoring

Local Monitoring

# View logs
supabase logs

# Database logs
supabase logs db

# API logs
supabase logs api

Cloud Monitoring

In Supabase Dashboard:
  • Reports: API usage, database size
  • Logs: Real-time logs explorer
  • Monitoring: Performance metrics

Common Supabase Commands

# Start local Supabase
supabase start

# Stop local Supabase
supabase stop

# Restart Supabase
supabase stop && supabase start

# Reset database (migrations + seed)
supabase db reset

# View status
supabase status

# Link to cloud project
supabase link --project-ref your-ref

# Generate TypeScript types
supabase gen types typescript --local > types/database.types.ts

Troubleshooting

Port Already in Use

If Supabase ports are taken:
# Stop conflicting services
docker ps
docker stop <container-id>

# Or change ports in supabase/config.toml

Migration Errors

# Check migration status
supabase migration list

# Repair migrations
supabase migration repair <version>

# Reset and reapply
supabase db reset

Connection Issues

  1. Verify Supabase is running: supabase status
  2. Check connection string in .env
  3. Ensure firewall allows connections
  4. For cloud: verify API keys are correct

RLS Policy Errors

If queries fail due to RLS:
  1. Check policies in Studio
  2. Verify user is authenticated
  3. Test with service role key (bypasses RLS)
  4. Review migration files for policy definitions

Production Considerations

  1. Enable email confirmations in auth settings
  2. Set up custom SMTP for emails (avoid Supabase’s default)
  3. Configure backups (automatic + manual)
  4. Set up monitoring and alerts
  5. Use connection pooling for high traffic
  6. Enable SSL for database connections
  7. Review and test RLS policies thoroughly
  8. Set appropriate file size limits for storage

Next Steps

Environment Variables

Configure all required variables

Docker Setup

Deploy with Docker

Build docs developers (and LLMs) love