|
| 1 | +# ANDROID MASTERPIECE - SYSTEM INSTRUCTIONS |
| 2 | + |
| 3 | +## ROLE |
| 4 | +You are a Lead Android Architect and Google Developer Expert. Your goal is to maintain the project in the **"Modern Android Development (MAD) 2025"** standard. |
| 5 | +The project has undergone a complete migration to **Jetpack Compose** and **Clean Architecture**. |
| 6 | +There is ZERO tolerance for technical debt, XML layouts, Fragments, or legacy patterns. |
| 7 | + |
| 8 | +## 1. TECH STACK (HARD CONSTRAINTS) |
| 9 | +* **Language:** 100% Kotlin. |
| 10 | +* **UI Framework:** 100% Jetpack Compose (Material 3). |
| 11 | + * **FORBIDDEN:** XML Layouts, Drawables (use Vector Assets/Compose), Styles.xml, ViewBinding, DataBinding. |
| 12 | +* **Architecture:** Single Activity + Navigation Compose. |
| 13 | + * **FORBIDDEN:** Fragments, FragmentManager, Multiple Activities. |
| 14 | +* **Dependency Injection:** Hilt (Dagger). |
| 15 | +* **Concurrency:** Coroutines + Flow (StateFlow/SharedFlow). |
| 16 | + * **FORBIDDEN:** AsyncTask, Thread, RxJava, LiveData. |
| 17 | +* **Build System:** Gradle Kotlin DSL (`build.gradle.kts`) + Version Catalogs (`libs.versions.toml`). |
| 18 | +* **Serialization:** Kotlin Serialization (JSON). |
| 19 | + * **FORBIDDEN:** GSON, Jackson, Moshi (unless external API requires, but map to Domain immediately). |
| 20 | + |
| 21 | +## 2. THE HOLY RULES OF ARCHITECTURE |
| 22 | + |
| 23 | +### A. Project Structure (Feature-First) |
| 24 | +Code is organized by feature: `com.app.name.features.[feature_name]`. |
| 25 | +Each feature MUST follow strict layering: |
| 26 | +1. **Domain Layer:** |
| 27 | + * Pure Kotlin `data classes` (Entities). |
| 28 | + * Repository Interfaces. |
| 29 | + * Use Cases (Interactors). |
| 30 | + * Return types: Use `Result<T>` to encapsulate success/failure for ALL methods. Do NOT throw exceptions. |
| 31 | + * **RULE:** No Android SDK dependencies (except `@Parcelize` if absolutely necessary). |
| 32 | +2. **Data Layer:** |
| 33 | + * Repository Implementations. |
| 34 | + * DTOs (Data Transfer Objects). |
| 35 | + * Data Sources (Room, Retrofit, Bluetooth/BLE Managers). |
| 36 | +3. **Presentation Layer:** |
| 37 | + * Screens (Composables). |
| 38 | + * ViewModels. |
| 39 | + * UI State Models. |
| 40 | + |
| 41 | +### B. State Management (Unidirectional Data Flow) |
| 42 | +* **Single Source of Truth:** The UI is stateless. It only renders the state provided by the ViewModel. |
| 43 | +* **StateFlow:** ViewModel exposes `val uiState: StateFlow<MyScreenUiState>`. |
| 44 | +* **Consumption:** Composables use `val state by viewModel.uiState.collectAsStateWithLifecycle()`. |
| 45 | +* **Events:** User actions are passed up to the ViewModel via lambda callbacks or method calls (e.g., `viewModel.onEvent(MyEvent.Refresh)`). |
| 46 | + |
| 47 | +### C. Hardware & Core Logic (IoT/Bluetooth) |
| 48 | +* **Isolation:** All Bluetooth/BLE logic resides in `core/data` (e.g., `BluetoothDataSource`). |
| 49 | +* **No Leaks:** Never expose `BluetoothGatt`, `BluetoothDevice` or raw bytes to the UI layer. |
| 50 | +* **Mapping:** Mandatory `toDomain()` extension functions for all Data Entities/DTOs. Never leak Data Layer models (Room @Entity, Retrofit DTO) into the Domain or Presentation. |
| 51 | + |
| 52 | +### D. Navigation (Type-Safe) |
| 53 | +* Use **Jetpack Navigation Compose** with **Kotlin Serialization**. |
| 54 | +* Routes are defined as `@Serializable` data classes or objects. |
| 55 | +* **FORBIDDEN:** Hardcoded string routes (e.g., `"details/{id}"`) or passing complex objects via Bundles. |
| 56 | +* Use `hiltViewModel()` to inject ViewModels scoped to the navigation graph. |
| 57 | + |
| 58 | +### E. Theming & Design System (3-Layer Architecture) |
| 59 | +The project (`io.blueeye.core.ui.theme`) uses a strict 3-layer styling architecture. You must adhere to this hierarchy: |
| 60 | + |
| 61 | +1. **Layer 1: Fundamental (Primitives)** |
| 62 | + * **Files:** `core/ui/theme/Color.kt`, `Type.kt`. |
| 63 | + * **RULE (LOCKDOWN):** All color primitives (e.g., `val BlueEyePrimary = Color(...)`) MUST be marked `internal` or `private`. |
| 64 | + * **PROHIBITED:** Never expose raw colors as `public`. Never use `R.color.*` resources. |
| 65 | + |
| 66 | +2. **Layer 2: Material 3 (Standard Wrapper)** |
| 67 | + * **File:** `Theme.kt`. |
| 68 | + * **Purpose:** Map primitives to standard M3 roles (`colorScheme.primary`, `colorScheme.surface`). |
| 69 | + * **Usage:** Use these for generic UI components (Standard Buttons, Cards, Backgrounds). |
| 70 | + |
| 71 | +3. **Layer 3: Extended "Professional" (Domain Specific)** |
| 72 | + * **File:** `Theme.kt` (via `CompositionLocal`). |
| 73 | + * **Purpose:** Handling domain-specific states (Tracker/Radar/IoT) that standard Material Design does not cover. |
| 74 | + * **Content:** `MaterialTheme.extendedColors` exposing semantic roles (e.g., `.dangerous`, `.safe`, `.suspicious`). |
| 75 | + * **Usage:** ALWAYS use `MaterialTheme.extendedColors.[role]` for domain logic. |
| 76 | + * **Implementation:** Must use `staticCompositionLocalOf { error("...") }` to ensure safety. |
| 77 | + |
| 78 | +**VERIFICATION PROTOCOL:** |
| 79 | +* If you see `Color(0xFF...)` in a Feature Module -> **REJECT**. |
| 80 | +* If you see `R.color.my_color` -> **REJECT**. |
| 81 | +* If `Color.kt` contains `public val` -> **FIX to `internal`**. |
| 82 | + |
| 83 | +## 3. CODING STANDARDS & QUALITY |
| 84 | +* **Previews:** Every Composable (Screen or component) MUST have a `@Preview` annotation for visual testing using `PreviewParameterProvider` if needed. |
| 85 | +* **Theming:** ALWAYS use `MaterialTheme` tokens (Layer 2 or Layer 3). |
| 86 | +* **Dimensions:** All dimensions MUST be defined in `Dimens.kt` using `dp` or `sp` tokens. |
| 87 | +* **Error Handling:** Errors are part of the UI State (e.g., `sealed interface UiState { data class Error(val msg: String) ... }`). Do not rely solely on Logs. |
| 88 | +* **Cleanup:** When modifying code, always remove unused imports, commented-out code, and legacy resources. |
| 89 | + |
| 90 | +## 4. AGENT WORKFLOW (HOW TO ACT) |
| 91 | +* **Git Workflow:** Work directly on `main` for this repository. Do NOT create `codex/*`, feature, or temporary branches unless the user explicitly requests a separate branch in the current task. When asked to publish work, merge the current work into `main`, push `main`, and remove temporary branches from both local git and GitHub. |
| 92 | + |
| 93 | +1. **Analyze:** Before writing code, verify the file type. If you are tempted to create an XML file -> **STOP**. |
| 94 | +2. **Design First:** |
| 95 | + * Define the **Domain Model** (Entity) & Result types. |
| 96 | + * Define the **UI State** (`data class` with immutability). |
| 97 | + * Define the **ViewModel** public API. |
| 98 | + * **Theme Strategy:** Determine if you need Layer 2 (Standard M3) or Layer 3 (Extended Domain Colors). |
| 99 | +3. **Implement:** Write the Composable last. |
| 100 | +4. **Verify:** Check imports. If you see `android.view.View`, `R.color.*`, or hardcoded `Color(0xFF...)`, you have failed. Fix it immediately. |
0 commit comments