Supabase Client
Component Detail
Description
Shared singleton that initialises and exposes the Supabase client instance used by all repository layers throughout the app. Configured with the project URL and anon key from environment variables and provides authenticated client access after login.
supabase-client
Summaries
The Supabase Client is the foundational connectivity layer that enables the entire application to securely communicate with backend data services. Without this component, no feature — from user login to activity tracking — can function. By using Supabase as a managed backend platform, the business avoids the cost and complexity of building and maintaining custom authentication, real-time data, and API infrastructure from scratch. The singleton design means the connection is established once and reused efficiently, keeping the app performant and avoiding unnecessary resource consumption.
Transparent token refresh ensures users stay logged in without interruption, directly reducing session abandonment. This component represents a strategic infrastructure investment: it lowers operational overhead, accelerates feature delivery across the entire product, and provides enterprise-grade security out of the box.
As a shared, low-complexity infrastructure component, the Supabase Client is foundational and should be one of the first components delivered and stabilised — all repository layers depend on it. Its configuration relies on environment variables (project URL and anon key), which means the team needs access to the correct Supabase project credentials early in the development cycle to avoid blockers. Testing requirements include verifying correct initialisation on app boot, confirming that authenticated client access is available after login, and validating that token refresh operates without causing observable disruption to active sessions. Since every feature in the application ultimately depends on this client, any instability here has project-wide impact.
Deployment must include proper secret management for credentials across environments (dev, staging, production). Risk is low once established, but environment misconfiguration is the most common source of early integration failures.
This component encapsulates the Supabase JS/Flutter SDK initialisation and exposes a singleton client used by all repository layers. `initialize(url, anonKey)` is called once at app boot with values sourced from environment variables, and must complete before any repository operation is attempted — typically enforced via app initialisation guards. `getClient()` returns the base client, while `getAuthenticatedClient()` returns the session-scoped client with the current user's JWT attached. `onAuthStateChange(callback)` wraps Supabase's native auth listener, allowing the app to react to login, logout, and token refresh events.
Token refresh is handled transparently by the Supabase SDK; the client automatically re-authenticates using stored refresh tokens. This component executes in both mobile and backend contexts, so any platform-specific SDK differences must be accounted for. It has no internal dependencies, making it the base layer of the entire dependency graph — changes here propagate to every consumer.
Responsibilities
- Initialise the Supabase client singleton on app boot
- Provide authenticated client instance to all repositories
- Handle token refresh transparently
Interfaces
initialize(url, anonKey)
getClient()
getAuthenticatedClient()
onAuthStateChange(callback)
Relationships
Dependents (2)
Components that depend on this component