SPB Git

Repository Public

ARCHITECTURE.md 5.1 KB 74 lines markdown

1# Architecture23SP Vault is one iOS app target with no dependency outside Apple's SDK: Swift 6 (strict concurrency), SwiftUI, a little UIKit, AVFoundation, Vision, VisionKit, Core Image, Metal (SwiftUI shaders), Core Motion, Core Haptics, CryptoKit, Security, LocalAuthentication, UserNotifications. Minimum iOS 26, iPhone, portrait. The project file is generated from `project.yml` with XcodeGen and committed.45## Layers67```8App/            SPVaultApp, AppEnvironment (object graph), RootView (state → screen), AppRouter, AppSettings9Core/10  Cryptography/ SealedBlob (SPV1), VaultCrypto, KDFParameters, PassphrasePolicy11  Biometrics/   KeyProtector protocol + Keychain / simulator / scripted implementations12  Storage/      Models, VaultRepository (encrypted files), CardMigrator, SearchIndex13  Security/     Vault (the security engine), SensitiveDataPolicy14  Privacy/      PrivacyShield (curtain window, capture and screenshot detection)15Engines/16  SmartScan/    detection, quality gates, perspective correction, OCR, parser, security-code redaction17  ImageProcessing/ CardImageCodec (re-encode, thumbnails, dominant colour) and scan image pipeline18  VirtualCard/  VirtualCardView, FlippableCardView, RawCardFace, DemoCardFactory (Debug / simulator)19  Backup/       BackupArchive (.spvault)20DesignSystem/   tokens, components, Metal shaders, haptics, motion21Features/       Onboarding, Lock, Shell, Wallet, Scanner, Cards, Search, Expirations, SecurityCenter, Settings22```2324Dependencies point downwards: features use engines and core; core knows nothing about SwiftUI views (except `Vault`, which decodes images with UIKit).2526## The security engine2728`Vault` (`@MainActor @Observable`) is the single owner of secrets and the only path to card data.2930```31            bootstrap()                unlock() ── Face ID ── Keychain ── key32 loading ───────────────► noVault ──createVault()──┐33    │                                              ▼34    └────────► locked ◄──────── lock() ──────── unlocked35                  │                                 ▲36                  └── key gone ──► keyInvalidated ──┘ recover(passphrase)37```3839- `unlock()` reads the master key through a `KeyProtector`; the manifest must authenticate with it before the state changes.40- While unlocked, `Vault` holds the key, the decrypted `Card` records, the `SearchIndex` and an image cache. `lock()` drops them all.41- Mutations (`add`, `update`, `delete`, `setImage`, `move`, categories, backup, restore) go through `VaultRepository`, a stateless `Sendable` value that takes the key as an argument and writes only sealed blobs. Heavy work (image codec, PBKDF2, full loads) runs in detached tasks.42- `reauthenticate()` reads the Keychain item again and compares keys; it gates number reveal, export, recovery changes and erasure.4344`RootView` switches on `vault.state`. The unlocked shell (`MainShellView`, its `AppRouter`, every sheet and cover) exists only in the `.unlocked` branch, so locking removes it from the hierarchy; there is no route that could show content afterwards, and there would be nothing decrypted to show.4546## Lock and privacy4748- Scene phase `.background` → `vault.lock()`.49- `UIApplication.willResignActive` → `PrivacyShield` raises an opaque window at `.alert + 1`, above sheets and covers, before the system takes the switcher snapshot.50- `isSceneCaptured` (recording or mirroring) keeps the curtain up.51- `userDidTakeScreenshotNotification` → in-app banner and a generic local notification.5253## Scanning pipeline (SmartScan)5455Camera frame → rectangle detection → quality gates (sharpness, glare, light, stability) → high-resolution still → perspective correction and crop → optional restrained enhancement → on-device OCR → `CardTextParser` proposals → for bank-card backs, security-code detection and irreversible redaction with manual validation → `ScanDraft` (bitmaps in memory) → `CardEditorView` → `CardImageCodec` → `Vault.add`. Nothing in this chain touches the disk or Photos before encryption.5657## Data flow of one card5859```60ScanDraft (CGImage ×2, proposals)61   └─ editor → Card record62        └─ CardImageCodec: HEIC/JPEG re-encode (metadata dropped), thumbnail63             └─ VaultRepository.insert: new card key, 6 sealed blobs in a staging directory, atomic rename64                  └─ manifest (order) and search index re-sealed65```6667## Testing hooks6869Debug builds accept launch arguments (`-uiTesting`, `-seedDemo`, `-screen`, `-biometry`, `-layout`, `-privacyMode`, `-keepVault`) that select a temporary vault, the scripted key protector and fictitious demo cards. They are parsed inside `#if DEBUG`; the Release binary contains neither the parser nor the test protectors nor the demo cards.7071## Build7273`scripts/build.sh debug | release | unit | uitest | test`, `scripts/shot.sh <name> [launch args]` (simulator screenshot of a screen), `scripts/make_icon.py`, `scripts/apple_dev_setup.applescript` + `scripts/portal/*.js` (App ID registration through the signed-in Safari session).74
Files main
Menu

Theme