Skip to main content
Complete setup guide: See /docs/integrations/ChatSync.md in the project

What Is Chat Sync?

Offline-First

Writes go to local database first (fast!)

Background Sync

Syncs to cloud in background

Cross-Device

Access from all devices

Optional

Enable only when needed

Quick Overview

1

Run Migration

Create Supabase tables:
# In Supabase Dashboard SQL Editor
# Run: supabase/migrations/20241016000000_chat_sync.sql
2

Enable Feature Flag

In FeatureFlags.swift:
public static var chatSyncEnabled: Bool {
    #if DEBUG
    return true  // Change from false
    #else
    return true
    #endif
}
3

Uncomment Implementations

Uncomment in Storage package:
  • SupabaseConversationRepository.swift
  • SupabaseMessageRepository.swift
4

Wire Up in CompositionRoot

Enable hybrid repositories:
self.conversationRepository = HybridConversationRepository(
    local: localRepo,
    remote: remoteRepo
)

How It Works

Write Flow:
User sends message → Local SwiftData (instant!) → Background sync to Supabase

Read Flow:
App opens → Show local data (instant!) → Background pull from Supabase → Update UI
Benefits:
  • ✅ Instant writes (no network wait)
  • ✅ Works offline
  • ✅ Syncs when online
  • ✅ Graceful degradation

Prerequisites

  • Supabase project configured
  • Supabase dependency added to Storage package
  • User authenticated

What You Get

After setup:
  • ✅ Conversations sync across devices
  • ✅ Messages sync across devices
  • ✅ Offline-first behavior preserved
  • ✅ Automatic conflict resolution
  • ✅ Background sync (non-blocking)

Complete Guide

The 22KB comprehensive guide includes:
  • Database schema design
  • Row Level Security policies
  • Repository implementations
  • Hybrid sync strategy
  • Conflict resolution
  • Testing procedures
  • Troubleshooting

View Complete Setup Guide

Find complete 22KB chat sync guide with architecture diagrams in your project

Need Help?

  • 📖 Complete troubleshooting section in full guide
  • 💬 Create an issue
  • 🔍 Check Supabase Dashboard logs
I