Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / backup / AGENTS.md
| 1 | # AGENTS.md — backup/ (':backup') |
| 2 | |
| 3 | > Scoped supplement. Global rules in root `AGENTS.md` apply. Stay inside `backup/` + allowed shared modules. Do not root-scan. |
| 4 | |
| 5 | _Install: ./install backup (dev by default)._ |
| 6 | <!-- last-reviewed: 2026-10-16 --> |
| 7 | - Gradle: :backup / dir: backup/ |
| 8 | - Package roots present: ui, data, domain, platform, service |
| 9 | - Entry files: MainActivity.kt, Route.kt, Navigation.kt |
| 10 | - Deps: :library:aosp-stubs, :library:network, :library:work, :library:biometric, :library:e2ee-p2p |
| 11 | - Metadata: metadata_data/backup.md (present) |
| 12 | - Rust: no / screenshotTest: yes |
| 13 | |
| 14 | ## Overview |
| 15 | **Purpose:** Privileged encrypted backup app for data, apps, and media. THE reference module — satisfies every repo rule; copy its layout for new apps. |
| 16 | **Key features:** |
| 17 | - AES-256-GCM E2EE keyed by a 12-word BIP-39 recovery code; restore from the code alone, no account |
| 18 | - SAF folder backend (internal/USB/SD) + WebDAV/Nextcloud remote backend behind one `BackupBackend` interface |
| 19 | - Scheduled encrypted photo/video/audio backup; system app-data transport on platform-signed installs |
| 20 | **Architecture / data-flow:** `ui/` onboarding→dashboard → `platform/BackupViewModel` → `data/backend/` (`BackendFactory` picks `SafBackend`/`WebDavBackend`, `BackupRepository` orchestrates) with `domain/crypto/` pure (Bip39/Crypto) and keys in `platform/crypto/KeyManager`; `platform/FileBackupWorker` runs schedules, `service/ConfigurableBackupTransport` exposes the system transport. `Navigation`: start gated on `onboarded` flag; `reset()` not `add()` (no back-navigation to onboarding); SAF folder picker + persistable URI perms owned at `Navigation` level since both screens use it. |
| 21 | **Entry points + reading order:** `Route` (`Onboarding` / `Dashboard`) → `MainActivity.kt` → `Navigation.kt` → `platform/BackupViewModel.kt` → `data/backend/BackendFactory.kt` + `BackupBackend.kt`. |
| 22 | **Gotchas:** |
| 23 | - Onboarding ends when the ViewModel has key + destination, not via navigation — the stack follows the flag |
| 24 | - Media-permission grant funnels straight into `backupFilesNow()` |
| 25 | - Internet is used only for WebDAV remotes; everything else is offline |
| 26 | |
| 27 | ## Why this is the reference (copy this, not others) |
| 28 | **Copy-this checklist:** |
| 29 | - `data/backend/BackupBackend` interface + `BackendFactory` + one impl per destination (SAF / WebDAV) — new destinations add a file, not a refactor |
| 30 | - Pure `domain/crypto/` (Bip39, Crypto) with zero Android imports; platform key custody isolated in `platform/crypto/KeyManager` |
| 31 | - `platform/` worker + ViewModel split: `FileBackupWorker` schedules/runs, `BackupViewModel` holds UI state — never mixed |
| 32 | - Onboarding-gated `Navigation` with the why-comments intact (`reset()` vs `add()`, picker ownership at `Navigation` level) |
| 33 | - Closed package roots (`ui data domain platform service`), one public `@Composable` per file |
| 34 | **Anti-patterns avoided here (seen elsewhere):** |
| 35 | - No `util/` dumping ground — helpers live in the package they serve |
| 36 | - No backend `when`-branches scattered through UI — all behind the interface |
| 37 | - No navigation back to onboarding; no picker duplicated per screen |
| 38 | |
| 39 | ## Key files |
| 40 | ### Root — entry + navigation |
| 41 | - com/vayunmathur/backup/MainActivity.kt |
| 42 | - com/vayunmathur/backup/Navigation.kt — onboarding gate + picker ownership (read the comments) |
| 43 | - com/vayunmathur/backup/Route.kt |
| 44 | ### data/ — backends, repo, file backup |
| 45 | - com/vayunmathur/backup/data/BackupConfig.kt |
| 46 | - com/vayunmathur/backup/data/backend/BackupBackend.kt — the interface to copy |
| 47 | - com/vayunmathur/backup/data/backend/BackendFactory.kt |
| 48 | - com/vayunmathur/backup/data/backend/BackupRepository.kt |
| 49 | - com/vayunmathur/backup/data/backend/SafBackend.kt |
| 50 | - com/vayunmathur/backup/data/backend/WebDavBackend.kt |
| 51 | - com/vayunmathur/backup/data/files/FileBackupManager.kt |
| 52 | - com/vayunmathur/backup/data/files/FileMetadata.kt |
| 53 | ### domain/ — pure crypto (no Android) |
| 54 | - com/vayunmathur/backup/domain/crypto/Bip39.kt |
| 55 | - com/vayunmathur/backup/domain/crypto/Crypto.kt |
| 56 | ### platform/ — ViewModel, worker, key custody |
| 57 | - com/vayunmathur/backup/platform/BackupViewModel.kt |
| 58 | - com/vayunmathur/backup/platform/FileBackupWorker.kt |
| 59 | - com/vayunmathur/backup/platform/crypto/KeyManager.kt |
| 60 | ### service/ — system backup transport |
| 61 | - com/vayunmathur/backup/service/ConfigurableBackupTransport.kt |
| 62 | - com/vayunmathur/backup/service/ConfigurableBackupTransportService.kt |
| 63 | ### ui/ — onboarding + dashboard |
| 64 | - com/vayunmathur/backup/ui/OnboardingScreen.kt |
| 65 | - com/vayunmathur/backup/ui/DashboardScreen.kt |
| 66 | - com/vayunmathur/backup/ui/components/BackendSection.kt |
| 67 | |
| 68 | ## Verify (this module only) |
| 69 | ``` |
| 70 | ./gradlew :backup:compileDevKotlin |
| 71 | ./gradlew :backup:lint |
| 72 | ./gradlew :backup:checkMetadata |
| 73 | ``` |