|
| 1 | +# 🚀 Getting Started with dynos_sync |
| 2 | + |
| 3 | +This guide will walk you through building a high-reliability, production-hardened offline-first synchronization layer in under 5 minutes. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## 🏗️ 1. Define Your Implementation |
| 8 | + |
| 9 | +Every **dynos_sync** architecture requires 4 core adapters. You can use our built-in helpers or write your own: |
| 10 | + |
| 11 | +### A. The Local Store (e.g. SQLite via Drift) |
| 12 | +```dart |
| 13 | +class MyLocalStore implements LocalStore { |
| 14 | + @override |
| 15 | + Future<void> upsert(String t, String id, Map<String, dynamic> d) async => ...; |
| 16 | + @override |
| 17 | + Future<void> delete(String t, String id) async => ...; |
| 18 | + @override |
| 19 | + Future<void> clearAll(List<String> tables) async => ...; // Critical for secure logout |
| 20 | +} |
| 21 | +``` |
| 22 | + |
| 23 | +### B. The Remote Store (e.g. Supabase or REST) |
| 24 | +```dart |
| 25 | +class MyRemoteStore implements RemoteStore { |
| 26 | + @override |
| 27 | + Future<void> pushBatch(List<SyncEntry> entries) async => ...; |
| 28 | + @override |
| 29 | + Future<List<Map<String, dynamic>>> pullSince(String t, DateTime ts) async => ...; |
| 30 | +} |
| 31 | +``` |
| 32 | + |
| 33 | +--- |
| 34 | + |
| 35 | +## ⚡ 2. Initialize the Engine |
| 36 | + |
| 37 | +Configure the `SyncEngine` with your schemas and security policies. |
| 38 | + |
| 39 | +```dart |
| 40 | +final sync = SyncEngine( |
| 41 | + local: MyLocalStore(), |
| 42 | + remote: MyRemoteStore(), |
| 43 | + queue: MyQueueStore(), |
| 44 | + timestamps: MyTimestampStore(), |
| 45 | + tables: ['workouts', 'profiles'], |
| 46 | + config: const SyncConfig( |
| 47 | + sensitiveFields: ['password', 'ssn'], // 🛡️ Automasking for PII |
| 48 | + useExponentialBackoff: true, // 📶 Scalable retry logic |
| 49 | + batchSize: 50, // 🧠 Memory-efficient processing |
| 50 | + ), |
| 51 | +); |
| 52 | +``` |
| 53 | + |
| 54 | +--- |
| 55 | + |
| 56 | +## 🦾 3. Efficient Backgrounding |
| 57 | + |
| 58 | +To keep your UI at 120 FPS during massive data pulls (e.g., 100k rows), use the `IsolateSyncEngine`: |
| 59 | + |
| 60 | +```dart |
| 61 | +final manager = IsolateSyncEngine(sync); |
| 62 | +
|
| 63 | +// Runs in a dedicated background worker |
| 64 | +await manager.syncAllInBackground(); |
| 65 | +``` |
| 66 | + |
| 67 | +--- |
| 68 | + |
| 69 | +## 🛡️ 4. Security Practices |
| 70 | + |
| 71 | +### The "Session Void" Pattern |
| 72 | +Ensure you call logout explicitly to purge sensitive un-synced data on shared devices: |
| 73 | + |
| 74 | +```dart |
| 75 | +await sync.logout(); // Triggers table-scoped local wiping |
| 76 | +``` |
| 77 | + |
| 78 | +### JSON Exfiltration Prevention |
| 79 | +Set `maxPayloadBytes` in the config to prevent oversized accidental writes from jamming your sync pipeline. |
| 80 | + |
| 81 | +--- |
| 82 | + |
| 83 | +## 📚 What's Next? |
| 84 | +* Read the **[🏟️ Architecture Guide](architecture.md)** for protocol deep-dives. |
| 85 | +* Check the **[🛡️ Security Audit](security_audit.md)** for the 42 attack vectors. |
| 86 | +* Explore **[example/example.dart](../example/example.dart)** for a complete Supabase integration sample. |
| 87 | + |
| 88 | +--- |
| 89 | + |
| 90 | +*Battle-Tested by [dynos.fit](https://dynos.fit)* |
0 commit comments