# oliexdev/openscale architecture

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

- Interactive diagram: https://gitdiagram.com/oliexdev/openscale
- Repository: https://github.com/oliexdev/openscale

## Overview

1. **Repository shape**
   This is primarily an Android/Kotlin application called **openScale**, with two supporting non-Android areas: `arduino_mcu` for custom scale firmware/hardware work, and `docs`/`fastlane` for product assets, store metadata, and release automation. The runtime architecture is centered on a local-only mobile app; there is no backend service in the repo.

2. **Top-level app boundary**
   The Android app lives under `android_app/` and uses a layered structure: UI, facades/use cases, services, database, and Bluetooth scale integrations. The codebase is intentionally split so the UI does not talk directly to Bluetooth or Room; it goes through facades and use cases.

3. **Entry points and app shell**
   `OpenScaleApp.kt` and `MainActivity.kt` are the app bootstrap points. `AndroidManifest.xml` plus the navigation layer define which screens exist and how users move through the app. The UI is organized around Compose-style screens in `ui/screen`, with shared state and events in `ui/shared`.

4. **User interface subsystem**
   The UI includes screens for overview, graphs, statistics, tables, settings, Bluetooth setup, and detail dialogs. Reusable components live in `ui/screen/components`, while modal interactions are grouped in `ui/screen/dialog`. The app also ships a resizable home-screen widget under `ui/widget`, which is part of the user-facing surface but updates from local app data.

5. **Domain model**
   Core business objects are in `core/data` and `core/model`. These represent users, measurements, measurement types, goals, enriched measurements, trends, insights, and evaluation contexts. This layer is the app’s semantic core: everything else transforms data into or out of these types.

6. **Local persistence**
   All durable state is stored locally through Room in `core/database`. There are DAOs for measurements, measurement values/types, users, and goals, backed by `AppDatabase`. Schema version snapshots under `app/schemas/` show that this is a long-lived offline database with explicit migrations and compatibility tracking.

7. **Bluetooth acquisition pipeline**
   Bluetooth scale support is the most specialized subsystem. `core/bluetooth` contains the communication layer and a `ScaleFactory`, while `core/bluetooth/scales` contains many device-specific handlers and adapters. The adapters abstract transport differences such as GATT, broadcast, and SPP, and the handlers implement vendor-specific parsing/protocol logic for many scale brands.

8. **Measurement processing**
   Raw scale data is not shown directly to the user. It is normalized and enriched by `core/service` classes such as `MeasurementEnricher`, `MeasurementEvaluator`, and `TrendCalculator`. This is where derived metrics, body-composition estimations, and range checks are computed before the UI renders charts, tables, or insight summaries.

9. **Application use-case layer**
   The `core/usecase` package is the main orchestration boundary between UI and the rest of the system. It groups feature-level operations such as CRUD, query/filtering, aggregation, smoothing, evaluation, import/export, backup/restore, reminders, sync hooks, and user goals. This layer keeps feature workflows separate from low-level storage and Bluetooth details.

10. **Facade layer**
   `core/facade` provides simplified entry points for major domains like Bluetooth, measurement management, settings, and user management. These facades are the likely boundary consumed by ViewModels and screens, reducing UI coupling to the deeper service/use-case graph.

11. **Background and lifecycle jobs**
   `core/worker` contains `BackupWorker`, `ReminderWorker`, and `BootReceiver`. These handle deferred or lifecycle-triggered tasks such as scheduled backups, notifications/reminders, and restoring periodic behavior after device reboot. This is the app’s background execution boundary outside the foreground UI.

12. **External and non-runtime surfaces**
   The app is designed for privacy: no cloud sync is built into the core repo, and the README explicitly notes that internet access is not required. Optional synchronization is delegated to a separate project. Release and distribution are managed through `fastlane`, while GitHub Actions under `.github/workflows` run CI for beta/master branches.

