# somespi/baseerah architecture

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

- Interactive diagram: https://gitdiagram.com/somespi/baseerah
- Repository: https://github.com/somespi/baseerah

## Overview

1. **High-level shape**
   - This is a **Flutter cross-platform client app** (`lib/main.dart`) built once and deployed to Android, iOS, web, macOS, Windows, and Linux.
   - The repo is mostly a **single front-end app with local device capabilities**, not a backend-heavy system. The important boundaries are the Flutter UI, the service layer under `lib/services`, and the native platform shells under `android/ios/macos/windows/linux`.

2. **App entry and navigation**
   - `lib/main.dart` is the app bootstrap.
   - The visible routes appear to be:
     - `lib/pages/login_route.dart`
     - `lib/pages/maps_route.dart`
     - `lib/pages/ocr_route.dart`
   - This suggests a route-based UI with separate feature screens rather than a large single-screen workflow.

3. **Core service layer**
   - Most non-UI logic is isolated in `lib/services`.
   - This folder is the architectural center: UI pages likely call these services, and services encapsulate hardware access, ML inference, speech, maps, and external integrations.
   - Key separation: **pages handle presentation**, while **services handle device APIs and domain behavior**.

4. **Assistive / multimodal feature set**
   - The presence of `ar_service.dart`, `ocr.dart`, `speech_to_text.dart`, `text_to_speech.dart`, and `help_utilities.dart` indicates the app is designed around **assistive interactions**:
     - vision/OCR input
     - spoken input/output
     - possibly real-world guidance or object recognition
   - `old/ar_route.dart` looks like a previous or deprecated AR-related screen, suggesting AR was experimented with or migrated into a service-based design.

5. **OCR subsystem**
   - OCR is split into its own subfolder: `lib/services/ocr/ocr.dart`.
   - Supporting assets include:
     - `assets/tessdata/ara.traineddata`
     - `assets/tessdata/eng.traineddata`
     - `assets/ocr/ocr_phrases.txt`
     - `assets/tessdata_config.json`
   - This indicates offline/on-device OCR with multilingual support, likely using Tesseract-style trained data packaged directly in the app.

6. **Machine learning / inference assets**
   - `assets/models` contains multiple model files:
     - `yolo11n.onnx`
     - `yolo11n_int8.onnx`
     - `yolo11n_int8.tflite`
     - `yolo_model.onnx`
     - `mixer128.onnx`
     - `vocos22.onnx`
     - `labels.txt`
   - This points to **local inference** for at least object detection/classification, and possibly audio generation or processing.
   - The architecture likely keeps these models on-device rather than calling a remote ML service.

7. **Speech and conversation flow**
   - `speech_to_text.dart` and `text_to_speech.dart` imply a voice loop:
     - user speech is captured and transcribed
     - the app processes the text locally or through helper logic
     - results are spoken back via TTS
   - `tfidf.dart` and `document.dart` suggest text matching / retrieval or simple intent ranking, likely used to interpret user phrases or commands without a server-side NLP stack.

8. **Maps and transportation features**
   - `maps.dart`, `maps_route.dart`, and `assets/maps/maps_phrases.txt` indicate a navigation or map-related feature with a phrase catalog.
   - `uber_service.dart` implies integration with an external ride-hailing or transport API/workflow.
   - Architecturally, this is a separate feature branch from OCR/vision, but still driven from the shared service layer.

9. **Device connectivity and hardware integration**
   - `ble_service.dart` shows Bluetooth Low Energy integration, likely for peripheral or wearable communication.
   - `device_filter.xml` in Android resources reinforces that the app may interact with specific hardware classes or filtered devices.
   - This is a notable boundary: some functionality depends on platform permissions and device hardware rather than pure Flutter code.

10. **Platform-specific wrappers**
   - Each desktop/mobile target has the standard Flutter host project:
     - Android native entry at `android/app/src/main/kotlin/.../MainActivity.kt`
     - iOS app shell in `ios/Runner`
     - macOS, Windows, Linux runner projects
   - These folders are mostly platform glue, but they matter architecturally because permissions, plugin registration, and native lifecycle events are handled there.

11. **Shared assets and configuration**
   - `assets/fonts`, `assets/icons`, and launcher resources support app presentation.
   - `assets/assistive_units` and the phrase files suggest the app relies on curated local vocabulary/data for matching or prompting.
   - Asset packaging is a key part of the runtime architecture because the app appears to depend on bundled models and datasets.

12. **Dependency and plugin boundary**
   - `pubspec.yaml` and platform registrants in generated folders indicate the usual Flutter plugin boundary: Flutter code calls plugins for camera, speech, BLE, TTS, OCR, and ML runtime support.
   - The architecture likely depends on a mix of Dart packages plus native plugins to access device capabilities and model runtimes.

