How ronyaburaihan/netspeedindicator works
1. Repository shape
- This is a single-module Android app (app/) built in Kotlin with Jetpack Compose.
- The codebase is organized around Clean Architecture + MVVM, with a clear split between presentation, domain, data, and core/platform concerns.
2. Main runtime entry points
- NetSpeedApplication is the application-level bootstrap point and is where dependency injection is initialized.
- MainActivity hosts the Compose UI.
- SpeedMonitorService is the key background runtime component: it runs as a foreground service to continuously monitor network speed and usage.
- BootCompletedReceiver is the startup hook for restoring monitoring after device reboot.
3. Presentation layer
- The presentation/ package contains the Compose UI, navigation, shared components, and theme system.
- Screens are grouped by feature: home, history, settings, and onboarding.
- ViewModels (HomeViewModel, HistoryViewModel, SettingsViewModel) own UI state and call into domain use cases rather than accessing storage or Android APIs directly.
- AppNavigation, ScreenRoute, and shared components like AppTopBar and AppBottomNavigation define the app’s navigation shell.
4. Domain layer as the architectural boundary
- The domain/ package is the pure business layer.
- It defines the app’s stable models (SpeedInfo, UsageInfo), repository contracts, and use cases.
- Use cases such as GetCurrentSpeedUseCase, GetDailyUsageUseCase, GetMonthlyUsageUseCase, and SaveUsageUseCase encapsulate the app’s core rules and data access orchestration.
5. Data layer composition
- The data/ package implements the domain contracts and bridges Android/platform APIs to the rest of the app.
- SpeedRepositoryImpl and UsageRepositoryImpl are the concrete repository implementations.
- SpeedDataSource and UsageDataSource represent lower-level sources of network and usage data.
- TrafficStateManager appears to hold the live network/traffic state used by the monitoring flow.
6. Local persistence
- Persistent usage history is stored locally with Room.
- AppDatabase, UsageDao, and UsageEntity form the database subsystem, while UsageMapper converts between database entities and domain models.
- PreferenceManager stores app settings and user preferences, likely including theme, notification, and monitoring-related flags.
7. Monitoring and notification flow
- The core runtime loop is centered on SpeedMonitorService: it samples network activity, updates the user-visible speed indicator, and persists usage periodically.
- NotificationHelper is responsible for the foreground notification that keeps the service alive and shows live status.
- FormatUtils handles user-facing formatting of speed/usage values for both the notification and UI.
8. Permissions and Android system integration
- The app depends heavily on Android permissions and system services: network state, Wi‑Fi state, usage stats, notifications, boot completion, and battery-optimization exceptions.
- PermissionUtils and AutoStartPermissionUtils centralize permission-related logic and device-specific startup constraints.
- This is important architecturally because monitoring is not purely internal; it is gated by platform access rules.
9. Data flow through the layers
- UI events originate in Compose screens, flow to ViewModels, then to use cases, then to repository implementations.
- Repositories read from Android APIs, Room, and preferences, then return domain models back up the stack.
- The background service is a second entry path into the same data layer: it gathers live network state and writes usage data so the UI can later read it.
10. Boundaries to keep in mind for a diagram
- Presentation should be shown as depending only on domain, not directly on Room, preferences, or Android traffic APIs.
- Domain is framework-independent and contains no Android-specific code.
- Data and core are the platform-facing layers, where Android services, receivers, database, permissions, and notifications live.
11. External dependencies and infrastructure
- There is no backend or remote API in this repository; the product is fully on-device.
- The key external dependencies are Android platform APIs, Jetpack Compose, Room, DataStore/shared preferences, Hilt, coroutines/Flow, and the foreground-service/notification system.
12. Operational characteristics
- The app is designed for continuous background monitoring with minimal battery impact.
- Startup resilience comes from the foreground service plus boot-completion handling, while the local database preserves historical usage for the history screens.
- The test folders indicate both unit and instrumented test coverage, aligned with the clean separation between layers.
Main entry points: SpeedMonitorService.kt Speed Monitor · HomeScreen.kt Compose Screens · GetCurrentSpeedUseCase.kt Use Cases · NetSpeedApplication.kt App
Components 23
Entry & Core
Application bootstrap, background runtime, platform integration, and shared utilities.
- App · Application class that initializes dependency injection.
app/src/main/java/com/englesoft/netspeedindicator/NetSpeedApplication.kt - Speed Monitor · Continuously monitors speed and persists usage in the background.
app/src/main/java/com/englesoft/netspeedindicator/core/service/SpeedMonitorService.kt - Boot Receiver · Restores monitoring after device reboot.
app/src/main/java/com/englesoft/netspeedindicator/core/receiver/BootCompletedReceiver.kt - Permissions · Permission and auto-start checks for Android system constraints.
app/src/main/java/com/englesoft/netspeedindicator/core/util/PermissionUtils.kt - Notifications · Builds the foreground notification for the monitoring service.
app/src/main/java/com/englesoft/netspeedindicator/core/util/NotificationHelper.kt
Presentation
Compose UI, navigation shell, screens, and view models.
- Main Activity · Hosts the Compose app UI.
app/src/main/java/com/englesoft/netspeedindicator/presentation/app/MainActivity.kt - Navigation · App navigation graph and route definitions.
app/src/main/java/com/englesoft/netspeedindicator/presentation/navigation/AppNavigation.kt - App Shell · Shared top bar, bottom navigation, and modal UI pieces.
app/src/main/java/com/englesoft/netspeedindicator/presentation/component/AppTopBar.kt - Home VM · Owns home screen state and invokes domain use cases.
app/src/main/java/com/englesoft/netspeedindicator/presentation/screen/main/home/HomeViewModel.kt - History VM · Loads usage history for the history screen.
app/src/main/java/com/englesoft/netspeedindicator/presentation/screen/main/history/HistoryViewModel.kt - Settings VM · Coordinates settings state and preference-backed options.
app/src/main/java/com/englesoft/netspeedindicator/presentation/screen/main/settings/SettingsViewModel.kt - Compose Screens · Home, history, settings, and onboarding Compose screens.
app/src/main/java/com/englesoft/netspeedindicator/presentation/screen/main/home/HomeScreen.kt - Theme · Colors, typography, dimensions, and composition locals.
app/src/main/java/com/englesoft/netspeedindicator/presentation/theme/Theme.kt
Domain
Pure business rules, models, repository contracts, and use cases.
- Domain Models · Stable business models for speed and usage.
app/src/main/java/com/englesoft/netspeedindicator/domain/model/SpeedInfo.kt - Repo Contracts · Abstract repositories for speed and usage data.
app/src/main/java/com/englesoft/netspeedindicator/domain/repository/SpeedRepository.kt - Use Cases · Core orchestration for speed sampling and usage aggregation.
app/src/main/java/com/englesoft/netspeedindicator/domain/usecase/GetCurrentSpeedUseCase.kt
Data
Repository implementations plus Android, Room, and preference-backed sources.
- Speed Repo · Concrete speed repository implementation.
app/src/main/java/com/englesoft/netspeedindicator/data/repository/SpeedRepositoryImpl.kt - Usage Repo · Concrete usage repository implementation.
app/src/main/java/com/englesoft/netspeedindicator/data/repository/UsageRepositoryImpl.kt - Data Sources · Low-level speed and usage data collectors.
app/src/main/java/com/englesoft/netspeedindicator/data/datasource/SpeedDataSource.kt - Traffic State · Holds live network and traffic state for monitoring.
app/src/main/java/com/englesoft/netspeedindicator/data/manager/TrafficStateManager.kt - Local DB · Room database, DAO, and usage entity storage.
app/src/main/java/com/englesoft/netspeedindicator/data/local/AppDatabase.kt - Preferences · Stores app settings and monitoring-related flags.
app/src/main/java/com/englesoft/netspeedindicator/data/preferences/PreferenceManager.kt - Usage Mapper · Converts between Room entities and domain usage models.
app/src/main/java/com/englesoft/netspeedindicator/data/mapper/UsageMapper.kt
Connections 25
- App → Main Activity: starts UI · Application bootstrap leads into the Compose host.
- App → Speed Monitor: injects · Dependency injection provides service dependencies.
- App → Boot Receiver: registers · Application setup includes reboot handling.
- Main Activity → Navigation: hosts · Main activity renders the navigation shell.
- Navigation → App Shell: composes · Navigation is wrapped by shared app chrome.
- Navigation → Compose Screens: routes to · Routes resolve to feature screens.
- Compose Screens → Home VM: uses · Home screen observes home state.
- Compose Screens → History VM: uses · History screen observes usage history.
- Compose Screens → Settings VM: uses · Settings screen reads and updates preferences.
- Home VM → Use Cases: calls · View models invoke domain use cases.
- History VM → Use Cases: calls · History view model reads aggregated usage.
- Settings VM → Preferences: reads/writes · Settings view model coordinates preference state.
- Use Cases → Repo Contracts: depends on · Use cases are defined against repository interfaces.
- Speed Repo → Data Sources: reads from · Speed repository pulls live network data.
- Speed Repo → Traffic State: tracks · Repository coordinates with traffic state.
- Usage Repo → Local DB: persists to · Usage repository stores and queries history.
- Usage Repo → Preferences: reads settings · Repository uses preferences for runtime configuration.
- Usage Repo → Usage Mapper: maps · Transforms between entities and domain models.
- Speed Monitor → Data Sources: samples · Foreground service continuously gathers traffic data.
- Speed Monitor → Notifications: shows · Service remains foreground via notification.
- Speed Monitor → Use Cases: persists usage · Service writes periodic usage snapshots through domain logic.
- Boot Receiver → Speed Monitor: restarts · Boot receiver restores monitoring after reboot.
- Permissions → Speed Monitor: gates · Permissions and startup constraints affect monitoring.
- Permissions → Compose Screens: gates · UI surfaces permission and setup flows.
- Theme → Compose Screens: styles · Theme system is consumed by Compose screens.