Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
translate ▾

Modern-Apps.git / apple / Hub / README.md

README.md6.8 KiBRenderedCodeRaw
1# EverySync Hub — Apple shell (Phase 3a)
2
3Sync hub. **All merge / transport / crypto lives in the shared XCFramework**
4(`everysync-core` KMP); this target runs `SyncDriver` cycles, owns the
5App-Group envelope store, and sinks todos / contacts / calendar into the
6system stores (Reminders, Contacts, Calendar). There is **no standalone Todo
7app** — tasks surface in the system Reminders app, matching the plan.
8
9## Architecture
10
11```
12HubSync ──► EverysyncCore.xcframework ──► relay
13 │ │
14 │ schedules │ merge / TOTP / PQC /
15 │ cycles only │ transport / cursors
16 ▼ ▼
17App-Group envelope store ◄── Passwords / Notes shells (IPC, see ../IPC_CONTRACT.md)
18 │
19 ├──► EKReminder sink (todos) ──► Reminders app
20 ├──► CNContact sink (contacts)
21 └──► EKEvent sink (calendar)
22```
23
24The hub is the only process that talks to the relay. Passwords/Notes shells
25read and write envelopes through the IPC store; the hub pushes/pulls.
26
27## KMP entry points this shell will call (nothing else)
28
29| Kotlin FQN | Used for |
30|---|---|
31| `core.data.RemoteTodo` | Envelope on `todos:<vaultId>`: `uid / title / notes / done / dueAt (epoch ms, nullable) / position / createdAt / deleted / updatedAt`. |
32| `core.sync.adapters.TodoKind` | `syncId=uid`, LWW on `updatedAt`, canonical strips identity/position/timestamps (reorder is not an edit), `contentKey = "todo␀" + title + "␀" + createdAt`. Todos soft-delete. |
33| `core.data.RemoteContact` | Envelope: name parts + organization + note + `phones/emails/addresses` (`TypedValue(value, type)`; type ints mirror Android `ContactsContract`) + ISO-8601 `birthday` + `etag/href/deleted/updatedAt`. |
34| `core.data.RemoteEvent` | Envelope: `calendarId / summary / description / location / startMillis / endMillis / allDay / timezone / rrule (no RRULE: prefix) / recurrenceId / etag / href / deleted / updatedAt`. |
35| `core.provider.SyncDriver` + `core.platform.RelayCursorStore` | Sync cycles; cursor keys `relay_cursor:<type>:<vault>:<channel>`. |
36| `core.network.IosRelayTransport` | Ktor-Darwin + trust pinning (lands Phase 3; stub today). Channels via `recordChannel` (`passwords:`/`notes:`/`todos:` per vault), `members:`/`keys:`/`owner:`/`title:` per vault, `inbox:<deviceId>`, blobs `notes-blobs:<vaultId>`. |
37| `core.network.RelayRoles` / `RelayLinks` | Role checks and `everysync://join/…` + share-link parsing stay in Kotlin. Passwords vaults offer EDITOR only, never VIEWER. |
38| PQC cinterop (`IOS_PQC_NOTES.md`) | Same 10 fns as Passwords/Notes. |
39
40## Todos → Reminders sink (no Todo app)
41
42`EKEventStore` + `requestAccess(to: .reminder)`; synced tasks live in a
43dedicated hub-managed `EKCalendar` (or the default list) and appear in the
44system Reminders app. Field mapping:
45
46| `RemoteTodo` | `EKReminder` |
47|---|---|
48| `uid` | `calendarItemIdentifier` via the hub's syncId↔identifier map (identifiers are hub-local state, not IPC columns) |
49| `title` | `title` |
50| `notes` | `notes` |
51| `done` | `completed` (+ `completionDate`) |
52| `dueAt` (epoch ms, nullable) | `dueDateComponents` (via `Calendar`; nil clears) |
53| `position` | not mapped — sort client-side (excluded from the merge hash, so reorder is never an edit) |
54| `createdAt` | read-only reference (part of the adoption content key; never written back) |
55| `deleted=true` envelope | remove the `EKReminder` |
56
57### Tombstone mapping
58
59`EKReminder` has no tombstone: a user-deleted reminder simply vanishes from
60the store. The hub therefore persists the set of known syncIds per vault;
61after a healthy fetch, any known syncId with no matching `EKReminder` is a
62genuine local delete and is folded into the next merge as a tombstone
63envelope. Merge-driven deletes always arrive as tombstone envelopes, never
64raw deletes. Same healthy-read discipline as `SyncSink.listLocalOk`: an
65unhealthy fetch aborts the cycle instead of reading absence as deletion.
66
67## Contacts sink
68
69`CNContactStore` + `requestAccess(for: .contacts)`. Maps `RemoteContact`
70name parts / organization / note / typed phones-emails-addresses / birthday
71onto `CNMutableContact`; syncId↔`CNContact.identifier` lives in the hub map
72(Swift never scribbles syncIds into user-visible contact fields). Delete and
73conflict semantics follow the XCFramework entity kind — Swift holds no
74opinion beyond faithfully applying `SyncDriver` output.
75
76## Calendar sink
77
78`EKEventStore` + calendar access. Maps `RemoteEvent` summary / description /
79location / start-end millis / allDay / timezone / RRULE / recurrenceId onto
80`EKEvent` in a hub-managed calendar. Same driver-applies, Swift-renders
81split as above.
82
83## Keychain / BGTaskScheduler
84
85KMP `SecureStore` actual = Keychain `kSecClassGenericPassword` (shared
86Keychain group with Passwords/Notes). `BGAppRefreshTaskRequest(identifier:
87"com.vayunmathur.everysync.hub.refresh")` for periodic cycles plus a
88`BGProcessingTaskRequest` for uploads after local system-store changes.
89Scheduling only — cycles run in the XCFramework.
90
91## Info.plist / entitlements notes
92
93- `NSRemindersUsageDescription` — todos sink ("EverySync syncs shared task lists into Reminders").
94- `NSCalendarsUsageDescription` — calendar sink.
95- `NSContactsUsageDescription` — contacts sink.
96- `com.apple.security.application-groups`: `group.<team>.everysync.shared` (envelope IPC store).
97- `keychain-access-groups`: `$(AppIdentifierPrefix)com.vayunmathur.everysync.hub`.
98- `UIBackgroundModes`: `fetch` + `processing` (BGTaskScheduler periodic work).
99
100## Swift must NOT
101
102Run merge/LWW, compute content hashes, encrypt envelopes, parse join links,
103check roles, or re-implement TOTP/block parsing. Driver output in, system
104stores out — nothing else.
105
106## Files (Phase 3)
107
108| File | Role |
109|---|---|
110| `HubSync.swift` | Hub entry: BGTask registration + per-vault cycle fan-out; no Todo UI |
111| `IPCRelayStore.swift` | `RelayStore` shim spec over the envelope IPC + baseline sidecar schema |
112| `TodoReminderSink.swift` | `RemoteTodo` -> `EKReminder` mapping + healthy-read tombstone detection |
113| `ContactSink.swift` | `RemoteContact` -> `CNContactStore` + shared type-int label tables |
114| `CalendarSink.swift` | `RemoteEvent` -> `EKEvent` + composite `uid␀recurrenceId` sync keys |
115| `SyncIdMap.swift` | Hub-local syncId<->system-identifier map + known-set (tombstone detection) |
116| `Info.plist.reference` | Reminders/Calendars/Contacts/FaceID strings, BGTask ids, `remote-notification` (pull trigger only), `everysync://join` scheme |
117| `Hub.entitlements.reference` | App Group + shared Keychain group + `aps-environment` |
118| `../Shared/EnvelopeIPC.swift` | SQLite IPC store (owned by the hub, read by shells) |
119| `../Shared/BlobStore.swift` | Blob sidecar (shared) |
120| `../Shared/KeychainSecureStore.swift` | Keychain layout contract (Kotlin implements) |
121| `../Shared/EverysyncCoreCrypto.swift` | CryptoKit AES-GCM C bridge |
122| `../Shared/BackgroundSync.swift` | BGTask registration helpers |