# FitBNR — Technical Overview, Audit & Handover Checklist

## 1. Technology Stack & Build Configuration

Verified directly from `app/build.gradle.kts`, `gradle/libs.versions.toml`, and `AndroidManifest.xml`:

| Layer | Technology / Configuration |
| :--- | :--- |
| **Application ID** | `com.fitriq.fitbnr` |
| **Current Version** | `versionName = "1.9.2"`, `versionCode = 17` |
| **Language & UI** | Kotlin (JVM 17), Jetpack Compose, Material 3, Material Icons Extended |
| **SDK Targets** | `compileSdk = 34`, `targetSdk = 34`, `minSdk = 26` (Android 8.0+) |
| **Architecture** | MVVM (`AndroidViewModel` + `StateFlow`), Repository Pattern, Jetpack Navigation Compose |
| **Backend & Auth** | Firebase Authentication (Email/Password), Cloud Firestore |
| **AI & ML APIs** | Google Gemini REST/SDK (`generativeai:0.9.0`), Groq OpenAI-compatible API (`llama-3.3-70b-versatile`, `llama-3.1-8b-instant`) |
| **Background Jobs & Sensors** | AndroidX `WorkManager`, `AlarmManager` (`SmartNotificationReceiver`), `SensorManager` (`TYPE_STEP_COUNTER`, `TYPE_STEP_DETECTOR`) |
| **Build & Signing** | Release & Debug configured with `fitbnr-release.jks` (V1–V4 signing); `isMinifyEnabled = false` |

---

## 2. Database & Cloud Firestore Architecture

Verified from `firestore.rules` and `data/repository/*.kt`:

- **`users/{userId}`**: User profile (`uid`, `email`, `firstName`, `lastName`, `age`, `dob`, `gender`, `heightCm`, `weightKg`, `preferredLanguage`, `createdAt`, `nutritionGoal`). Protected by `isOwner(userId)`.
  - **`nutritionGoal/current`**: Active Mifflin-St Jeor BMR, TDEE, calorie/macro targets, and daily water target.
  - **`weightHistory/{logId}`**: Historical weight entries for trend charting.
  - **`dailyLogs/{dateString}`**: Daily snapshots (meals, workout sessions, water ml, creatine boolean, steps, calories burned). Rules allow `read, create` by owner.
  - **`dailyState/current`**: Active daily nutrition state.
  - **`workoutRoutines/{routineId}`**: Custom user-created workout routines (synced with local `SharedPreferences`).
  - **`aiPrograms/{programId}`**: Generated multi-day workout splits.
- **`global_food_database/{foodId}`**: Shared community food macro cache keyed by SHA-256 hash of normalized food query; readable/writable by authenticated users.
- **`app_feedback/{feedbackId}`**: Tester bug reports and feature suggestions (`create` open, `read/update/delete` authenticated).

---

## 3. Permissions & Hardware Features (`AndroidManifest.xml`)

- `INTERNET`, `ACCESS_NETWORK_STATE`
- `POST_NOTIFICATIONS` (Android 13+ runtime permission handled via `NotificationPermissionHelper.kt`)
- `ACTIVITY_RECOGNITION` (Hardware step sensor permission)
- `WAKE_LOCK`, `RECEIVE_BOOT_COMPLETED` (Reminder scheduling persistence)
- `REQUEST_INSTALL_PACKAGES` *(Required only for direct APK OTA updates via `AppUpdateManager.kt`; **must be removed** before Google Play submission)*

---

## 4. Technical Readiness Assessment

### Strengths
1. **Clean 100% Jetpack Compose UI**: Zero legacy XML layouts, unified theme tokens (`FitNightPalette` / `FitDayPalette`), and native RTL layout support.
2. **Resilient Multi-Tier AI Pipeline**: Gemini Vision/Text → Groq Llama → Offline fallback ensures meal logging never completely breaks if one provider hits rate limits.
3. **Offline-Capable Session Persistence**: Active workout sessions and timers persist in `SharedPreferences` (`LiveSessionState.toJson()`), surviving tab switches and process restarts.
4. **Rich Local Asset Pack**: 56 `.webp` exercise illustrations bundled directly in `app/src/main/assets/exercises/` (zero external CDN dependency for exercise images).

