# yal-pj/kan architecture

> Architecture diagram of the GitHub repository yal-pj/kan, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yal-pj/kan
- Repository: https://github.com/yal-pj/kan

## Overview

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: [`app/src/main/java/com/kan/app/data/KanSnapshot.kt`](https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/data/KanSnapshot.kt) (Snapshot), [`app/src/main/java/com/kan/app/ui/screens/KanApp.kt`](https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/ui/screens/KanApp.kt) (Kan app), [`app/src/main/java/com/kan/app/service/ScreenTimeService.kt`](https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/service/ScreenTimeService.kt) (Screen service), [`app/src/main/java/com/kan/app/ui/screens/LockTimerScreen.kt`](https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/ui/screens/LockTimerScreen.kt) (Lock timer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Android entry"]
  node_manifest["Manifest"]
  node_main_activity["Main activity<br/>[MainActivity.kt]"]
  node_lock_activity["Lock timer<br/>activity"]
end

subgraph group_service["Tracking runtime"]
  node_boot_receiver["Boot receiver"]
  node_screen_service["Screen service<br/>foreground service"]
  node_tracking_notifications["Notifications<br/>service support"]
  node_overlay_controller["Overlay"]
end

subgraph group_data["State & storage"]
  node_repository[("Repository")]
  node_snapshot["Snapshot<br/>app state<br/>[KanSnapshot.kt]"]
  node_daily_history["Daily history<br/>history model"]
  node_history_serializer["History codec<br/>serializer"]
end

subgraph group_ui["Compose UI"]
  node_kan_app["Kan app<br/>compose root<br/>[KanApp.kt]"]
  node_main_hub["Main hub<br/>screen<br/>[MainHubScreen.kt]"]
  node_history_screen["History settings<br/>screen"]
  node_lock_screen["Lock timer<br/>screen<br/>[LockTimerScreen.kt]"]
  node_onboarding["Onboarding<br/>screen"]
  node_components["Components<br/>shared ui<br/>[KanComponents.kt]"]
  node_theme["Theme<br/>design system<br/>[KanTheme.kt]"]
end

subgraph group_model["Shared model"]
  node_lock_mode(("Lock mode<br/>view mode<br/>[LockTimerMode.kt]"))
  node_lock_visual(("Lock visual<br/>visual state"))
  node_overlay_style(("Overlay style<br/>overlay state<br/>[OverlayStyle.kt]"))
  node_formatters(("Time formatters<br/>formatting<br/>[TimeFormatters.kt]"))
end

node_manifest -->|"launches"| node_main_activity
node_manifest -->|"launches"| node_lock_activity
node_manifest -->|"registers"| node_boot_receiver
node_manifest -->|"declares"| node_screen_service
node_main_activity -->|"hosts"| node_kan_app
node_lock_activity -->|"hosts"| node_lock_screen
node_kan_app -->|"navigates"| node_main_hub
node_kan_app -->|"navigates"| node_history_screen
node_kan_app -->|"navigates"| node_onboarding
node_main_hub -->|"uses"| node_components
node_history_screen -->|"uses"| node_components
node_lock_screen -->|"uses"| node_components
node_kan_app -->|"styles"| node_theme
node_main_hub -->|"formats"| node_formatters
node_history_screen -->|"formats"| node_formatters
node_lock_screen -->|"binds"| node_lock_mode
node_lock_screen -->|"binds"| node_lock_visual
node_screen_service -->|"publishes"| node_tracking_notifications
node_screen_service -->|"updates"| node_overlay_controller
node_screen_service -->|"persists"| node_repository
node_boot_receiver -->|"restarts"| node_screen_service
node_overlay_controller -->|"applies"| node_overlay_style
node_repository -->|"stores"| node_snapshot
node_repository -->|"stores"| node_daily_history
node_repository -->|"serializes"| node_history_serializer
node_history_serializer -->|"encodes"| node_daily_history
node_snapshot -->|"renders"| node_main_hub
node_snapshot -->|"renders"| node_history_screen
node_snapshot -->|"renders"| node_lock_screen
node_snapshot -->|"mirrors"| node_overlay_controller

click node_manifest "https://github.com/yal-pj/kan/blob/main/app/src/main/AndroidManifest.xml"
click node_main_activity "https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/ui/MainActivity.kt"
click node_lock_activity "https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/ui/LockTimerActivity.kt"
click node_boot_receiver "https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/service/BootCompletedReceiver.kt"
click node_screen_service "https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/service/ScreenTimeService.kt"
click node_tracking_notifications "https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/service/TrackingNotifications.kt"
click node_overlay_controller "https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/service/OverlayController.kt"
click node_repository "https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/data/ScreenTimeRepository.kt"
click node_snapshot "https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/data/KanSnapshot.kt"
click node_daily_history "https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/data/DailyHistoryEntry.kt"
click node_history_serializer "https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/data/HistorySerializer.kt"
click node_kan_app "https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/ui/screens/KanApp.kt"
click node_main_hub "https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/ui/screens/MainHubScreen.kt"
click node_history_screen "https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/ui/screens/HistorySettingsScreen.kt"
click node_lock_screen "https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/ui/screens/LockTimerScreen.kt"
click node_onboarding "https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/ui/screens/OnboardingScreen.kt"
click node_components "https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/ui/components/KanComponents.kt"
click node_theme "https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/ui/theme/KanTheme.kt"
click node_lock_mode "https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/core/LockTimerMode.kt"
click node_lock_visual "https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/core/LockScreenVisualization.kt"
click node_overlay_style "https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/core/OverlayStyle.kt"
click node_formatters "https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/domain/TimeFormatters.kt"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_manifest,node_main_activity,node_lock_activity toneBlue
class node_boot_receiver,node_screen_service,node_tracking_notifications,node_overlay_controller toneAmber
class node_repository,node_snapshot,node_daily_history,node_history_serializer toneMint
class node_kan_app,node_main_hub,node_history_screen,node_lock_screen,node_onboarding,node_components,node_theme toneRose
class node_lock_mode,node_lock_visual,node_overlay_style,node_formatters toneIndigo
```

## Components

### Android entry

Manifested app entry points and OS lifecycle hooks.

- [Manifest](https://github.com/yal-pj/kan/blob/main/app/src/main/AndroidManifest.xml): android manifest · Declares activities, receivers, services, and permissions. · `app/src/main/AndroidManifest.xml`
- [Main activity](https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/ui/MainActivity.kt): activity · Primary app entry and host for the main Compose UI. · `app/src/main/java/com/kan/app/ui/MainActivity.kt`
- [Lock timer](https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/ui/LockTimerActivity.kt): activity · 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](https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/service/BootCompletedReceiver.kt): receiver · Restarts tracking after boot or app update when allowed. · `app/src/main/java/com/kan/app/service/BootCompletedReceiver.kt`
- [Screen service](https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/service/ScreenTimeService.kt): foreground service · Central long-running tracker that keeps state alive. · `app/src/main/java/com/kan/app/service/ScreenTimeService.kt`
- [Notifications](https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/service/TrackingNotifications.kt): service support · Owns the persistent foreground notification surface. · `app/src/main/java/com/kan/app/service/TrackingNotifications.kt`
- [Overlay](https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/service/OverlayController.kt): system 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](https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/data/ScreenTimeRepository.kt): state repository · Main boundary for current snapshot and history persistence. · `app/src/main/java/com/kan/app/data/ScreenTimeRepository.kt`
- [Snapshot](https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/data/KanSnapshot.kt): app state · Current state model shared between service and UI. · `app/src/main/java/com/kan/app/data/KanSnapshot.kt`
- [Daily history](https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/data/DailyHistoryEntry.kt): history model · Per-day persisted tracking records. · `app/src/main/java/com/kan/app/data/DailyHistoryEntry.kt`
- [History codec](https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/data/HistorySerializer.kt): serializer · 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](https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/ui/screens/KanApp.kt): compose root · Top-level Compose composition and navigation host. · `app/src/main/java/com/kan/app/ui/screens/KanApp.kt`
- [Main hub](https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/ui/screens/MainHubScreen.kt): screen · Primary dashboard for progress and current state. · `app/src/main/java/com/kan/app/ui/screens/MainHubScreen.kt`
- [History settings](https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/ui/screens/HistorySettingsScreen.kt): screen · History, past sessions, and budget adjustment UI. · `app/src/main/java/com/kan/app/ui/screens/HistorySettingsScreen.kt`
- [Lock timer](https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/ui/screens/LockTimerScreen.kt): screen · Focused timer view for the active lock state. · `app/src/main/java/com/kan/app/ui/screens/LockTimerScreen.kt`
- [Onboarding](https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/ui/screens/OnboardingScreen.kt): screen · Introduces permissions and app behavior before tracking begins. · `app/src/main/java/com/kan/app/ui/screens/OnboardingScreen.kt`
- [Components](https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/ui/components/KanComponents.kt): shared ui · Reusable Compose UI primitives. · `app/src/main/java/com/kan/app/ui/components/KanComponents.kt`
- [Theme](https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/ui/theme/KanTheme.kt): design system · 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](https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/core/LockTimerMode.kt): view mode · Defines the lock timer presentation state. · `app/src/main/java/com/kan/app/core/LockTimerMode.kt`
- [Lock visual](https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/core/LockScreenVisualization.kt): visual state · Controls how lock state is visualized. · `app/src/main/java/com/kan/app/core/LockScreenVisualization.kt`
- [Overlay style](https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/core/OverlayStyle.kt): overlay state · Defines the appearance of the floating overlay. · `app/src/main/java/com/kan/app/core/OverlayStyle.kt`
- [Time formatters](https://github.com/yal-pj/kan/blob/main/app/src/main/java/com/kan/app/domain/TimeFormatters.kt): formatting · Shared time and duration formatting utilities. · `app/src/main/java/com/kan/app/domain/TimeFormatters.kt`

## Connections

- 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.