13. **What to show in an architecture diagram**
   - A good diagram would center on:
     - **Flutter UI routes**
     - **service layer**
     - **local assets/models**
     - **native platform/plugin boundary**
     - **external services** like maps/ride-hailing
   - The key data flows are:
     - user input → page → service → local ML/OCR/speech
     - user/location intent → maps/uber service → external provider
     - hardware events → BLE/native plugin → service → UI feedback

14. **Repository maturity note**
   - The README is still the default Flutter starter text, so the file structure is more informative than the documentation.
   - The codebase appears to be a feature-rich assistive Flutter app that emphasizes **offline capability, multimodal input/output, and packaged ML assets** over a traditional client-server architecture.

Main entry points: [`lib/services/ble_service.dart`](https://github.com/somespi/baseerah/blob/main/lib/services/ble_service.dart) (BLE service), [`lib/services/ocr/ocr.dart`](https://github.com/somespi/baseerah/blob/main/lib/services/ocr/ocr.dart) (OCR engine), [`lib/services/help_utilities.dart`](https://github.com/somespi/baseerah/blob/main/lib/services/help_utilities.dart) (Assistive helpers), [`lib/main.dart`](https://github.com/somespi/baseerah/blob/main/lib/main.dart) (App bootstrap)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Flutter app"]
  node_main["App bootstrap<br/>Dart entrypoint<br/>[main.dart]"]
  node_login_route["Login screen<br/>UI route<br/>[login_route.dart]"]
  node_maps_route["Maps screen<br/>UI route<br/>[maps_route.dart]"]
  node_ocr_route["OCR screen<br/>UI route<br/>[ocr_route.dart]"]
  node_ar_service["AR service<br/>[ar_service.dart]"]
  node_ocr_service["OCR engine<br/>ocr service<br/>[ocr.dart]"]
  node_speech_to_text["Speech input<br/>speech recognition"]
  node_text_to_speech["Speech output<br/>tts service"]
  node_help_utilities["Assistive helpers<br/>interaction helpers"]
  node_maps_service["Maps logic<br/>maps service<br/>[maps.dart]"]
  node_uber_service["Ride service<br/>transport integration<br/>[uber_service.dart]"]
  node_ble_service["BLE service<br/>device connectivity<br/>[ble_service.dart]"]
  node_tfidf["Text matcher<br/>nlp ranking<br/>[tfidf.dart]"]
  node_document["Text corpus<br/>local knowledge<br/>[document.dart]"]
end

subgraph group_assets["Bundled assets"]
  node_ocr_assets[("OCR data<br/>asset bundle")]
  node_ml_models[("ML models<br/>asset bundle")]
  node_phrase_assets["Phrase files<br/>asset bundle"]
end

subgraph group_platforms["Native shells"]
  node_native_android["Android host<br/>platform shell<br/>[MainActivity.kt]"]
  node_native_ios["iOS host<br/>platform shell<br/>[AppDelegate.swift]"]
  node_native_macos["macOS host<br/>platform shell"]
  node_native_windows["Windows host<br/>platform shell<br/>[main.cpp]"]
  node_native_linux["Linux host<br/>platform shell<br/>[main.cc]"]
end

node_main -->|"starts at"| node_login_route
node_main -->|"navigates"| node_maps_route
node_main -->|"navigates"| node_ocr_route
node_login_route -->|"uses"| node_help_utilities
node_maps_route -->|"uses"| node_maps_service
node_maps_route -->|"uses"| node_uber_service
node_ocr_route -->|"uses"| node_ocr_service
node_ocr_service -->|"loads"| node_ocr_assets
node_ocr_service -->|"may use"| node_ml_models
node_speech_to_text -->|"feeds"| node_help_utilities
node_text_to_speech -->|"driven by"| node_help_utilities
node_help_utilities -->|"uses"| node_tfidf
node_tfidf -->|"reads"| node_document
node_ar_service -->|"loads"| node_ml_models
node_maps_service -->|"reads"| node_phrase_assets
node_uber_service -->|"reads"| node_phrase_assets
node_ble_service -->|"bridges"| node_native_android
node_ble_service -->|"bridges"| node_native_ios
node_ble_service -->|"bridges"| node_native_macos
node_ble_service -->|"bridges"| node_native_windows
node_ble_service -->|"bridges"| node_native_linux
node_ocr_service -->|"bridges"| node_native_android
node_ocr_service -->|"bridges"| node_native_ios

click node_main "https://github.com/somespi/baseerah/blob/main/lib/main.dart"
click node_login_route "https://github.com/somespi/baseerah/blob/main/lib/pages/login_route.dart"
click node_maps_route "https://github.com/somespi/baseerah/blob/main/lib/pages/maps_route.dart"
click node_ocr_route "https://github.com/somespi/baseerah/blob/main/lib/pages/ocr_route.dart"
click node_ar_service "https://github.com/somespi/baseerah/blob/main/lib/services/ar_service.dart"
click node_ocr_service "https://github.com/somespi/baseerah/blob/main/lib/services/ocr/ocr.dart"
click node_speech_to_text "https://github.com/somespi/baseerah/blob/main/lib/services/speech_to_text.dart"
click node_text_to_speech "https://github.com/somespi/baseerah/blob/main/lib/services/text_to_speech.dart"
click node_help_utilities "https://github.com/somespi/baseerah/blob/main/lib/services/help_utilities.dart"
click node_maps_service "https://github.com/somespi/baseerah/blob/main/lib/services/maps.dart"
click node_uber_service "https://github.com/somespi/baseerah/blob/main/lib/services/uber_service.dart"
click node_ble_service "https://github.com/somespi/baseerah/blob/main/lib/services/ble_service.dart"
click node_tfidf "https://github.com/somespi/baseerah/blob/main/lib/services/tfidf.dart"
click node_document "https://github.com/somespi/baseerah/blob/main/lib/services/document.dart"
click node_ocr_assets "https://github.com/somespi/baseerah/tree/main/assets/tessdata"
click node_ml_models "https://github.com/somespi/baseerah/tree/main/assets/models"
click node_phrase_assets "https://github.com/somespi/baseerah/tree/main/assets/ocr"
click node_native_android "https://github.com/somespi/baseerah/blob/main/android/app/src/main/kotlin/com/example/baseerah/MainActivity.kt"
click node_native_ios "https://github.com/somespi/baseerah/blob/main/ios/Runner/AppDelegate.swift"
click node_native_macos "https://github.com/somespi/baseerah/blob/main/macos/Runner/MainFlutterWindow.swift"
click node_native_windows "https://github.com/somespi/baseerah/blob/main/windows/runner/main.cpp"
click node_native_linux "https://github.com/somespi/baseerah/blob/main/linux/main.cc"

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_main,node_login_route,node_maps_route,node_ocr_route,node_ar_service,node_ocr_service,node_speech_to_text,node_text_to_speech,node_help_utilities,node_maps_service,node_uber_service,node_ble_service,node_tfidf,node_document toneBlue
class node_ocr_assets,node_ml_models,node_phrase_assets toneAmber
class node_native_android,node_native_ios,node_native_macos,node_native_windows,node_native_linux toneMint
```

## Components

### Flutter app

Cross-platform Dart application: entrypoint, routes, and shared services.

- [App bootstrap](https://github.com/somespi/baseerah/blob/main/lib/main.dart): Dart entrypoint · Initializes the Flutter app and wiring between routes and services. · `lib/main.dart`
- [Login screen](https://github.com/somespi/baseerah/blob/main/lib/pages/login_route.dart): UI route · Entry/login-facing page in the route-based UI. · `lib/pages/login_route.dart`
- [Maps screen](https://github.com/somespi/baseerah/blob/main/lib/pages/maps_route.dart): UI route · Screen for map and transport-related interactions. · `lib/pages/maps_route.dart`
- [OCR screen](https://github.com/somespi/baseerah/blob/main/lib/pages/ocr_route.dart): UI route · Screen for image-to-text capture and review. · `lib/pages/ocr_route.dart`
- [AR service](https://github.com/somespi/baseerah/blob/main/lib/services/ar_service.dart): vision/AR service · Assistive vision or augmented-reality oriented logic behind the UI. · `lib/services/ar_service.dart`
- [OCR engine](https://github.com/somespi/baseerah/blob/main/lib/services/ocr/ocr.dart): ocr service · OCR implementation used by the OCR route and related assistive flows. · `lib/services/ocr/ocr.dart`
- [Speech input](https://github.com/somespi/baseerah/blob/main/lib/services/speech_to_text.dart): speech recognition · Converts spoken user input into text. · `lib/services/speech_to_text.dart`
- [Speech output](https://github.com/somespi/baseerah/blob/main/lib/services/text_to_speech.dart): tts service · Reads app responses aloud to the user. · `lib/services/text_to_speech.dart`
- [Assistive helpers](https://github.com/somespi/baseerah/blob/main/lib/services/help_utilities.dart): interaction helpers · Shared assistive utilities and support logic used across features. · `lib/services/help_utilities.dart`
- [Maps logic](https://github.com/somespi/baseerah/blob/main/lib/services/maps.dart): maps service · Map-related feature logic and phrase handling. · `lib/services/maps.dart`
- [Ride service](https://github.com/somespi/baseerah/blob/main/lib/services/uber_service.dart): transport integration · External ride-hailing or transport workflow integration. · `lib/services/uber_service.dart`
- [BLE service](https://github.com/somespi/baseerah/blob/main/lib/services/ble_service.dart): device connectivity · Bluetooth Low Energy communication with nearby peripherals or wearables. · `lib/services/ble_service.dart`
- [Text matcher](https://github.com/somespi/baseerah/blob/main/lib/services/tfidf.dart): nlp ranking · Local phrase matching or intent ranking for commands and prompts. · `lib/services/tfidf.dart`
- [Text corpus](https://github.com/somespi/baseerah/blob/main/lib/services/document.dart): local knowledge · Structured text or document data used by local matching logic. · `lib/services/document.dart`

### Bundled assets

Local models, OCR data, phrases, icons, and fonts used at runtime.

- [OCR data](https://github.com/somespi/baseerah/tree/main/assets/tessdata): asset bundle · OCR phrases, trained data, and config packaged for offline recognition. · `assets/tessdata`
- [ML models](https://github.com/somespi/baseerah/tree/main/assets/models): asset bundle · Packaged ONNX/TFLite models and labels for local inference. · `assets/models`
- [Phrase files](https://github.com/somespi/baseerah/tree/main/assets/ocr): asset bundle · Curated phrase lists for OCR, maps, taxi, and assistive workflows. · `assets/ocr`

### Native shells

Platform-specific host projects and plugin registrants for mobile, desktop, and web.

- [Android host](https://github.com/somespi/baseerah/blob/main/android/app/src/main/kotlin/com/example/baseerah/MainActivity.kt): platform shell · Android runner and native entrypoint for permissions, plugins, and lifecycle. · `android/app/src/main/kotlin/com/example/baseerah/MainActivity.kt`
- [iOS host](https://github.com/somespi/baseerah/blob/main/ios/Runner/AppDelegate.swift): platform shell · iOS runner and app lifecycle shell. · `ios/Runner/AppDelegate.swift`
- [macOS host](https://github.com/somespi/baseerah/blob/main/macos/Runner/MainFlutterWindow.swift): platform shell · macOS runner and window shell. · `macos/Runner/MainFlutterWindow.swift`
- [Windows host](https://github.com/somespi/baseerah/blob/main/windows/runner/main.cpp): platform shell · Windows runner and desktop window shell. · `windows/runner/main.cpp`
- [Linux host](https://github.com/somespi/baseerah/blob/main/linux/main.cc): platform shell · Linux runner and desktop application shell. · `linux/main.cc`

## Connections

- App bootstrap → Login screen: starts at · App bootstraps into the route-based UI.
- App bootstrap → Maps screen: navigates · Registers or reaches the maps feature screen.
- App bootstrap → OCR screen: navigates · Registers or reaches the OCR feature screen.
- Login screen → Assistive helpers: uses · Login and onboarding reuse shared assistive helpers.
- Maps screen → Maps logic: uses · Maps screen delegates feature logic to service layer.
- Maps screen → Ride service: uses · Transport-related actions flow to ride integration.
- OCR screen → OCR engine: uses · OCR screen delegates capture and recognition work.
- OCR engine → OCR data: loads · OCR depends on bundled trained data and phrases.
- OCR engine → ML models: may use · Recognition or inference can leverage packaged local models.
- Speech input → Assistive helpers: feeds · Captured speech is interpreted by shared assistive logic.
- Speech output → Assistive helpers: driven by · Response generation and spoken feedback are coordinated by helpers.
- Assistive helpers → Text matcher: uses · Helper logic relies on local text ranking or matching.
- Text matcher → Text corpus: reads · Text matching is driven by local document/corpus data.
- AR service → ML models: loads · Vision/AR features can depend on local inference models.
- Maps logic → Phrase files: reads · Maps-related command phrases are bundled locally.
- Ride service → Phrase files: reads · Transport prompts and phrases are packaged as local assets.
- BLE service → Android host: bridges · Device connectivity depends on native plugin access on mobile platforms.
- BLE service → iOS host: bridges · Device connectivity depends on native plugin access on mobile platforms.
- BLE service → macOS host: bridges · Desktop platform shell may expose plugin support.
- BLE service → Windows host: bridges · Desktop platform shell may expose plugin support.
- BLE service → Linux host: bridges · Desktop platform shell may expose plugin support.
- OCR engine → Android host: bridges · OCR and device permissions rely on native host integration.
- OCR engine → iOS host: bridges · OCR and device permissions rely on native host integration.
