Here is the introduction.mdx file, tailored to the specific architecture and codebase provided.
Copy
---title: "System Architecture"sidebarTitle: "Introduction"description: "High-level overview of the ScrollLess technology stack, architectural patterns, and data flow."icon: "sitemap"mode: "wide"---## Welcome to the TeamWelcome to the **ScrollLess** engineering team. You are looking at the "Spinal Cord" of our application. Unlike a standard CRUD app, ScrollLess operates as a system-level monitor, requiring a robust architecture to handle real-time event ingestion (scrolling, notifications) while maintaining a smooth UI.## System MetaphorThink of ScrollLess as a **Digital Wellbeing Interceptor**.It sits quietly between the Android Operating System and the User. It listens for specific signals (an app opening, a scroll gesture, a notification), processes them against a local set of rules (Limits), and intervenes only when necessary (blocking the screen or sending a nudge).## Technology StackWe use a modern, opinionated Android stack centered around Google's latest recommendations.| Layer | Technology | Purpose || :--- | :--- | :--- || **UI** | <Tooltip tip="Google's modern toolkit for building native UI using Kotlin code">Jetpack Compose</Tooltip> | We use Material3 and Compose for 99% of our UI. || **DI** | <Tooltip tip="Dependency Injection library built on top of Dagger">Hilt</Tooltip> | Connects our Database, Network, and Services to the UI. || **Async** | <Tooltip tip="Kotlin's solution for asynchronous programming">Coroutines</Tooltip> & Flow | Handling background threads and reactive data streams. || **Local Data** | <Tooltip tip="Abstraction layer over SQLite database">Room</Tooltip> | The "Single Source of Truth" for all app data. || **Remote** | <Tooltip tip="Type-safe HTTP client for Android">Retrofit</Tooltip> | Syncing app categories and metadata. || **Background** | <Tooltip tip="Library for persistent background processing">WorkManager</Tooltip> | Daily data summarization and limit enforcement. || **Ingestion** | Accessibility & Notification Services | Listening to system events in real-time. |## High-Level ArchitectureWe follow the **MVVM (Model-View-ViewModel)** pattern with a strict **Repository** layer. Data flows unidirectionally: from the Database to the UI.```mermaidgraph TD subgraph "UI Layer" UI[Jetpack Compose UI] VM[ViewModel] end subgraph "Data Layer" Repo[Repository] Room[<Tooltip tip='Local Database'>Room DB</Tooltip>] Remote[Retrofit API] end subgraph "Ingestion Layer (Services)" Acc[Accessibility Service] Notif[Notification Listener] Usage[Usage Stats Worker] end %% Flows UI <-->|"StateFlow / Events"| VM VM <-->|"Suspend Functions"| Repo Repo <-->|"Read/Write"| Room Repo <-->|"Fetch"| Remote Acc -->|"Write Raw Events"| Room Notif -->|"Write Notifications"| Room Usage -->|"Write Usage Stats"| Room style Room fill:#f9f,stroke:#333,stroke-width:2px style Acc fill:#bbf,stroke:#333,stroke-width:1px style Notif fill:#bbf,stroke:#333,stroke-width:1px
Source of Truth: The local database (AppDatabase.kt) is the absolute truth.
Syncing: We use (CategorySyncWorker) to fetch app categories from the cloud, but the UI always reads from the local database, never the network directly.