### Current Technical Limitations & Gaps
1. **Client-Side API Keys**: `GEMINI_API_KEY` and `GROQ_API_KEY` are injected via `BuildConfig` from `local.properties`. For production scale on Google Play, these should be proxied through a backend (e.g., Firebase Cloud Functions or Next.js/Node API) to prevent key extraction from the APK.
2. **Code Obfuscation Disabled**: `isMinifyEnabled = false` in `build.gradle.kts` release build. Enabling R8/ProGuard shrinking and obfuscation is recommended before Play Store release.
3. **No Automated Test Suite**: `src/test` and `src/androidTest` currently contain no unit or Compose UI tests.
4. **Sideload OTA Conflict with Play Store**: `REQUEST_INSTALL_PACKAGES` and `AppUpdateManager.kt` violate Google Play policy if left enabled in a Play Store binary; they must be stripped or swapped for Google Play In-App Updates API.
5. **Firestore `dailyLogs` Rule vs. Repository Mismatch**: `firestore.rules` defines `allow read, create: if isOwner(userId);` on `users/{userId}/dailyLogs/{logId}` (intentionally blocking updates/deletes on archived logs). However, `DailyLogRepository.kt` performs same-day `set(..., SetOptions.merge())` writes (`addMeal`, `deleteMeal`, `updateWater`, `addWorkout`, `deleteWorkout`, `updateSteps`, `updateCreatine`). Once a day's document is created, subsequent same-day edits will be rejected by Firestore rules with `PERMISSION_DENIED` unless `update` (for owner only) is added or writes target a mutable `dailyState` document before archiving.

---

## 5. Google Play Readiness Assessment

> **Current Status**: **Advanced, feature-rich native Android fitness application with remaining technical, policy, licensing, and release-readiness tasks before Google Play submission.** FitBNR currently targets **API 34 (Android 14)**. For any new app submission on or after **August 31, 2026**, Google Play requires **Android 16 / API 36 or higher** (`targetSdk >= 36`).

| Requirement | Current Status | Action Needed Before Play Store Launch |
| :--- | :--- | :--- |
| **Target SDK (API 36+)** | **Upgrade Required** | Currently `targetSdk = 34`; must upgrade to **Android 16 / API 36+** for new submissions on/after August 31, 2026 |
| **AAB Format & Play App Signing** | **Needs Build** | Build `.aab` (`bundleRelease`) and enroll in Play App Signing |
| **Remove `REQUEST_INSTALL_PACKAGES`** | **Required Change** | Remove permission & sideload APK installer (`AppUpdateManager.kt`) |
| **Privacy Policy & Data Safety Form** | **Required** | Host public Privacy Policy URL; declare Firebase Auth, Firestore, AI meal text/images, and Activity Recognition |
| **Backend Proxy for AI Keys** | **Strongly Recommended** | Move Gemini/Groq API keys off the client APK |
| **R8 Minification** | **Recommended** | Enable `isMinifyEnabled = true` and test release rules |
| **Third-Party Asset Licensing** | **Verification Required** | Verify commercial usage rights for the 56 `.webp` exercise illustrations prior to Play Store launch |
| **Health Declaration** | **Required on Play Console** | Complete Google Play Health Apps declaration accurately |

---

## 6. Technical Handover Checklist

- [ ] Transfer the private Android repository (excluding local secrets) including `app/`, `gradle/`, and `assets/exercises/`
- [ ] Transfer or guide buyer through creating their own **Firebase Project** (`google-services.json`, `firestore.rules`)
- [ ] Provide `fitbnr-release.jks` keystore and credentials (or guide Play App Signing migration)
- [ ] Document `local.properties` keys (`GEMINI_API_KEY`, `GROQ_API_KEY`) and advise moving to server proxy
- [ ] Hand over branding assets (`ic_launcher.png`, `fitbnr-logo.png`, 56 `.webp` exercise illustrations)
- [ ] Conduct 1–2 live technical walkthrough sessions covering `HomeViewModel`, `WorkoutTabContent`, `AiNutritionManager`, and `MuscleRecoveryManager`
- [ ] Verify `firestore.rules` (`dailyLogs` update permissions) and strip `REQUEST_INSTALL_PACKAGES` for Play Store release
