How yal-pj/kan works
1. Repository shape
- This is a single-module Android app centered in app/, written in Kotlin and built with Gradle Kotlin DSL.
- There is no backend or multi-module architecture visible here; the main boundaries are UI, foreground tracking/service logic, and local persistence.
2. Primary runtime model
- KAN behaves like a long-running tracker rather than a one-shot screen.
- The app can be opened through MainActivity for the main hub, and LockTimerActivity for a dedicated timer view.
- Core tracking continues even when the activity is not visible by running inside a foreground service.
3. Tracking and lifecycle core
- service/ScreenTimeService.kt is the central runtime component that keeps tracking alive.
- service/BootCompletedReceiver.kt restarts tracking after device boot or app update when Android allows it.
- This means the app is designed around Android lifecycle events and OS-managed process death, not only around user navigation.
4. Foreground service and user-visible status
- The service is paired with service/TrackingNotifications.kt, which likely owns the persistent notification required for foreground execution.
- The notification is part of the app’s operational contract: it keeps tracking alive and makes background activity visible to the user.
- This is an important architecture boundary because Android foreground-service policy affects the entire app flow.
5. Overlay subsystem
- service/OverlayController.kt manages the optional floating “pill” overlay shown on top of other apps.
- The overlay is controlled separately from the main UI, and only appears when the user grants overlay permission.
- The overlay is a second presentation surface for the same tracking state, so the app has both an in-app and system-level UI path.
6. State and persistence
- data/ScreenTimeRepository.kt is the main persistence boundary for tracking state and history.
- data/KanSnapshot.kt appears to represent the current snapshot of app state consumed by UI and service layers.
- data/DailyHistoryEntry.kt models day-by-day historical records, indicating the app stores accumulated daily results rather than only live counters.
7. History serialization
- data/HistorySerializer.kt suggests history is stored locally in serialized form, likely for durable app restarts.
- This implies the app keeps its own state on device instead of relying on a remote database or cloud sync.
- The repository likely mediates between live tracking data and serialized history snapshots.
8. Domain/presentation models
- core/LockScreenVisualization.kt, core/LockTimerMode.kt, and core/OverlayStyle.kt define the app’s view/state vocabulary.
- domain/TimeFormatters.kt handles human-readable time formatting used across screens and notifications.
- These files separate display logic from state collection, helping the UI stay thin and consistent.
9. UI structure
- The UI is organized as Jetpack Compose screens under ui/screens/.
- screens/KanApp.kt is likely the top-level composition root.
- MainHubScreen.kt, HistorySettingsScreen.kt, OnboardingScreen.kt, and LockTimerScreen.kt are the main user-facing screens.
- ui/components/KanComponents.kt contains shared reusable UI elements, while ui/theme/KanTheme.kt defines the visual system.
10. App navigation and user flow
- Onboarding likely introduces notification, overlay, and foreground-service behavior before sensitive permissions are requested.
- The main hub shows today’s budget progress and current streak state.
- The history/settings screen exposes past absence sessions and budget adjustment.
- The lock timer screen provides a focused runtime view of the absence/timer state.
11. Data flow across layers
- The core flow is: tracking service collects state → repository persists snapshot/history → Compose screens render current state → overlay/notification mirror the same state.
- This means service and UI are not isolated silos; they share a common state model and persistence layer.
- The overlay is effectively an additional read-only presentation of the service state.
12. Android-specific dependencies and boundaries
- The manifest and permissions matter architecturally because the app depends on overlay display, notifications, boot handling, and wake locks.
- The app targets modern Android constraints, with API 26+ mentioned in the README and SDK 35 for compilation/targeting.
- These platform requirements strongly influence how background tracking is implemented and why the foreground-service pattern is used.
13. Build and delivery
- The repo includes a GitHub Actions workflow, build-debug-apk.yml, for hosted debug APK builds.
- Local development uses the checked-in Gradle wrapper, with Android Studio or command-line Gradle as the supported workflows.
- This build setup does not change runtime architecture, but it is the main delivery path for artifacts.
14. Architectural summary
- KAN is a local-first Android tracker built around a persistent foreground service, a repository-backed state model, and multiple UI surfaces for the same live data.
- The most important diagram boundaries are: Android lifecycle entry points, tracking/service layer, local data persistence, and Compose presentation plus optional overlay.
Main entry points: KanSnapshot.kt Snapshot · KanApp.kt Kan app · ScreenTimeService.kt Screen service · LockTimerScreen.kt Lock timer
Components 22
Android entry
Manifested app entry points and OS lifecycle hooks.
- Manifest · Declares activities, receivers, services, and permissions.
app/src/main/AndroidManifest.xml - Main activity · Primary app entry and host for the main Compose UI.
app/src/main/java/com/kan/app/ui/MainActivity.kt - Lock timer · Dedicated timer-focused screen entry point.
app/src/main/java/com/kan/app/ui/LockTimerActivity.kt
Tracking runtime
Foreground tracking, notifications, and overlay presentation.
- Boot receiver · Restarts tracking after boot or app update when allowed.
app/src/main/java/com/kan/app/service/BootCompletedReceiver.kt - Screen service · Central long-running tracker that keeps state alive.
app/src/main/java/com/kan/app/service/ScreenTimeService.kt - Notifications · Owns the persistent foreground notification surface.
app/src/main/java/com/kan/app/service/TrackingNotifications.kt - Overlay · Manages the optional floating pill shown over other apps.
app/src/main/java/com/kan/app/service/OverlayController.kt
State & storage
Local snapshot, history, and serialization boundaries.
- Repository · Main boundary for current snapshot and history persistence.
app/src/main/java/com/kan/app/data/ScreenTimeRepository.kt - Snapshot · Current state model shared between service and UI.
app/src/main/java/com/kan/app/data/KanSnapshot.kt - Daily history · Per-day persisted tracking records.
app/src/main/java/com/kan/app/data/DailyHistoryEntry.kt - History codec · Encodes and decodes durable local history storage.
app/src/main/java/com/kan/app/data/HistorySerializer.kt
Compose UI
Activities, screens, shared UI pieces, and theme.
- Kan app · Top-level Compose composition and navigation host.
app/src/main/java/com/kan/app/ui/screens/KanApp.kt - Main hub · Primary dashboard for progress and current state.
app/src/main/java/com/kan/app/ui/screens/MainHubScreen.kt - History settings · History, past sessions, and budget adjustment UI.
app/src/main/java/com/kan/app/ui/screens/HistorySettingsScreen.kt - Lock timer · Focused timer view for the active lock state.
app/src/main/java/com/kan/app/ui/screens/LockTimerScreen.kt - Onboarding · Introduces permissions and app behavior before tracking begins.
app/src/main/java/com/kan/app/ui/screens/OnboardingScreen.kt - Components · Reusable Compose UI primitives.
app/src/main/java/com/kan/app/ui/components/KanComponents.kt - Theme · Shared app styling and visual tokens.
app/src/main/java/com/kan/app/ui/theme/KanTheme.kt
Shared model
Presentation and formatting types used across layers.
- Lock mode · Defines the lock timer presentation state.
app/src/main/java/com/kan/app/core/LockTimerMode.kt - Lock visual · Controls how lock state is visualized.
app/src/main/java/com/kan/app/core/LockScreenVisualization.kt - Overlay style · Defines the appearance of the floating overlay.
app/src/main/java/com/kan/app/core/OverlayStyle.kt - Time formatters · Shared time and duration formatting utilities.
app/src/main/java/com/kan/app/domain/TimeFormatters.kt
Connections 30
- Manifest → Main activity: launches · Declares the main activity as an app entry point.
- Manifest → Lock timer: launches · Declares the dedicated lock timer activity.
- Manifest → Boot receiver: registers · Wires boot/update lifecycle restarts.
- Manifest → Screen service: declares · Registers the foreground tracking service.
- Main activity → Kan app: hosts · Creates the main Compose tree.
- Lock timer → Lock timer: hosts · Presents the lock timer focused view.
- Kan app → Main hub: navigates · Routes users to the dashboard.
- Kan app → History settings: navigates · Routes users to history and settings.
- Kan app → Onboarding: navigates · Shows first-run permission and setup flow.
- Main hub → Components: uses · Shares reusable UI primitives.
- History settings → Components: uses · Shares reusable UI primitives.
- Lock timer → Components: uses · Shares reusable UI primitives.
- Kan app → Theme: styles · Applies the shared design system.
- Main hub → Time formatters: formats · Renders durations and streak/time values.
- History settings → Time formatters: formats · Presents history values consistently.
- Lock timer → Lock mode: binds · Uses the lock timer state vocabulary.
- Lock timer → Lock visual: binds · Uses visualization state for the timer screen.
- Screen service → Notifications: publishes · Runs in the foreground through the persistent notification.
- Screen service → Overlay: updates · Feeds the optional overlay presentation.
- Screen service → Repository: persists · Writes live tracking state and history.
- Boot receiver → Screen service: restarts · Brings tracking back after eligible OS events.
- Overlay → Overlay style: applies · Maps state into overlay appearance.
- Repository → Snapshot: stores · Maintains the current app snapshot.
- Repository → Daily history: stores · Maintains daily history entries.
- Repository → History codec: serializes · Uses local serialization for durable storage.
- History codec → Daily history: encodes · Converts history entries to persistent form.
- Snapshot → Main hub: renders · Supplies the dashboard with current state.
- Snapshot → History settings: renders · Supplies history and settings views.
- Snapshot → Lock timer: renders · Supplies the focused lock timer view.
- Snapshot → Overlay: mirrors · Feeds the read-only overlay surface.