Data Layer medium complexity mobile
0
Dependencies
3
Dependents
2
Entities
0
Integrations

Description

Data access layer responsible for fetching organization feature flag configurations from the Supabase `organization_configs` table. Parses the flat key-value features map and maps it to typed FeatureFlag domain objects including rollout metadata.

Feature: Organization-scoped Feature Flags

feature-flag-repository

Summaries

The Feature Flag Repository is the system's authoritative connection to the organization configuration database, ensuring that feature entitlements are always synchronized with the commercial and operational decisions made in the back office. By supporting real-time streaming updates via Supabase Realtime, it enables the business to activate or deactivate features for an organization instantly—without requiring users to restart the app or wait for the next release cycle. This directly supports account management workflows, customer onboarding, and incident response capabilities. The ability to persist admin-initiated flag changes back to the source of truth reduces manual ops effort and eliminates configuration drift between environments.

The Feature Flag Repository has medium complexity and is the only component in the feature flag system with a direct Supabase dependency, making it the primary integration risk point. The team must confirm the `organization_configs` table schema, the shape of the features JSON column, and Supabase RLS policies that govern read and write access before implementation begins. The `watchFlags` stream requires a live Supabase Realtime subscription—this needs to be tested under flaky network conditions and app backgrounding. The `updateFlag` and `updateRolloutCondition` write paths should be gated behind admin-only role checks.

Allocate time for integration testing with a real Supabase instance, not just mocked responses.

FeatureFlagRepository queries the `organization_configs` Supabase table, selecting the `features` JSONB column for a given `organizationId`. Deserialization maps each key in the features map to a `FeatureFlag` domain object—fields include `key`, `enabled`, and optional rollout metadata (`minAppVersion`, `activationDate`). Use `supabase.from('organization_configs').stream(primaryKey: ['id']).eq('id', organizationId)` for the `watchFlags` stream; this leverages Supabase Realtime and returns a `Stream>` that you map to `List`. For writes, call `.update({...}).eq('id', organizationId)` and merge the changed flag key into the existing features JSON.

Add a try/catch with typed `PostgrestException` handling. Keep this class free of Riverpod—inject it as a plain dependency to keep the repository layer testable with a mock Supabase client.

Responsibilities

  • Query the organization_configs table for the active organization's features map
  • Deserialize the JSON features object into a list of FeatureFlag domain models
  • Persist admin flag updates back to the Supabase table
  • Expose a stream for real-time flag updates via Supabase Realtime

Interfaces

getFlags(String organizationId) → Future<List<FeatureFlag>>
watchFlags(String organizationId) → Stream<List<FeatureFlag>>
updateFlag(String organizationId, String flagKey, bool enabled) → Future<void>
updateRolloutCondition(String organizationId, String flagKey, RolloutCondition condition) → Future<void>

Related Data Entities (2)

Data entities managed by this component

API Contract

View full contract →
REST /api/v1/organizations/{organization_id}/feature-flags 6 endpoints
GET /api/v1/organizations/{organization_id}/feature-flags List all feature flags for an organization
GET /api/v1/organizations/{organization_id}/feature-flags/{flag_key} Get a single feature flag by key
POST /api/v1/organizations/{organization_id}/feature-flags Create a new feature flag for an organization
PUT /api/v1/organizations/{organization_id}/feature-flags/{flag_key} Update a feature flag's enabled state or rollout condition
DELETE /api/v1/organizations/{organization_id}/feature-flags/{flag_key} Delete a feature flag for an organization
PATCH /api/v1/organizations/{organization_id}/feature-flags/{flag_key}/rollout Update only the rollout condition for a flag