Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / vpn / AGENTS.md
| 1 | # AGENTS.md — vpn/ (':vpn') |
| 2 | |
| 3 | > Scoped supplement. Global rules in root `AGENTS.md` apply. Stay inside `vpn/` + allowed shared modules. Do not root-scan. |
| 4 | |
| 5 | _Install: ./install vpn (dev by default)._ |
| 6 | - Gradle: :vpn / dir: vpn/ |
| 7 | - Package roots present: ui, data, platform, service |
| 8 | - Entry files: MainActivity.kt, Route.kt, Navigation.kt |
| 9 | - Deps: :library:room, :library:network |
| 10 | - Metadata: metadata_data/vpn.md (present) |
| 11 | - Rust: yes / screenshotTest: yes |
| 12 | |
| 13 | ## Overview |
| 14 | **Purpose:** Offline-first WireGuard VPN client — user-imported configs, per-app bypass, connection logging. Tunnel crypto runs in a native Rust library. |
| 15 | **Key features:** |
| 16 | - WireGuard configs (manual import) with connect/disconnect via `service/VpnTunnelService` |
| 17 | - Per-app bypass list (`platform/BypassList` + `BypassListPage`); SNI parsing + packet inspection + DNS cache in `service/` |
| 18 | - Connection log persisted in Room; Material You UI |
| 19 | **Architecture / data-flow:** `ui/` config list/detail + logging → `platform/VpnViewModel` → `data/VpnRepository` over Room (`VpnConfig`, connection-log entities); tunnel control goes ViewModel → `service/VpnTunnelService` → Rust core via `util/VpnNative` JNI bridge; `service/ConnectionTracker` feeds the log. |
| 20 | **Entry points + reading order:** `Route` → `MainActivity.kt` → `Navigation.kt` → `ui/ConfigListPage.kt` → `platform/VpnViewModel.kt` → `service/VpnTunnelService.kt` → `util/VpnNative.kt`. |
| 21 | **Gotchas:** |
| 22 | - `util/` is NOT a closed package root — don't add more files there |
| 23 | - Tunnel state lives in the service + Rust core — UI reflects, never drives; reconnect races come from driving twice |
| 24 | - VPN permission + always-on/blocking modes are system-mediated; test grant/revoke, not just in-app toggles |
| 25 | - WireGuard import (`WgConfigParser`, also used for `.mavpn` servers) is single-peer: configs with multiple `[Peer]` sections are rejected rather than merged into one tunnel |
| 26 | - An `Endpoint` (or `.mavpn` manifest endpoint override) with a numeric port outside 1-65535 is rejected at import; already-stored configs with such a port fail cleanly at tunnel start (established TUN closed, service stopped) instead of throwing out of the tunnel coroutine |
| 27 | |
| 28 | ## Key files |
| 29 | ### Root — entry + navigation |
| 30 | - com/vayunmathur/vpn/MainActivity.kt |
| 31 | - com/vayunmathur/vpn/Navigation.kt |
| 32 | - com/vayunmathur/vpn/Route.kt |
| 33 | ### data/ — configs + connection log (Room) |
| 34 | - com/vayunmathur/vpn/data/VpnDatabase.kt |
| 35 | - com/vayunmathur/vpn/data/VpnRepository.kt |
| 36 | - com/vayunmathur/vpn/data/VpnConfig.kt |
| 37 | - com/vayunmathur/vpn/data/ConnectionLogDao.kt |
| 38 | - com/vayunmathur/vpn/data/ConnectionLogEntity.kt |
| 39 | ### platform/ — ViewModel + bypass |
| 40 | - com/vayunmathur/vpn/platform/VpnViewModel.kt |
| 41 | - com/vayunmathur/vpn/platform/BypassList.kt |
| 42 | ### service/ — tunnel, inspection, tracking |
| 43 | - com/vayunmathur/vpn/service/VpnTunnelService.kt |
| 44 | - com/vayunmathur/vpn/service/ConnectionTracker.kt |
| 45 | - com/vayunmathur/vpn/service/PacketInspector.kt |
| 46 | - com/vayunmathur/vpn/service/SniParser.kt |
| 47 | - com/vayunmathur/vpn/service/DnsCache.kt |
| 48 | - com/vayunmathur/vpn/service/AppResolver.kt |
| 49 | ### util/ — Rust bridge |
| 50 | - com/vayunmathur/vpn/util/VpnNative.kt — JNI bridge into the WireGuard core |
| 51 | ### ui/ + ui/components/ — configs, bypass, logging |
| 52 | - com/vayunmathur/vpn/ui/VpnTabs.kt |
| 53 | - com/vayunmathur/vpn/ui/ConfigListPage.kt |
| 54 | - com/vayunmathur/vpn/ui/ConfigListContent.kt |
| 55 | - com/vayunmathur/vpn/ui/ConfigDetailPage.kt |
| 56 | - com/vayunmathur/vpn/ui/BypassListPage.kt |
| 57 | - com/vayunmathur/vpn/ui/LoggingPage.kt |
| 58 | - com/vayunmathur/vpn/ui/LoggingContent.kt |
| 59 | - com/vayunmathur/vpn/ui/SettingsPage.kt |
| 60 | - com/vayunmathur/vpn/ui/GeoPickerPage.kt |
| 61 | - com/vayunmathur/vpn/ui/GeoCountryPage.kt |
| 62 | - com/vayunmathur/vpn/ui/GeoCityPage.kt |
| 63 | - com/vayunmathur/vpn/ui/dialogs/DeleteAllLogsDialog.kt |
| 64 | - com/vayunmathur/vpn/ui/components/BypassHelpers.kt |
| 65 | |
| 66 | ## Verify (this module only) |
| 67 | ``` |
| 68 | ./gradlew :vpn:compileDevKotlin |
| 69 | ./gradlew :vpn:lint |
| 70 | ./gradlew :vpn:checkMetadata |
| 71 | ``` |