Database Supabase Inc. Bidirectional
Database Connection
Connection
Bidirectional
Data Flow
26
Components
3
Dependencies

Description

Managed PostgreSQL database serving as the primary persistent data store for the entire peer mentor platform. Hosts all relational data including organisations, contacts, activities, expense claims, certifications, user roles, and audit logs. Row-Level Security (RLS) policies enforce multi-tenant data isolation across all tables.

Detailed Analysis

Supabase PostgreSQL 15 is the central nervous system of the peer mentor platform, serving as the single source of truth for every business record — organisations, contacts, activities, expense claims, certifications, and audit trails. Its Row-Level Security architecture provides enterprise-grade multi-tenant data isolation, meaning each organisation's data is cryptographically separated at the database layer, not just the application layer. This reduces regulatory risk and simplifies compliance audits. The managed Supabase Pro subscription bundles 60,000 monthly active users, 99.9% uptime SLA, and built-in observability — eliminating the need for a dedicated database operations team.

Cost scales predictably with storage size, compute load, and user growth, making budgeting straightforward. The offline-first fallback strategy ensures field workers retain access to critical data even without connectivity, directly improving the quality of service delivery in remote locations.

This integration underpins every other system capability — 25+ repository components depend on it directly. Initial setup requires Supabase project provisioning, schema migrations, and RLS policy configuration across all tables, which should be scoped as a dedicated infrastructure sprint before feature development begins. Environment variables (SUPABASE_URL, SUPABASE_ANON_KEY, SUPABASE_SERVICE_ROLE_KEY) must be managed in CI/CD secrets from day one to prevent credential leakage. Ongoing maintenance includes monitoring query latency (alert threshold: >500ms), disk usage (alert at 80%), and connection pool exhaustion.

The offline-first cache layer (Drift/SQLite) adds complexity to the data layer and requires thorough testing of sync edge cases. External dependency risk is moderate: Supabase outages affect all app functionality, but the 99.9% SLA and offline fallback mitigate this. Team members need familiarity with PostgreSQL RLS policy authoring and Supabase dashboard tooling.

Supabase PostgreSQL 15 is accessed exclusively via the supabase_flutter SDK using the PostgREST HTTP API layer, not direct TCP connections. All queries are mediated through RLS policies that evaluate the JWT claims of the authenticated session — service role key bypasses RLS and must never reach mobile clients. PostgrestException is caught at repository boundaries and mapped to typed domain errors. Transient connection failures trigger exponential backoff retry; constraint violations trigger transaction rollback.

Offline resilience is implemented via Drift/SQLite as a local read cache with queued write operations that sync on reconnect — staleness is surfaced via UI indicators. Performance targets are <200ms for standard queries and <1s for aggregation queries, enforced via Supabase observability alerts. The 128-supabase-stats-views component provides pre-aggregated materialised views to avoid expensive runtime aggregations. RLS policy evaluation time is tracked as a key metric alongside active connections and row counts per table.

Dependencies (3)

Internet connectivity External
supabase_flutter SDK External
Valid Supabase project with RLS policies configured External

Authentication

TypeApi Key
RequirementsSupabase project URL, Supabase anon/service role API key, JWT secret for RLS policy verification
Scopesreadwriterls_bypass (service role only)

Configuration

Required Settings

SUPABASE_URL Required
SUPABASE_ANON_KEY Required
Database schema migrations applied Required

Optional Settings

Connection pool size Optional
Statement timeout Optional
WAL replication settings Optional

Environment Variables

SUPABASE_URL
SUPABASE_ANON_KEY
SUPABASE_SERVICE_ROLE_KEY

Error Handling

PostgrestException caught and mapped to domain errors
Retry with exponential backoff for transient connection failures
Offline-first cache fallback for read operations
Transaction rollback on constraint violations

Monitoring

Health Checks

Supabase dashboard connection status
Database query latency monitoring via Supabase observability

Metrics

Query response time
Active connections
RLS policy evaluation time
Row count per table

Alerts

Connection pool exhaustion
Slow query threshold exceeded (>500ms)
Disk usage above 80%

Performance

Latency< 200ms for standard queries, < 1s for aggregation queries
Availability99.9% uptime SLA on Supabase Pro plan

Rate Limits

Supabase Pro: 60,000 monthly active users included
Database compute scales with Supabase plan

Cost Implications

Pricing ModelMonthly subscription with usage-based overages

Cost Factors

Database storage size
Monthly active users
Compute resources (CPU/RAM)
Egress bandwidth

Security Considerations

Row-Level Security enforced on all tables for multi-tenant isolation
Service role key never exposed to mobile clients
All PII fields subject to encryption before storage
Database credentials stored in secure CI/CD secrets

Fallback Mechanisms

Offline cache via local Drift/SQLite for read-only data
Queued write operations synced on reconnect
Graceful degradation showing cached data with staleness indicator