Documentation

    Concepts, value, and typical clone scenarios — less code.

    Welcome to Ring
    Quick Reference
    Getting Started
    Prerequisites
    Installation
    First Success Validation
    Next Steps
    Features
    Multi-Vendor Store
    SubscriptionConductor
    PaymentConductor
    Payments Overview
    WayForPay Payment Integration
    Wallet & Credit System
    WalletConductor
    Affiliate & Referral Enablement
    Referral Codes (Refcodes)
    NFT Exhibition Marketplace
    Solana NFT Gates
    Token Staking System
    Owner Project Lab
    Entities
    Opportunities
    Real-Time Messaging
    Ring Tasks
    WebRTC Calls & STUNner TURN
    News Module
    Member Blogs
    Public Profile Pages
    Username Reservation System
    Scientific Editor
    Notifications
    Push Notifications with FCM (Ring-Powered)
    Email AI-CRM
    Ring Mailer & RingdomX Mail
    Tunnel Protocol
    VideoConductor
    MediaConductor
    Generative Gallery
    Authentication
    Security & Compliance
    Admin console
    Admin Wiki
    Manage via Telegram
    Locale System
    Mobile Experience
    Performance Optimization Patterns
    Examples
    Quick Start
    Basic Setup
    White Label
    Custom Branding
    Web3 Integration
    Real World
    Advanced Features
    Customization
    Quick Start — Your First Ring Clone
    Customization Guide
    Branding
    Themes
    Features
    Localization
    Token Economics Setup
    Payment Gateway Integration
    Reference Ring deployments
    Web3
    Token launch jurisdictions
    Wallet
    Wallet Security Tips
    Integrations
    Ethereum wallets (Wagmi v3)
    RingFileBase (object storage API)
    Ring CDN (RingFileBase edge)
    Deployment
    Self-hosted deployment
    Vercel
    Docker
    Environment Configuration
    Monitoring & Analytics
    Performance Optimization
    Backup & Recovery
    Architecture
    Data Model
    Security
    Real Time
    Discovery Mutation Sync
    PaymentConductor architecture
    WalletConductor architecture
    Development
    Ring MCP Server

    Quick entry (CTOs · auditors · agents)

    Welcome — mission & audiences
    Quick Reference
    Getting started
    Architecture & Auth.js
    Backend modes & databases (DB_BACKEND_MODE)
    Self-hosted
    Ring MCP Tools
    Ring MCP Server
    Token economics
    Token launch jurisdictions
    Deploy (Docker · k8s)
    Security & compliance reads
    ringdom.org — LegioX homebase
    Source — MIT license (GitHub)

    Documentation

    Concepts, value, and typical clone scenarios — less code.

    Welcome to Ring
    Quick Reference
    Getting Started
    Prerequisites
    Installation
    First Success Validation
    Next Steps
    Features
    Multi-Vendor Store
    SubscriptionConductor
    PaymentConductor
    Payments Overview
    WayForPay Payment Integration
    Wallet & Credit System
    WalletConductor
    Affiliate & Referral Enablement
    Referral Codes (Refcodes)
    NFT Exhibition Marketplace
    Solana NFT Gates
    Token Staking System
    Owner Project Lab
    Entities
    Opportunities
    Real-Time Messaging
    Ring Tasks
    WebRTC Calls & STUNner TURN
    News Module
    Member Blogs
    Public Profile Pages
    Username Reservation System
    Scientific Editor
    Notifications
    Push Notifications with FCM (Ring-Powered)
    Email AI-CRM
    Ring Mailer & RingdomX Mail
    Tunnel Protocol
    VideoConductor
    MediaConductor
    Generative Gallery
    Authentication
    Security & Compliance
    Admin console
    Admin Wiki
    Manage via Telegram
    Locale System
    Mobile Experience
    Performance Optimization Patterns
    Examples
    Quick Start
    Basic Setup
    White Label
    Custom Branding
    Web3 Integration
    Real World
    Advanced Features
    Customization
    Quick Start — Your First Ring Clone
    Customization Guide
    Branding
    Themes
    Features
    Localization
    Token Economics Setup
    Payment Gateway Integration
    Reference Ring deployments
    Web3
    Token launch jurisdictions
    Wallet
    Wallet Security Tips
    Integrations
    Ethereum wallets (Wagmi v3)
    RingFileBase (object storage API)
    Ring CDN (RingFileBase edge)
    Deployment
    Self-hosted deployment
    Vercel
    Docker
    Environment Configuration
    Monitoring & Analytics
    Performance Optimization
    Backup & Recovery
    Architecture
    Data Model
    Security
    Real Time
    Discovery Mutation Sync
    PaymentConductor architecture
    WalletConductor architecture
    Development
    Ring MCP Server

    Quick entry (CTOs · auditors · agents)

    Welcome — mission & audiences
    Quick Reference
    Getting started
    Architecture & Auth.js
    Backend modes & databases (DB_BACKEND_MODE)
    Self-hosted
    Ring MCP Tools
    Ring MCP Server
    Token economics
    Token launch jurisdictions
    Deploy (Docker · k8s)
    Security & compliance reads
    ringdom.org — LegioX homebase
    Source — MIT license (GitHub)

    Documentation

    Concepts, value, and typical clone scenarios — less code.

    Welcome to Ring
    Quick Reference
    Getting Started
    Prerequisites
    Installation
    First Success Validation
    Next Steps
    Features
    Multi-Vendor Store
    SubscriptionConductor
    PaymentConductor
    Payments Overview
    WayForPay Payment Integration
    Wallet & Credit System
    WalletConductor
    Affiliate & Referral Enablement
    Referral Codes (Refcodes)
    NFT Exhibition Marketplace
    Solana NFT Gates
    Token Staking System
    Owner Project Lab
    Entities
    Opportunities
    Real-Time Messaging
    Ring Tasks
    WebRTC Calls & STUNner TURN
    News Module
    Member Blogs
    Public Profile Pages
    Username Reservation System
    Scientific Editor
    Notifications
    Push Notifications with FCM (Ring-Powered)
    Email AI-CRM
    Ring Mailer & RingdomX Mail
    Tunnel Protocol
    VideoConductor
    MediaConductor
    Generative Gallery
    Authentication
    Security & Compliance
    Admin console
    Admin Wiki
    Manage via Telegram
    Locale System
    Mobile Experience
    Performance Optimization Patterns
    Examples
    Quick Start
    Basic Setup
    White Label
    Custom Branding
    Web3 Integration
    Real World
    Advanced Features
    Customization
    Quick Start — Your First Ring Clone
    Customization Guide
    Branding
    Themes
    Features
    Localization
    Token Economics Setup
    Payment Gateway Integration
    Reference Ring deployments
    Web3
    Token launch jurisdictions
    Wallet
    Wallet Security Tips
    Integrations
    Ethereum wallets (Wagmi v3)
    RingFileBase (object storage API)
    Ring CDN (RingFileBase edge)
    Deployment
    Self-hosted deployment
    Vercel
    Docker
    Environment Configuration
    Monitoring & Analytics
    Performance Optimization
    Backup & Recovery
    Architecture
    Data Model
    Security
    Real Time
    Discovery Mutation Sync
    PaymentConductor architecture
    WalletConductor architecture
    Development
    Ring MCP Server

    Quick entry (CTOs · auditors · agents)

    Welcome — mission & audiences
    Quick Reference
    Getting started
    Architecture & Auth.js
    Backend modes & databases (DB_BACKEND_MODE)
    Self-hosted
    Ring MCP Tools
    Ring MCP Server
    Token economics
    Token launch jurisdictions
    Deploy (Docker · k8s)
    Security & compliance reads
    ringdom.org — LegioX homebase
    Source — MIT license (GitHub)
    1. Docs
    2. /Architecture
    3. /Backend modes and databases

    Updated Jul 7, 20264 min listen

    Ring Platform Logo

    Завантаження документації...

    Підготовка контенту платформи Ring

    1. Docs
    2. /Architecture
    3. /Backend modes and databases

    Updated Jul 7, 20264 min listen

    Ring Platform Logo

    Завантаження документації...

    Підготовка контенту платформи Ring

    1. Docs
    2. /Architecture
    3. /Backend modes and databases

    Updated Jul 7, 20264 min listen

    Ring Platform Logo

    Завантаження документації...

    Підготовка контенту платформи Ring

    Backend modes and databases

    Use the Founder / Developer tabs to filter this page for your role. The DB_BACKEND_MODE environment variable is required — the platform will not start without it.

    Ring Platform uses a single codebase with a required runtime switch: DB_BACKEND_MODE. The value selects which database adapters are registered, whether Firestore is used for application data, and how push notifications are wired.

    ModePrimary databaseFirebase useBest for
    k8s-postgres-fcmPostgreSQL 16 + PostGISFCM push onlyProduction self-hosted, local dev
    firebase-fullFirestore (first-class)Everything: DB, FCM, Storage, AI, HostingVercel Edge, clones, rapid prototyping
    supabase-fcmSupabase PostgreSQLFCM push onlyManaged cloud PostgreSQL

    Naming: Production on your own Postgres is often described as "self‑hosted PostgreSQL + FCM." The enum value remains k8s-postgres-fcm — renaming would break every deployment and clone without a coordinated migration.

    Implementation files: lib/database/backend-mode-config.ts, lib/database/DatabaseService.ts, lib/database/BackendSelector.ts, lib/database/shared-pg-pool.ts, lib/services/firebase-service-manager.ts (SSOT helpers for firebase-full).

    Firebase integration

    k8s-postgres-fcm mode

    Push notifications (FCM)

    Database selection guide

    Environment variables

    Tunnel protocol

    Which mode should I choose?

    ScenarioRecommended modeWhy
    Self-hosted production (k3s, K8s)k8s-postgres-fcmFull data sovereignty, PostgreSQL performance, PostGIS spatial queries
    Rapid prototyping / MVPfirebase-fullZero database provisioning, free FCM push, auto-scale
    Ring clone (white-label)firebase-fullNo PostgreSQL dependency for the clone operator
    Vercel Edge deploymentfirebase-fullVercel Edge Runtime + Firestore = no cold-start DB connection
    Cloud PostgreSQL (no K8s)supabase-fcm

    Architecture by mode

    Three-mode architecture comparison

    Database routing rules (PostgreSQL modes)

    All application CRUD goes through db() from @/lib/database:

    • readDoc, createDoc, updateDoc, deleteDoc, queryDocs — document-shaped collections
    • findById, create, update, delete, query, transaction — legacy DatabaseService surface

    Raw SQL escape hatch: getSharedPgPool() in lib/database/shared-pg-pool.ts — calls initializeDatabase() then returns the adapter pool. Use only for PostGIS / SQL the doc-model cannot express. new Pool( is allowed only under lib/database/ (enforced by validate-provider-ssot.sh).

    2026-07-07 audit: Three rogue private pools in platform-settings-service.ts, ring-token-oracle.ts, and geolocation-service.ts were eliminated. Only platform_settings had a real hybrid-table bypass; those modules now use db().*Doc or getSharedPgPool().

    Backend selection in code

    Firebase in k8s-postgres-fcm and supabase-fcm

    Backend modes and databases

    Use the Founder / Developer tabs to filter this page for your role. The DB_BACKEND_MODE environment variable is required — the platform will not start without it.

    Ring Platform uses a single codebase with a required runtime switch: DB_BACKEND_MODE. The value selects which database adapters are registered, whether Firestore is used for application data, and how push notifications are wired.

    ModePrimary databaseFirebase useBest for
    k8s-postgres-fcmPostgreSQL 16 + PostGISFCM push onlyProduction self-hosted, local dev
    firebase-fullFirestore (first-class)Everything: DB, FCM, Storage, AI, HostingVercel Edge, clones, rapid prototyping
    supabase-fcmSupabase PostgreSQLFCM push onlyManaged cloud PostgreSQL

    Naming: Production on your own Postgres is often described as "self‑hosted PostgreSQL + FCM." The enum value remains k8s-postgres-fcm — renaming would break every deployment and clone without a coordinated migration.

    Implementation files: lib/database/backend-mode-config.ts, lib/database/DatabaseService.ts, lib/database/BackendSelector.ts, lib/database/shared-pg-pool.ts, lib/services/firebase-service-manager.ts (SSOT helpers for firebase-full).

    Firebase integration

    k8s-postgres-fcm mode

    Push notifications (FCM)

    Database selection guide

    Environment variables

    Tunnel protocol

    Which mode should I choose?

    ScenarioRecommended modeWhy
    Self-hosted production (k3s, K8s)k8s-postgres-fcmFull data sovereignty, PostgreSQL performance, PostGIS spatial queries
    Rapid prototyping / MVPfirebase-fullZero database provisioning, free FCM push, auto-scale
    Ring clone (white-label)firebase-fullNo PostgreSQL dependency for the clone operator
    Vercel Edge deploymentfirebase-fullVercel Edge Runtime + Firestore = no cold-start DB connection
    Cloud PostgreSQL (no K8s)supabase-fcm

    Architecture by mode

    Three-mode architecture comparison

    Database routing rules (PostgreSQL modes)

    All application CRUD goes through db() from @/lib/database:

    • readDoc, createDoc, updateDoc, deleteDoc, queryDocs — document-shaped collections
    • findById, create, update, delete, query, transaction — legacy DatabaseService surface

    Raw SQL escape hatch: getSharedPgPool() in lib/database/shared-pg-pool.ts — calls initializeDatabase() then returns the adapter pool. Use only for PostGIS / SQL the doc-model cannot express. new Pool( is allowed only under lib/database/ (enforced by validate-provider-ssot.sh).

    2026-07-07 audit: Three rogue private pools in platform-settings-service.ts, ring-token-oracle.ts, and geolocation-service.ts were eliminated. Only platform_settings had a real hybrid-table bypass; those modules now use db().*Doc or getSharedPgPool().

    Backend selection in code

    Firebase in k8s-postgres-fcm and supabase-fcm

    Backend modes and databases

    Use the Founder / Developer tabs to filter this page for your role. The DB_BACKEND_MODE environment variable is required — the platform will not start without it.

    Ring Platform uses a single codebase with a required runtime switch: DB_BACKEND_MODE. The value selects which database adapters are registered, whether Firestore is used for application data, and how push notifications are wired.

    ModePrimary databaseFirebase useBest for
    k8s-postgres-fcmPostgreSQL 16 + PostGISFCM push onlyProduction self-hosted, local dev
    firebase-fullFirestore (first-class)Everything: DB, FCM, Storage, AI, HostingVercel Edge, clones, rapid prototyping
    supabase-fcmSupabase PostgreSQLFCM push onlyManaged cloud PostgreSQL

    Naming: Production on your own Postgres is often described as "self‑hosted PostgreSQL + FCM." The enum value remains k8s-postgres-fcm — renaming would break every deployment and clone without a coordinated migration.

    Implementation files: lib/database/backend-mode-config.ts, lib/database/DatabaseService.ts, lib/database/BackendSelector.ts, lib/database/shared-pg-pool.ts, lib/services/firebase-service-manager.ts (SSOT helpers for firebase-full).

    Firebase integration

    k8s-postgres-fcm mode

    Push notifications (FCM)

    Database selection guide

    Environment variables

    Tunnel protocol

    Which mode should I choose?

    ScenarioRecommended modeWhy
    Self-hosted production (k3s, K8s)k8s-postgres-fcmFull data sovereignty, PostgreSQL performance, PostGIS spatial queries
    Rapid prototyping / MVPfirebase-fullZero database provisioning, free FCM push, auto-scale
    Ring clone (white-label)firebase-fullNo PostgreSQL dependency for the clone operator
    Vercel Edge deploymentfirebase-fullVercel Edge Runtime + Firestore = no cold-start DB connection
    Cloud PostgreSQL (no K8s)supabase-fcm

    Architecture by mode

    Three-mode architecture comparison

    Database routing rules (PostgreSQL modes)

    All application CRUD goes through db() from @/lib/database:

    • readDoc, createDoc, updateDoc, deleteDoc, queryDocs — document-shaped collections
    • findById, create, update, delete, query, transaction — legacy DatabaseService surface

    Raw SQL escape hatch: getSharedPgPool() in lib/database/shared-pg-pool.ts — calls initializeDatabase() then returns the adapter pool. Use only for PostGIS / SQL the doc-model cannot express. new Pool( is allowed only under lib/database/ (enforced by validate-provider-ssot.sh).

    2026-07-07 audit: Three rogue private pools in platform-settings-service.ts, ring-token-oracle.ts, and geolocation-service.ts were eliminated. Only platform_settings had a real hybrid-table bypass; those modules now use db().*Doc or getSharedPgPool().

    Backend selection in code

    Firebase in k8s-postgres-fcm and supabase-fcm

    Managed PostgreSQL with Supabase, FCM push
    Push notifications neededAny modeFCM is optional and available in all three modes

    Why connection pooling matters

    In k8s-postgres-fcm and supabase-fcm, every feature module shares one adapter pool. You do not get surprise connection spikes when admin settings, wallet oracle, geolocation, or email CRM load concurrently — they all route through db() or the sanctioned getSharedPgPool() escape hatch for PostGIS.

    Cost comparison

    Aspectk8s-postgres-fcmfirebase-fullsupabase-fcm
    DatabaseInfrastructure cost onlyPay-per-read/writeSupabase tier pricing
    Push (FCM)FreeFreeFree
    StorageVercel Blob / self-hostedFirebase Storage (free tier)Supabase Storage
    ComputeK8s / DockerVercel Edge / Cloud RunVercel / Cloud Run
    AILLM client via lib/ai/llm-client.tsFirebase AI Logic + GeminiLLM client via lib/ai/llm-client.ts
  1. Application data routes through db() / PostgreSQLAdapter
  2. getAdminDb() returns a mock Firestore when shouldUseFirebaseForDatabase() is false
  3. FCM uses Firebase project credentials for push delivery only
  4. build-mock.server.ts provides type-compatible mocks during SSG and Postgres-primary modes
  5. Firebase in firebase-full mode

    • All application data goes to Firestore via FirebaseAdapter
    • lib/services/firebase-service-manager.ts provides 30+ React 19 cache()-native SSOT helpers
    • 3 atomic write primitives wrap read-modify-write in a single Firestore transaction
    • 6 real-time listener factories pair with Tunnel for live UI updates

    React 19 cache() pattern

    Eliminates duplicate Firestore reads within a single SSG/SSR cycle.

    Supabase: two different roles

    1. DB_BACKEND_MODE=supabase-fcm — PostgreSQL on Supabase; same Postgres-primary + FCM pattern as k8s mode
    2. Tunnel realtime (NEXT_PUBLIC_TUNNEL_TRANSPORT=supabase) — optional Realtime channel in lib/tunnel/transports/supabase-transport.ts. Orthogonal to which SQL backend owns your tables.

    Auth.js and database mode

    Auth tables live in PostgreSQL (k8s-postgres-fcm, supabase-fcm) or Firestore (firebase-full). See lib/auth/postgres-adapter.ts / data/schema.sql for the SQL path.

    Related documentation

    k8s-postgres-fcm mode

    Data model

    Firebase integration

    Database selection guide

    Environment variables

    Tunnel protocol

    Code structure

    typescript
    
    // lib/database/backend-mode-config.ts
    export type BackendMode = 'k8s-postgres-fcm' | 'firebase-full' | 'supabase-fcm'
    
    export function shouldUseFirebaseForDatabase(): boolean {
      return detectBackendMode() === 'firebase-full'
    }
    typescript
    
    import { cache } from 'react'
    
    export const getCachedUserCreditBalance = cache(async (userId: string) => {
      // Firestore read — cached for the duration of the request
    })
    Managed PostgreSQL with Supabase, FCM push
    Push notifications neededAny modeFCM is optional and available in all three modes

    Why connection pooling matters

    In k8s-postgres-fcm and supabase-fcm, every feature module shares one adapter pool. You do not get surprise connection spikes when admin settings, wallet oracle, geolocation, or email CRM load concurrently — they all route through db() or the sanctioned getSharedPgPool() escape hatch for PostGIS.

    Cost comparison

    Aspectk8s-postgres-fcmfirebase-fullsupabase-fcm
    DatabaseInfrastructure cost onlyPay-per-read/writeSupabase tier pricing
    Push (FCM)FreeFreeFree
    StorageVercel Blob / self-hostedFirebase Storage (free tier)Supabase Storage
    ComputeK8s / DockerVercel Edge / Cloud RunVercel / Cloud Run
    AILLM client via lib/ai/llm-client.tsFirebase AI Logic + GeminiLLM client via lib/ai/llm-client.ts
  6. Application data routes through db() / PostgreSQLAdapter
  7. getAdminDb() returns a mock Firestore when shouldUseFirebaseForDatabase() is false
  8. FCM uses Firebase project credentials for push delivery only
  9. build-mock.server.ts provides type-compatible mocks during SSG and Postgres-primary modes
  10. Firebase in firebase-full mode

    • All application data goes to Firestore via FirebaseAdapter
    • lib/services/firebase-service-manager.ts provides 30+ React 19 cache()-native SSOT helpers
    • 3 atomic write primitives wrap read-modify-write in a single Firestore transaction
    • 6 real-time listener factories pair with Tunnel for live UI updates

    React 19 cache() pattern

    Eliminates duplicate Firestore reads within a single SSG/SSR cycle.

    Supabase: two different roles

    1. DB_BACKEND_MODE=supabase-fcm — PostgreSQL on Supabase; same Postgres-primary + FCM pattern as k8s mode
    2. Tunnel realtime (NEXT_PUBLIC_TUNNEL_TRANSPORT=supabase) — optional Realtime channel in lib/tunnel/transports/supabase-transport.ts. Orthogonal to which SQL backend owns your tables.

    Auth.js and database mode

    Auth tables live in PostgreSQL (k8s-postgres-fcm, supabase-fcm) or Firestore (firebase-full). See lib/auth/postgres-adapter.ts / data/schema.sql for the SQL path.

    Related documentation

    k8s-postgres-fcm mode

    Data model

    Firebase integration

    Database selection guide

    Environment variables

    Tunnel protocol

    Code structure

    typescript
    
    // lib/database/backend-mode-config.ts
    export type BackendMode = 'k8s-postgres-fcm' | 'firebase-full' | 'supabase-fcm'
    
    export function shouldUseFirebaseForDatabase(): boolean {
      return detectBackendMode() === 'firebase-full'
    }
    typescript
    
    import { cache } from 'react'
    
    export const getCachedUserCreditBalance = cache(async (userId: string) => {
      // Firestore read — cached for the duration of the request
    })
    Managed PostgreSQL with Supabase, FCM push
    Push notifications neededAny modeFCM is optional and available in all three modes

    Why connection pooling matters

    In k8s-postgres-fcm and supabase-fcm, every feature module shares one adapter pool. You do not get surprise connection spikes when admin settings, wallet oracle, geolocation, or email CRM load concurrently — they all route through db() or the sanctioned getSharedPgPool() escape hatch for PostGIS.

    Cost comparison

    Aspectk8s-postgres-fcmfirebase-fullsupabase-fcm
    DatabaseInfrastructure cost onlyPay-per-read/writeSupabase tier pricing
    Push (FCM)FreeFreeFree
    StorageVercel Blob / self-hostedFirebase Storage (free tier)Supabase Storage
    ComputeK8s / DockerVercel Edge / Cloud RunVercel / Cloud Run
    AILLM client via lib/ai/llm-client.tsFirebase AI Logic + GeminiLLM client via lib/ai/llm-client.ts
  11. Application data routes through db() / PostgreSQLAdapter
  12. getAdminDb() returns a mock Firestore when shouldUseFirebaseForDatabase() is false
  13. FCM uses Firebase project credentials for push delivery only
  14. build-mock.server.ts provides type-compatible mocks during SSG and Postgres-primary modes
  15. Firebase in firebase-full mode

    • All application data goes to Firestore via FirebaseAdapter
    • lib/services/firebase-service-manager.ts provides 30+ React 19 cache()-native SSOT helpers
    • 3 atomic write primitives wrap read-modify-write in a single Firestore transaction
    • 6 real-time listener factories pair with Tunnel for live UI updates

    React 19 cache() pattern

    Eliminates duplicate Firestore reads within a single SSG/SSR cycle.

    Supabase: two different roles

    1. DB_BACKEND_MODE=supabase-fcm — PostgreSQL on Supabase; same Postgres-primary + FCM pattern as k8s mode
    2. Tunnel realtime (NEXT_PUBLIC_TUNNEL_TRANSPORT=supabase) — optional Realtime channel in lib/tunnel/transports/supabase-transport.ts. Orthogonal to which SQL backend owns your tables.

    Auth.js and database mode

    Auth tables live in PostgreSQL (k8s-postgres-fcm, supabase-fcm) or Firestore (firebase-full). See lib/auth/postgres-adapter.ts / data/schema.sql for the SQL path.

    Related documentation

    k8s-postgres-fcm mode

    Data model

    Firebase integration

    Database selection guide

    Environment variables

    Tunnel protocol

    Code structure

    typescript
    
    // lib/database/backend-mode-config.ts
    export type BackendMode = 'k8s-postgres-fcm' | 'firebase-full' | 'supabase-fcm'
    
    export function shouldUseFirebaseForDatabase(): boolean {
      return detectBackendMode() === 'firebase-full'
    }
    typescript
    
    import { cache } from 'react'
    
    export const getCachedUserCreditBalance = cache(async (userId: string) => {
      // Firestore read — cached for the duration of the request
    })