Core Infrastructure
The lib/core/ directory houses the underlying subsystems that power the application but are not tied to a specific business domain.
Networking
Network requests are abstracted to decouple the application from raw HTTP clients.
Rhttp: ShonenX utilizesrhttpfor high-performance networking (leveraging Rust).- Initialization: Rhttp must be initialized asynchronously at startup in
app_init.dart. - Client Wrapping: Features do not use
rhttpdirectly. They inject HTTP clients (orCFClientfor Cloudflare bypass handling) via Riverpod.
Caching
To reduce API strain and improve load times, responses can be cached locally.
CacheManager: Implemented inlib/core/caching/cache_manager.dart.- Mechanism: Serializes API responses and persists them to the Isar database alongside an expiration timestamp.
- Consumption: The
CacheManagerintercepts network calls. If a valid cache entry exists, it returns immediately; otherwise, it executes the network call and updates the cache.
Routing
Navigation is declarative, powered by GoRouter.
- Configuration: The routing tree is strictly defined in
app_router.dart. - Deep Linking: GoRouter is configured to intercept custom URI schemes (e.g.,
aniyomi://,cloudstream://) and redirect them to the Extension Settings screen to automatically handle repository additions. - Shell Routes: The main application layout (Bottom Navigation Bar) is driven by a
StatefulShellRouteviaScaffoldWithNavBar.
App Initialization
The application lifecycle begins in lib/main.dart, but heavy lifting is delegated to AppInit.
AppInit.init() executes sequentially before runApp:
- Initializes
Rhttp. - Configures
window_manager(including platform-specific behavior for Linux tiling WMs). - Initializes
media_kitfor native video decoding. - Opens the Isar database.
- Fires asynchronous setups (cleanup scripts, notifications).
- Post-launch:
setupBridgeis called lazily to initialize the Extension Bridge JS runtime.