# huisam1611/voice3 architecture

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

- Interactive diagram: https://gitdiagram.com/huisam1611/voice3
- Repository: https://github.com/huisam1611/voice3

## Overview

1. This is a Flutter mobile app with a thin platform layer for Android and iOS. The main product logic lives in `lib/`, while `android/` and `ios/` provide native packaging, platform entry points, and speech-related integrations.

2. The app is organized as a feature-first Flutter UI. Major screens are `home`, `learning`, `theme_detail`, `result`, `review`, `progress`, and `settings`, each with its own screen file and local widgets. That layout suggests the app flow is primarily user-driven through a learning journey rather than a generic CRUD app.

3. The central domain appears to be a guided language/voice learning experience. The learning flow is backed by models such as `ThemePack`, `Question`, `Level`, `LearningRecord`, and `ScoringResult`, which indicate content packs, step-based progression, and post-attempt evaluation.

4. `lib/core/database` contains a local persistence layer, including `database_helper.dart` and table definitions. This is the main storage boundary for user progress and learning history; the presence of progress and review screens implies the database is used to reconstruct prior attempts and aggregate statistics offline.

5. `lib/core/bridge/native_bridge.dart` is the key cross-platform boundary. It likely mediates between Flutter and native Android/iOS capabilities, especially speech input/output and possibly model execution, so it is the architectural seam where Dart UI logic hands off to platform code.

6. Speech processing is split into dedicated native services on Android under `android/app/src/main/kotlin/com/example/voice3/services/`: `SttService`, `TtsService`, and `ScoringEngine`. This strongly suggests recognition, synthesis, and answer scoring are handled outside Dart for performance and/or native SDK access.

7. Android bundles a local speech model stack: `android/app/libs/sherpa-onnx-1.12.28.aar` and assets under `android/app/src/main/assets/models/sherpa-onnx-paraformer-zh/`. The included `tokens.txt` and placeholder for model files indicate on-device STT using Sherpa-ONNX rather than a cloud speech API.

8. The asset tree shows the app is content-heavy and likely driven by packaged learning materials. `assets/data/themes/*.json` defines themed lesson content, while `assets/images/scenes`, `assets/images/words`, `assets/audio`, and `assets/animations` supply the visual and audio content shown during learning.

9. `lib/features/learning/learning_controller.dart` is probably the primary orchestration point for session state: loading theme content, moving through prompts, invoking speech services, scoring responses, and updating progress records. The nearby widgets (`mic_button`, `feedback_overlay`, `progress_indicator_bar`, `scene_intro`, `word_card`) imply a real-time interaction loop around voice capture and feedback.

10. The result and progress areas form the app’s feedback/reporting loop. `result` presents per-attempt scoring details and ratings, while `progress` summarizes longer-term performance using a calendar heatmap and stats widgets; both likely read from the local database rather than remote analytics.

11. `lib/app/` contains the app shell: routing, theming, and top-level composition. `routes.dart` and `theme.dart` define navigation and visual system boundaries, while `main.dart` bootstraps the Flutter app.

12. Platform-specific entry points are standard but still important for architecture. Android uses a custom `MainActivity.kt` and an app-level Gradle setup; iOS uses `AppDelegate.swift`, `Runner-Bridging-Header.h`, and the usual Xcode project structure. These files indicate the Flutter shell delegates to native code where needed, rather than reimplementing the full app natively.

13. The repository is intentionally offline-first. Content packs are local, speech models are bundled locally on Android, and progress appears to be stored in SQLite via the app’s database layer. That means the main runtime dependency is device resources, not network connectivity.

14. In diagram terms, the main flow is: Flutter home/theme selection → learning session controller → native speech bridge/services for recording, recognition, synthesis, and scoring → local database writes for progress/result history → result/progress/review screens for user feedback. The major boundaries are UI vs domain logic, Dart vs native speech implementation, and content/assets vs persisted user state.

