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

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

README.md5.8 KiBRenderedCodeRaw
1# EverySync Notes — Apple shell (Phase 3a)
2
3SwiftUI shell. **All merge / transport / crypto lives in the shared
4XCFramework** (`everysync-core` KMP); this target renders the editor, maps
5PencilKit strokes to the shared ink model, hosts the Share extension, and
6schedules background sync. Zero sync logic in Swift.
7
8## Architecture
9
10```
11NotesApp (SwiftUI, PencilKit canvas) ──► EverysyncCore.xcframework ──► relay
12 │ │
13 │ render + thin PencilKit mapping │ NoteBody parse/serialize,
14 │ │ merge, transport, cursors
15 ▼ ▼
16Keychain (SecureStore) App-Group envelope IPC
17BGTaskScheduler periodic (see ../IPC_CONTRACT.md)
18Share extension Blob store (image bytes by fileName)
19```
20
21## KMP entry points this shell will call (nothing else)
22
23| Kotlin FQN | Used for |
24|---|---|
25| `core.data.RemoteNote` | Envelope: `uid / title / content / blocksJson / position / deleted / updatedAt`. |
26| `core.notes.parseNoteBody` / `serializeNoteBody` / `noteBodyText` | Blocks JSON ⇄ editor model; plain-text projection for search/preview/share. `ignoreUnknownKeys` keeps legacy notes parsing. |
27| `core.notes.NoteBlock` (`Text`/`Image`/`Ink`), `InkStroke`, `InkPoint` | Canonical model. Swift never defines its own block schema. |
28| `core.sync.adapters.NoteKind` | `syncId=uid`, LWW on `updatedAt`, hash over canonical JSON (identity/position/timestamps stripped; reorder is not an edit), `imageNames(blocksJson)` for blob prefetch. |
29| `core.provider.SyncDriver` + `core.platform.RelayCursorStore` | Sync cycles; cursor keys `relay_cursor:<type>:<vault>:<channel>`. |
30| `core.network` | `IosRelayTransport`; record channel `notes:<vaultId>` via `recordChannel`; blob channel `notes-blobs:<vaultId>` for image bytes (never inline in envelopes). |
31| PQC / roles / links | Same surface as Passwords (see `../Passwords/README.md`); notes vaults may offer EDITOR or VIEWER. |
32
33## Wire shape (mirrored verbatim — do not extend in Swift)
34
35```json
36{"blocks":[
37 {"type":"text","id":"…","markdown":"…"},
38 {"type":"image","id":"…","fileName":"<sha256>.jpg","widthFraction":1.0},
39 {"type":"ink","id":"…","strokes":[],"heightDp":300}
40]}
41```
42
43`InkStroke`: `brushFamily` (default `"pressurePen"`), `brushSize`, `brushColor`
44(argb int), `brushEpsilon` (default `0.1`), `points: InkPoint[]`.
45`InkPoint`: `x, y, timeMillis, pressure, tiltRadians, orientationRadians`.
46
47## PencilKit → InkPoint mapping (thin platform layer, in Swift)
48
49PencilKit has no shared counterpart, so the stroke converter lives here, but
50it maps 1:1 onto `InkPoint`/`InkStroke` and performs no merge/hash/crypto:
51
52| `PKStrokePoint` | `InkPoint` |
53|---|---|
54| `location.x / .y` | `x / y` |
55| `timeOffset + stroke start` | `timeMillis` |
56| `force` (fallback `size`) | `pressure` |
57| `π/2 − altitude` | `tiltRadians` |
58| `azimuth` | `orientationRadians` |
59
60| `PKStroke` / `PKInk` | `InkStroke` |
61|---|---|
62| `ink.inkType` | `brushFamily` |
63| `ink` line width | `brushSize` |
64| `ink.color` → argb int | `brushColor` |
65| constant | `brushEpsilon = 0.1` |
66
67Serialization of the mapped strokes (`serializeNoteBody`) stays in the
68XCFramework. Canvas height maps to the ink block's `heightDp` (default 300).
69
70## Images
71
72Image bytes ride the blob channel keyed by `fileName`; envelopes carry only
73the name + `widthFraction`. Prefetch via `NoteKind.imageNames(blocksJson)`.
74
75## Delete semantics — SOFT delete
76
77Notes soft-delete: tombstone rows (`deleted=true`) persist locally and
78propagate. `NoteKind.localDeletesAreAuthoritative == true`.
79`SyncSink.delete` tombstones; never raw-deletes. See `../IPC_CONTRACT.md`.
80
81## Share extension
82
83Share-extension target receives text/URLs/images, converts to `NoteBlock`s via
84the XCFramework parsers, and writes through the App-Group envelope IPC. It
85never talks to the relay directly.
86
87## Keychain / BGTaskScheduler
88
89Same pattern as Passwords: KMP `SecureStore` actual = Keychain
90`kSecClassGenericPassword`; `BGAppRefreshTaskRequest(identifier:
91"com.vayunmathur.everysync.notes.refresh")` for periodic pulls, one-shot
92processing task after local edits. Scheduling only.
93
94## Info.plist / entitlements notes
95
96- `com.apple.security.application-groups`: `group.<team>.everysync.shared` (envelope IPC + blob store).
97- `keychain-access-groups`: `$(AppIdentifierPrefix)com.vayunmathur.everysync.notes`.
98- `NSExtension` (`com.apple.share-services`) on the Share-extension target, sharing the App Group.
99- No camera/photo-library keys in this shell (image blocks reference shared-store files; capture UI adds its own usage strings later).
100
101## Swift must NOT
102
103Parse/serialize blocks JSON by hand, compute content hashes, run merge/LWW,
104encrypt envelopes, or invent block types. All of that is `NoteBlocks.kt` +
105`NoteKind` in the XCFramework.
106
107## Files (Phase 3)
108
109| File | Role |
110|---|---|
111| `NotesApp.swift` | SwiftUI entry + note list contract; zero sync logic |
112| `NoteBodyView.swift` | Native Text/Image/Ink block rendering over the XCFramework `NoteBody` |
113| `PencilKitMapping.swift` | `PKStroke` <-> `InkStroke` unit conversion only (no merge/hash/crypto) |
114| `ShareExtension.swift` | `com.apple.share-services` target; XCFramework parsers -> envelope IPC |
115| `Info.plist.reference` | BGTask id, `everysync://join` scheme (no camera keys in this shell) |
116| `Notes.entitlements.reference` | App Group + shared Keychain group (shared with the extension) |
117| `../Shared/EnvelopeIPC.swift` | SQLite IPC store (shared with Passwords/Hub) |
118| `../Shared/BlobStore.swift` | Blob sidecar: image bytes by `fileName` (shared) |
119| `../Shared/KeychainSecureStore.swift` | Keychain layout contract (Kotlin implements) |
120| `../Shared/EverysyncCoreCrypto.swift` | CryptoKit AES-GCM C bridge (fills the Rust AES gap) |
121| `../Shared/BackgroundSync.swift` | BGTask registration helpers |