How wendor/teapod-stream works
Purpose and Entry Points
TeapodStream is an Android-only Flutter VPN client built around Xray protocols and Android’s TUN/VpnService interface. Flutter starts in lib/main.dart, initializes application services in lib/app.dart, and presents the client UI. Android embedding and platform-channel registration begin at android/app/src/main/kotlin/com/teapodstream/teapodstream/MainActivity.kt.
Flutter Application and State
The UI is organized as screens backed by provider-style application state. Connection state, lifecycle actions, statistics, and native VPN events are centralized in lib/providers/vpn_provider.dart; persisted configuration, profiles, settings, geo data, and subscriptions have separate providers under lib/providers/. Primary user workflows originate in lib/ui/screens/home_screen.dart, lib/ui/screens/configs_screen.dart, and lib/ui/screens/settings_screen.dart.
Profiles, Configuration, and Persistence
Protocol-neutral connection, routing, DNS, tuning, and statistics models live under lib/core/models/, especially lib/core/models/vpn_config.dart, lib/core/models/routing_config.dart, and lib/core/models/profile.dart. Storage is an explicit boundary: ordinary and secure persistence are handled by lib/core/services/config_storage_service.dart, lib/core/services/profile_storage_service.dart, and lib/core/services/storage_secure_service.dart. Migration support allows persisted data evolution through lib/core/services/storage_migration_service.dart.
Xray Configuration and Engine Boundary
Dart parses VLESS links and converts selected profiles plus runtime settings into Xray-compatible configuration. Key stages are lib/protocols/xray/vless_parser.dart, lib/protocols/xray/xray_config_builder.dart, and lib/protocols/xray/xray_engine.dart. The abstract engine contract at lib/core/interfaces/vpn_engine.dart isolates Flutter state/UI from the Android-native implementation. Xray core is supplied externally through the downloaded teapod-core AAR rather than implemented in this repository.
Native VPN Lifecycle and Traffic Path
android/app/src/main/kotlin/com/teapodstream/teapodstream/XrayVpnService.kt owns Android VpnService lifecycle, establishes the TUN interface, and coordinates the native engine. In normal mode, device traffic crosses TUN, external teapod-tun2socks, a local SOCKS5 listener, then Xray. Proxy-only mode bypasses TUN and exposes only the local SOCKS endpoint. Native event delivery crosses back to Dart via android/app/src/main/kotlin/com/teapodstream/teapodstream/VpnEventStreamHandler.kt; commands arrive through android/app/src/main/kotlin/com/teapodstream/teapodstream/VpnCommandReceiver.kt.
Native Networking, Boot, and System Integration
android/app/src/main/kotlin/com/teapodstream/teapodstream/ConnectionParams.kt carries connection parameters into the native layer. android/app/src/main/kotlin/com/teapodstream/teapodstream/PrefixTcpProxy.kt implements the Shadowsocks prefix-proxy/DPI-bypass path, with native support in android/app/src/main/cpp/vpn_helper.cpp. Reconnect, autostart, and Quick Settings controls integrate with Android through android/app/src/main/kotlin/com/teapodstream/teapodstream/BootReceiver.kt, android/app/src/main/kotlin/com/teapodstream/teapodstream/VpnServiceUtils.kt, and android/app/src/main/kotlin/com/teapodstream/teapodstream/VpnTileService.kt.
External Data and Build Runtime
The runtime depends on Android, Flutter/Dart, Java 21, Xray core, and teapod-tun2socks. build.sh downloads the binary AAR plus geoip.dat/geosite.dat, which support geo-routing configured from Flutter. Subscription retrieval and update behavior are represented by lib/core/services/subscription_service.dart and lib/core/services/update_service.dart; deep links enter through lib/core/services/deeplink_handler.dart and lib/core/services/deeplink_router.dart.
Components 20
Flutter app
- Flutter entry
lib/main.dart - Application setup
lib/app.dart - Client screens · Home, configurations, and settings workflows.
lib/ui/screens/home_screen.dart - VPN state · Centralizes lifecycle, statistics, and native VPN events.
lib/providers/vpn_provider.dart
Configuration & data
- Connection models · Protocol-neutral VPN, routing, and profile models.
lib/core/models/vpn_config.dart - Persistent storage · Configuration, profile, secure storage, and migrations.
lib/core/services/config_storage_service.dart - Subscriptions & updates
lib/core/services/subscription_service.dart - Deep links
lib/core/services/deeplink_handler.dart - VLESS parser
lib/protocols/xray/vless_parser.dart - Xray config builder
lib/protocols/xray/xray_config_builder.dart - VPN engine contract · Isolates Flutter state from the native engine.
lib/core/interfaces/vpn_engine.dart
Android VPN runtime
- Android embedding · Registers platform channels.
android/app/src/main/kotlin/com/teapodstream/teapodstream/MainActivity.kt - VPN service · Owns VPN lifecycle, TUN establishment, and native engine coordination.
android/app/src/main/kotlin/com/teapodstream/teapodstream/XrayVpnService.kt - VPN commands
android/app/src/main/kotlin/com/teapodstream/teapodstream/VpnCommandReceiver.kt - Native VPN events
android/app/src/main/kotlin/com/teapodstream/teapodstream/VpnEventStreamHandler.kt - Boot & system controls · Autostart, reconnect, and Quick Settings controls.
android/app/src/main/kotlin/com/teapodstream/teapodstream/BootReceiver.kt - Prefix TCP proxy · Shadowsocks DPI-bypass path with C++ support.
android/app/src/main/kotlin/com/teapodstream/teapodstream/PrefixTcpProxy.kt
Other components
- teapod-tun2socks
- Xray core · Downloaded teapod-core runtime.
- Geo routing data · geoip.dat and geosite.dat downloaded at build time.
build.sh
Connections 22
- Flutter entry → Application setup: initializes
- Application setup → Client screens: presents
- Client screens → VPN state: uses
- VPN state → Persistent storage: loads and persists
- VPN state → Connection models: manages
- Deep links → VLESS parser: imports links
- Subscriptions & updates → VLESS parser: updates profiles
- VLESS parser → Connection models: creates profiles
- Connection models → Xray config builder: supplies selected config
- Geo routing data → Xray config builder: supports routing rules
- Xray config builder → VPN engine contract: produces engine config
- VPN state → VPN engine contract: controls
- Android embedding → VPN commands: receives channel commands
- VPN commands → VPN service: starts and stops
- VPN engine contract → VPN service: implemented by platform bridge
- VPN service → Native VPN events: emits status and statistics
- Native VPN events → VPN state: delivers to Dart
- Boot & system controls → VPN service: controls lifecycle
- VPN service → teapod-tun2socks: normal mode TUN traffic
- teapod-tun2socks → Xray core: forwards local SOCKS
- VPN service → Xray core: proxy-only local SOCKS
- VPN service → Prefix TCP proxy: uses bypass path