Main entry points: [`lib/features/learning/learning_controller.dart`](https://github.com/huisam1611/voice3/blob/main/lib/features/learning/learning_controller.dart) (Session controller), [`lib/core/bridge/native_bridge.dart`](https://github.com/huisam1611/voice3/blob/main/lib/core/bridge/native_bridge.dart) (Native bridge), [`android/app/src/main/kotlin/com/example/voice3/MainActivity.kt`](https://github.com/huisam1611/voice3/blob/main/android/app/src/main/kotlin/com/example/voice3/MainActivity.kt) (MainActivity), [`lib/app/app.dart`](https://github.com/huisam1611/voice3/blob/main/lib/app/app.dart) (App shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_flutter_app["Flutter app"]
  node_main(("Main<br/>bootstrap<br/>[main.dart]"))
  node_app_shell["App shell<br/>routing/theme<br/>[app.dart]"]
  node_routes["Routes<br/>navigation<br/>[routes.dart]"]
  node_theme["Theme<br/>ui system<br/>[theme.dart]"]
end

subgraph group_domain["Domain & data"]
  node_bridge["Native bridge<br/>platform channel<br/>[native_bridge.dart]"]
  node_db[("Database<br/>local storage")]
  node_models{{"Learning models<br/>domain model<br/>[theme_pack.dart]"}}
end

subgraph group_features["Feature screens"]
  node_home["Home<br/>screen<br/>[home_screen.dart]"]
  node_theme_detail["Theme detail<br/>screen"]
  node_learning_screen["Learning<br/>screen"]
  node_learning_ctrl["Session controller<br/>orchestration"]
  node_result_screen["Result<br/>screen<br/>[result_screen.dart]"]
  node_progress_screen["Progress<br/>screen"]
  node_review_screen["Review<br/>screen<br/>[review_screen.dart]"]
  node_settings_screen["Settings<br/>screen"]
end

subgraph group_native_android["Android native"]
  node_stt["STT service<br/>native speech<br/>[SttService.kt]"]
  node_tts["TTS service<br/>native speech<br/>[TtsService.kt]"]
  node_scoring["Scoring engine<br/>native evaluation<br/>[ScoringEngine.kt]"]
  node_android_entry["MainActivity<br/>android entry<br/>[MainActivity.kt]"]
end

subgraph group_native_ios["iOS native"]
  node_ios_entry["AppDelegate<br/>ios entry<br/>[AppDelegate.swift]"]
end

subgraph group_content["Packaged content"]
  node_theme_assets["Theme packs<br/>lesson content<br/>[hobbies.json]"]
  node_media_assets["Media assets<br/>audio/visual content<br/>[.gitkeep]"]
end

node_main -->|"boots"| node_app_shell
node_app_shell -->|"uses"| node_routes
node_app_shell -->|"applies"| node_theme
node_routes -->|"opens"| node_home
node_home -->|"selects"| node_theme_detail
node_theme_detail -->|"starts"| node_learning_screen
node_learning_screen -->|"drives"| node_learning_ctrl
node_learning_ctrl -->|"loads"| node_models
node_learning_ctrl -->|"uses"| node_theme_assets
node_learning_ctrl -->|"renders"| node_media_assets
node_learning_ctrl -->|"invokes"| node_bridge
node_bridge -->|"calls"| node_stt
node_bridge -->|"calls"| node_tts
node_bridge -->|"calls"| node_scoring
node_learning_ctrl -->|"persists"| node_db
node_db -->|"feeds"| node_progress_screen
node_db -->|"feeds"| node_review_screen
node_learning_ctrl -->|"publishes"| node_result_screen
node_progress_screen -->|"drills into"| node_result_screen
node_android_entry -->|"hosts"| node_stt
node_android_entry -->|"hosts"| node_tts
node_android_entry -->|"hosts"| node_scoring
node_ios_entry -->|"connects"| node_bridge

click node_main "https://github.com/huisam1611/voice3/blob/main/lib/main.dart"
click node_app_shell "https://github.com/huisam1611/voice3/blob/main/lib/app/app.dart"
click node_routes "https://github.com/huisam1611/voice3/blob/main/lib/app/routes.dart"
click node_theme "https://github.com/huisam1611/voice3/blob/main/lib/app/theme.dart"
click node_bridge "https://github.com/huisam1611/voice3/blob/main/lib/core/bridge/native_bridge.dart"
click node_db "https://github.com/huisam1611/voice3/blob/main/lib/core/database/database_helper.dart"
click node_models "https://github.com/huisam1611/voice3/blob/main/lib/core/models/theme_pack.dart"
click node_home "https://github.com/huisam1611/voice3/blob/main/lib/features/home/home_screen.dart"
click node_theme_detail "https://github.com/huisam1611/voice3/blob/main/lib/features/theme_detail/theme_detail_screen.dart"
click node_learning_screen "https://github.com/huisam1611/voice3/blob/main/lib/features/learning/learning_screen.dart"
click node_learning_ctrl "https://github.com/huisam1611/voice3/blob/main/lib/features/learning/learning_controller.dart"
click node_result_screen "https://github.com/huisam1611/voice3/blob/main/lib/features/result/result_screen.dart"
click node_progress_screen "https://github.com/huisam1611/voice3/blob/main/lib/features/progress/progress_screen.dart"
click node_review_screen "https://github.com/huisam1611/voice3/blob/main/lib/features/review/review_screen.dart"
click node_settings_screen "https://github.com/huisam1611/voice3/blob/main/lib/features/settings/settings_screen.dart"
click node_stt "https://github.com/huisam1611/voice3/blob/main/android/app/src/main/kotlin/com/example/voice3/services/SttService.kt"
click node_tts "https://github.com/huisam1611/voice3/blob/main/android/app/src/main/kotlin/com/example/voice3/services/TtsService.kt"
click node_scoring "https://github.com/huisam1611/voice3/blob/main/android/app/src/main/kotlin/com/example/voice3/services/ScoringEngine.kt"
click node_android_entry "https://github.com/huisam1611/voice3/blob/main/android/app/src/main/kotlin/com/example/voice3/MainActivity.kt"
click node_ios_entry "https://github.com/huisam1611/voice3/blob/main/ios/Runner/AppDelegate.swift"
click node_theme_assets "https://github.com/huisam1611/voice3/blob/main/assets/data/themes/hobbies.json"
click node_media_assets "https://github.com/huisam1611/voice3/blob/main/assets/images/scenes/.gitkeep"

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_app_shell,node_routes,node_theme toneBlue
class node_bridge,node_db,node_models toneAmber
class node_home,node_theme_detail,node_learning_screen,node_learning_ctrl,node_result_screen,node_progress_screen,node_review_screen,node_settings_screen toneMint
class node_stt,node_tts,node_scoring,node_android_entry toneRose
class node_ios_entry toneIndigo
class node_theme_assets,node_media_assets toneTeal
```

## Components

### Flutter app

Dart shell, routing, and feature UI

- [Main](https://github.com/huisam1611/voice3/blob/main/lib/main.dart): bootstrap · Flutter app entry point · `lib/main.dart`
- [App shell](https://github.com/huisam1611/voice3/blob/main/lib/app/app.dart): routing/theme · Top-level composition, routes, and theme · `lib/app/app.dart`
- [Routes](https://github.com/huisam1611/voice3/blob/main/lib/app/routes.dart): navigation · App route map and screen wiring · `lib/app/routes.dart`
- [Theme](https://github.com/huisam1611/voice3/blob/main/lib/app/theme.dart): ui system · Shared visual styling and tokens · `lib/app/theme.dart`

### Domain & data

Learning models, persistence, and native bridge

- [Native bridge](https://github.com/huisam1611/voice3/blob/main/lib/core/bridge/native_bridge.dart): platform channel · Dart boundary to native speech capabilities · `lib/core/bridge/native_bridge.dart`
- [Database](https://github.com/huisam1611/voice3/blob/main/lib/core/database/database_helper.dart): local storage · SQLite helper and table access · `lib/core/database/database_helper.dart`
- [Learning models](https://github.com/huisam1611/voice3/blob/main/lib/core/models/theme_pack.dart): domain model · Theme packs, questions, levels, records, and scores · `lib/core/models/theme_pack.dart`

### Feature screens

User-facing learning journey screens

- [Home](https://github.com/huisam1611/voice3/blob/main/lib/features/home/home_screen.dart): screen · Entry screen for theme selection · `lib/features/home/home_screen.dart`
- [Theme detail](https://github.com/huisam1611/voice3/blob/main/lib/features/theme_detail/theme_detail_screen.dart): screen · Theme overview and level selection · `lib/features/theme_detail/theme_detail_screen.dart`
- [Learning](https://github.com/huisam1611/voice3/blob/main/lib/features/learning/learning_screen.dart): screen · Interactive voice learning session UI · `lib/features/learning/learning_screen.dart`
- [Session controller](https://github.com/huisam1611/voice3/blob/main/lib/features/learning/learning_controller.dart): orchestration · Loads content, advances prompts, scores input, and persists progress · `lib/features/learning/learning_controller.dart`
- [Result](https://github.com/huisam1611/voice3/blob/main/lib/features/result/result_screen.dart): screen · Per-attempt scoring and feedback view · `lib/features/result/result_screen.dart`
- [Progress](https://github.com/huisam1611/voice3/blob/main/lib/features/progress/progress_screen.dart): screen · Long-term stats and history overview · `lib/features/progress/progress_screen.dart`
- [Review](https://github.com/huisam1611/voice3/blob/main/lib/features/review/review_screen.dart): screen · Past attempt review and recap · `lib/features/review/review_screen.dart`
- [Settings](https://github.com/huisam1611/voice3/blob/main/lib/features/settings/settings_screen.dart): screen · App preferences and configuration · `lib/features/settings/settings_screen.dart`

### Android native

Platform speech and packaging layer

- [STT service](https://github.com/huisam1611/voice3/blob/main/android/app/src/main/kotlin/com/example/voice3/services/SttService.kt): native speech · Android on-device speech recognition · `android/app/src/main/kotlin/com/example/voice3/services/SttService.kt`
- [TTS service](https://github.com/huisam1611/voice3/blob/main/android/app/src/main/kotlin/com/example/voice3/services/TtsService.kt): native speech · Android text-to-speech output · `android/app/src/main/kotlin/com/example/voice3/services/TtsService.kt`
- [Scoring engine](https://github.com/huisam1611/voice3/blob/main/android/app/src/main/kotlin/com/example/voice3/services/ScoringEngine.kt): native evaluation · Android answer evaluation and scoring · `android/app/src/main/kotlin/com/example/voice3/services/ScoringEngine.kt`
- [MainActivity](https://github.com/huisam1611/voice3/blob/main/android/app/src/main/kotlin/com/example/voice3/MainActivity.kt): android entry · Flutter host activity and plugin boundary · `android/app/src/main/kotlin/com/example/voice3/MainActivity.kt`

### iOS native

Platform entry and bridge layer

- [AppDelegate](https://github.com/huisam1611/voice3/blob/main/ios/Runner/AppDelegate.swift): ios entry · iOS host entry and bridge setup · `ios/Runner/AppDelegate.swift`

### Packaged content

Local lesson assets and media

- [Theme packs](https://github.com/huisam1611/voice3/blob/main/assets/data/themes/hobbies.json): lesson content · Packaged lesson JSON content · `assets/data/themes/hobbies.json`
- [Media assets](https://github.com/huisam1611/voice3/blob/main/assets/images/scenes/.gitkeep): audio/visual content · Packaged scenes, words, audio, and animations · `assets/images/scenes/.gitkeep`

## Connections

- Main → App shell: boots · Starts the app shell
- App shell → Routes: uses · Wires navigation between screens
- App shell → Theme: applies · Provides global styling
- Routes → Home: opens · Initial landing screen
- Home → Theme detail: selects · Moves into a theme
- Theme detail → Learning: starts · Begins a learning session
- Learning → Session controller: drives · UI is coordinated by session state
- Session controller → Learning models: loads · Reads theme packs, questions, levels, and results
- Session controller → Theme packs: uses · Consumes packaged lesson content
- Session controller → Media assets: renders · Shows scenes, words, audio, and animations
- Session controller → Native bridge: invokes · Hands off speech and scoring work to native layer
- Native bridge → STT service: calls · Requests speech recognition
- Native bridge → TTS service: calls · Requests spoken feedback
- Native bridge → Scoring engine: calls · Requests answer evaluation
- Session controller → Database: persists · Stores attempts and progress
- Database → Progress: feeds · Supplies history and summaries
- Database → Review: feeds · Reconstructs prior attempts
- Session controller → Result: publishes · Sends final attempt scoring
- Progress → Result: drills into · Detailed attempt feedback
- MainActivity → STT service: hosts · Android host for speech services
- MainActivity → TTS service: hosts · Android host for speech services
- MainActivity → Scoring engine: hosts · Android host for speech services
- AppDelegate → Native bridge: connects · iOS platform bridge setup