13. **Hardware companion area**
   `arduino_mcu/` contains an Arduino-based firmware project and libraries used for a custom scale device ecosystem. This is separate from the Android app but conceptually connected: it supports the “custom made Bluetooth scale” path documented in the README.

14. **What to show in an architecture diagram**
   A clear diagram should show: UI screens and widget at the top; facades/use cases in the middle; Room database and Bluetooth adapters/handlers as the two main data sources; service classes for enrichment/evaluation/trends between raw data and UI; and background workers/boot receiver as asynchronous system actors. The strongest architectural boundary is between device-specific Bluetooth parsing and the generic measurement domain stored locally in Room.

Main entry points: [`android_app/app/src/main/java/com/health/openscale/core/facade`](https://github.com/oliexdev/openscale/tree/master/android_app/app/src/main/java/com/health/openscale/core/facade) (Facades), [`android_app/app/src/main/java/com/health/openscale/ui/navigation/AppNavigation.kt`](https://github.com/oliexdev/openscale/blob/master/android_app/app/src/main/java/com/health/openscale/ui/navigation/AppNavigation.kt) (Navigation), [`android_app/app/src/main/java/com/health/openscale/core/usecase`](https://github.com/oliexdev/openscale/tree/master/android_app/app/src/main/java/com/health/openscale/core/usecase) (Use cases), [`android_app/app/src/main/java/com/health/openscale/ui/screen/overview/OverviewScreen.kt`](https://github.com/oliexdev/openscale/blob/master/android_app/app/src/main/java/com/health/openscale/ui/screen/overview/OverviewScreen.kt) (Overview)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_android_app["Android App"]
  node_entry_app["App shell<br/>bootstrap<br/>[OpenScaleApp.kt]"]
  node_entry_activity["Main activity<br/>entrypoint<br/>[MainActivity.kt]"]
  node_nav["Navigation<br/>routing<br/>[AppNavigation.kt]"]
  node_ui_shared["Shared state<br/>ui-state<br/>[SharedViewModel.kt]"]
  node_overview_ui["Overview<br/>screen<br/>[OverviewScreen.kt]"]
  node_analytics_ui["Charts & stats<br/>screen<br/>[GraphScreen.kt]"]
  node_settings_ui["Settings<br/>screen<br/>[SettingsScreen.kt]"]
  node_insights_ui["Insights<br/>screen<br/>[InsightsScreen.kt]"]
  node_widget_ui["Home widget"]
  node_facades["Facades<br/>application-facade"]
  node_usecases["Use cases<br/>orchestration"]
  node_domain_model["Domain model<br/>entities"]
  node_persistence[("Room store<br/>database<br/>[AppDatabase.kt]")]
  node_measurement_service["Processing<br/>service-layer"]
  node_bluetooth["Bluetooth core<br/>device-ingestion<br/>[ScaleFactory.kt]"]
  node_scale_handlers["Scale handlers<br/>protocol-parsers"]
  node_workers["Background jobs<br/>async-jobs"]
end

subgraph group_companion["Companion Hardware"]
  node_firmware["MCU firmware<br/>arduino-sketch<br/>[openScale_MCU.ino]"]
end

subgraph group_release["Release & Docs"]
  node_release_tools["Release tools<br/>distribution"]
end

node_entry_app -->|"launches"| node_entry_activity
node_entry_activity -->|"hosts"| node_nav
node_nav -->|"opens"| node_overview_ui
node_nav -->|"opens"| node_analytics_ui
node_nav -->|"opens"| node_settings_ui
node_nav -->|"opens"| node_insights_ui
node_overview_ui -->|"events"| node_ui_shared
node_analytics_ui -->|"events"| node_ui_shared
node_settings_ui -->|"events"| node_ui_shared
node_overview_ui -->|"reads/writes"| node_facades
node_analytics_ui -->|"reads/writes"| node_facades
node_settings_ui -->|"reads/writes"| node_facades
node_insights_ui -->|"reads/writes"| node_facades
node_facades -->|"delegates"| node_usecases
node_usecases -->|"stores"| node_persistence
node_usecases -->|"computes"| node_measurement_service
node_measurement_service -->|"produces"| node_domain_model
node_persistence -->|"persists"| node_domain_model
node_bluetooth -->|"dispatches"| node_scale_handlers
node_scale_handlers -->|"emits"| node_domain_model
node_bluetooth -->|"feeds"| node_measurement_service
node_usecases -->|"schedules"| node_workers
node_workers -->|"uses"| node_persistence
node_widget_ui -->|"reads"| node_facades
node_firmware -.->|"pairs with"| node_bluetooth
node_release_tools -.->|"packages"| node_entry_app

click node_entry_app "https://github.com/oliexdev/openscale/blob/master/android_app/app/src/main/java/com/health/openscale/OpenScaleApp.kt"
click node_entry_activity "https://github.com/oliexdev/openscale/blob/master/android_app/app/src/main/java/com/health/openscale/MainActivity.kt"
click node_nav "https://github.com/oliexdev/openscale/blob/master/android_app/app/src/main/java/com/health/openscale/ui/navigation/AppNavigation.kt"
click node_ui_shared "https://github.com/oliexdev/openscale/blob/master/android_app/app/src/main/java/com/health/openscale/ui/shared/SharedViewModel.kt"
click node_overview_ui "https://github.com/oliexdev/openscale/blob/master/android_app/app/src/main/java/com/health/openscale/ui/screen/overview/OverviewScreen.kt"
click node_analytics_ui "https://github.com/oliexdev/openscale/blob/master/android_app/app/src/main/java/com/health/openscale/ui/screen/graph/GraphScreen.kt"
click node_settings_ui "https://github.com/oliexdev/openscale/blob/master/android_app/app/src/main/java/com/health/openscale/ui/screen/settings/SettingsScreen.kt"
click node_insights_ui "https://github.com/oliexdev/openscale/blob/master/android_app/app/src/main/java/com/health/openscale/ui/screen/insights/InsightsScreen.kt"
click node_widget_ui "https://github.com/oliexdev/openscale/blob/master/android_app/app/src/main/java/com/health/openscale/ui/widget/MeasurementWidget.kt"
click node_facades "https://github.com/oliexdev/openscale/tree/master/android_app/app/src/main/java/com/health/openscale/core/facade"
click node_usecases "https://github.com/oliexdev/openscale/tree/master/android_app/app/src/main/java/com/health/openscale/core/usecase"
click node_domain_model "https://github.com/oliexdev/openscale/tree/master/android_app/app/src/main/java/com/health/openscale/core/model"
click node_persistence "https://github.com/oliexdev/openscale/blob/master/android_app/app/src/main/java/com/health/openscale/core/database/AppDatabase.kt"
click node_measurement_service "https://github.com/oliexdev/openscale/tree/master/android_app/app/src/main/java/com/health/openscale/core/service"
click node_bluetooth "https://github.com/oliexdev/openscale/blob/master/android_app/app/src/main/java/com/health/openscale/core/bluetooth/ScaleFactory.kt"
click node_scale_handlers "https://github.com/oliexdev/openscale/tree/master/android_app/app/src/main/java/com/health/openscale/core/bluetooth/scales"
click node_workers "https://github.com/oliexdev/openscale/tree/master/android_app/app/src/main/java/com/health/openscale/core/worker"
click node_firmware "https://github.com/oliexdev/openscale/blob/master/arduino_mcu/openScale_MCU/openScale_MCU.ino"
click node_release_tools "https://github.com/oliexdev/openscale/tree/master/fastlane/Fastfile"

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_entry_app,node_entry_activity,node_nav,node_ui_shared,node_overview_ui,node_analytics_ui,node_settings_ui,node_insights_ui,node_widget_ui,node_facades,node_usecases,node_domain_model,node_persistence,node_measurement_service,node_bluetooth,node_scale_handlers,node_workers toneBlue
class node_firmware toneAmber
class node_release_tools toneMint
```

## Components

### Android App

Local-only Kotlin/Compose application

- [App shell](https://github.com/oliexdev/openscale/blob/master/android_app/app/src/main/java/com/health/openscale/OpenScaleApp.kt): bootstrap · Application startup and process wiring · `android_app/app/src/main/java/com/health/openscale/OpenScaleApp.kt`
- [Main activity](https://github.com/oliexdev/openscale/blob/master/android_app/app/src/main/java/com/health/openscale/MainActivity.kt): entrypoint · Primary Android activity hosting the UI · `android_app/app/src/main/java/com/health/openscale/MainActivity.kt`
- [Navigation](https://github.com/oliexdev/openscale/blob/master/android_app/app/src/main/java/com/health/openscale/ui/navigation/AppNavigation.kt): routing · Screen graph and route definitions · `android_app/app/src/main/java/com/health/openscale/ui/navigation/AppNavigation.kt`
- [Shared state](https://github.com/oliexdev/openscale/blob/master/android_app/app/src/main/java/com/health/openscale/ui/shared/SharedViewModel.kt): ui-state · Cross-screen events and top bar/snackbar state · `android_app/app/src/main/java/com/health/openscale/ui/shared/SharedViewModel.kt`
- [Overview](https://github.com/oliexdev/openscale/blob/master/android_app/app/src/main/java/com/health/openscale/ui/screen/overview/OverviewScreen.kt): screen · Main measurement dashboard and detail entry · `android_app/app/src/main/java/com/health/openscale/ui/screen/overview/OverviewScreen.kt`
- [Charts & stats](https://github.com/oliexdev/openscale/blob/master/android_app/app/src/main/java/com/health/openscale/ui/screen/graph/GraphScreen.kt): screen · Graph, statistics, and table views · `android_app/app/src/main/java/com/health/openscale/ui/screen/graph/GraphScreen.kt`
- [Settings](https://github.com/oliexdev/openscale/blob/master/android_app/app/src/main/java/com/health/openscale/ui/screen/settings/SettingsScreen.kt): screen · Settings, Bluetooth, users, data, and measurement types · `android_app/app/src/main/java/com/health/openscale/ui/screen/settings/SettingsScreen.kt`
- [Insights](https://github.com/oliexdev/openscale/blob/master/android_app/app/src/main/java/com/health/openscale/ui/screen/insights/InsightsScreen.kt): screen · Derived measurement summaries and evaluations · `android_app/app/src/main/java/com/health/openscale/ui/screen/insights/InsightsScreen.kt`
- [Home widget](https://github.com/oliexdev/openscale/blob/master/android_app/app/src/main/java/com/health/openscale/ui/widget/MeasurementWidget.kt): widget · Resizable widget fed from local measurements · `android_app/app/src/main/java/com/health/openscale/ui/widget/MeasurementWidget.kt`
- [Facades](https://github.com/oliexdev/openscale/tree/master/android_app/app/src/main/java/com/health/openscale/core/facade): application-facade · Simplified entry points for UI and view models · `android_app/app/src/main/java/com/health/openscale/core/facade`
- [Use cases](https://github.com/oliexdev/openscale/tree/master/android_app/app/src/main/java/com/health/openscale/core/usecase): orchestration · Feature workflows for CRUD, query, backup, import/export, and reminders · `android_app/app/src/main/java/com/health/openscale/core/usecase`
- [Domain model](https://github.com/oliexdev/openscale/tree/master/android_app/app/src/main/java/com/health/openscale/core/model): entities · Measurements, users, goals, trends, and evaluation models · `android_app/app/src/main/java/com/health/openscale/core/model`
- [Room store](https://github.com/oliexdev/openscale/blob/master/android_app/app/src/main/java/com/health/openscale/core/database/AppDatabase.kt): database · Local database, DAOs, converters, and schema history · `android_app/app/src/main/java/com/health/openscale/core/database/AppDatabase.kt`
- [Processing](https://github.com/oliexdev/openscale/tree/master/android_app/app/src/main/java/com/health/openscale/core/service): service-layer · Enrichment, evaluation, trend calculation, BLE connector/scanner · `android_app/app/src/main/java/com/health/openscale/core/service`
- [Bluetooth core](https://github.com/oliexdev/openscale/blob/master/android_app/app/src/main/java/com/health/openscale/core/bluetooth/ScaleFactory.kt): device-ingestion · Scale factory and transport abstractions · `android_app/app/src/main/java/com/health/openscale/core/bluetooth/ScaleFactory.kt`
- [Scale handlers](https://github.com/oliexdev/openscale/tree/master/android_app/app/src/main/java/com/health/openscale/core/bluetooth/scales): protocol-parsers · Device-specific adapters and vendor protocol implementations · `android_app/app/src/main/java/com/health/openscale/core/bluetooth/scales`
- [Background jobs](https://github.com/oliexdev/openscale/tree/master/android_app/app/src/main/java/com/health/openscale/core/worker): async-jobs · Backup, reminder, and boot-time receivers · `android_app/app/src/main/java/com/health/openscale/core/worker`

### Companion Hardware

Arduino firmware and scale-related support files

- [MCU firmware](https://github.com/oliexdev/openscale/blob/master/arduino_mcu/openScale_MCU/openScale_MCU.ino): arduino-sketch · Arduino-based companion scale firmware · `arduino_mcu/openScale_MCU/openScale_MCU.ino`

### Release & Docs

Store metadata, assets, and release automation

- [Release tools](https://github.com/oliexdev/openscale/tree/master/fastlane/Fastfile): distribution · Fastlane metadata, changelogs, and store assets · `fastlane/Fastfile`

## Connections

- App shell → Main activity: launches · App bootstrap hands off to the main Android activity
- Main activity → Navigation: hosts · Activity renders the navigation graph
- Navigation → Overview: opens · Routes map to the main overview screen
- Navigation → Charts & stats: opens · Routes map to charts, statistics, and tables
- Navigation → Settings: opens · Routes map to settings and configuration screens
- Navigation → Insights: opens · Routes map to evaluation summaries
- Overview → Shared state: events · Screens exchange snackbar and top-bar state
- Charts & stats → Shared state: events · Analytics views reuse shared UI state
- Settings → Shared state: events · Settings views reuse shared UI state
- Overview → Facades: reads/writes · UI talks to the app through facades
- Charts & stats → Facades: reads/writes · Charts and tables consume facade APIs
- Settings → Facades: reads/writes · Configuration screens use facade APIs
- Insights → Facades: reads/writes · Insight views consume facade APIs
- Facades → Use cases: delegates · Facades route feature work to use cases
- Use cases → Room store: stores · CRUD, query, backup, and import/export persist locally
- Use cases → Processing: computes · Orchestration invokes enrichment and evaluation logic
- Processing → Domain model: produces · Processing turns raw readings into enriched domain objects
- Room store → Domain model: persists · Room stores measurement and user domain records
- Bluetooth core → Scale handlers: dispatches · Factory selects the correct scale implementation
- Scale handlers → Domain model: emits · Device protocols yield measurement-domain data
- Bluetooth core → Processing: feeds · Acquired readings flow into enrichment and evaluation
- Use cases → Background jobs: schedules · Backup and reminder workflows are executed in background
- Background jobs → Room store: uses · Workers operate on the local database
- Home widget → Facades: reads · Home screen widget pulls from app facades
- MCU firmware → Bluetooth core: pairs with · Companion scale firmware supports the custom scale path
- Release tools → App shell: packages · Release automation ships the Android app
