# lungmen-hkm/traincenter architecture

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

- Interactive diagram: https://gitdiagram.com/lungmen-hkm/traincenter
- Repository: https://github.com/lungmen-hkm/traincenter

## Overview

TrainCenter is a privacy-first Flutter activity tracker with no account or backend; activities, gear, segments, and settings are stored locally. The main workflow is GPS recording, reviewing and confirming a finished activity, then saving it for history and automatic segment-effort matching. Other capabilities include gear management, activity details, transparent PNG export, and appearance settings. Relationships below follow README documentation; Dart implementation files were not sampled, so undocumented calls are omitted.

Main entry points: [`lib/features/finish/finish_screen.dart`](https://github.com/lungmen-hkm/traincenter/blob/main/lib/features/finish/finish_screen.dart) (Finish confirmation), [`lib/features/export/export_sheet.dart`](https://github.com/lungmen-hkm/traincenter/blob/main/lib/features/export/export_sheet.dart) (PNG export), [`lib/data/repositories/activity_repository.dart`](https://github.com/lungmen-hkm/traincenter/blob/main/lib/data/repositories/activity_repository.dart) (Activity repository), [`lib/features/record/record_screen.dart`](https://github.com/lungmen-hkm/traincenter/blob/main/lib/features/record/record_screen.dart) (Record screen)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_recording["Recording"]
  node_record_ui["Record screen<br/>[record_screen.dart]"]
  node_record_ctrl["Record controller"]
  node_location["Location service"]
  node_background_location["Background tracking"]
  node_map["Training map"]
  node_finish["Finish confirmation<br/>[finish_screen.dart]"]
  node_confirm_widget["Slide to confirm"]
end

subgraph group_activities["Activities"]
  node_activities_ui["Activity history"]
  node_activity_detail["Activity detail"]
  node_export["PNG export<br/>[export_sheet.dart]"]
  node_export_card["Export card"]
  node_gear["Gear management<br/>[gear_screen.dart]"]
  node_segments["Segment management"]
end

subgraph group_domain_data["Domain and Data"]
  node_matcher["Segment matcher"]
  node_efforts["Effort service"]
  node_activity_repo["Activity repository"]
  node_database[("Local database<br/>[app_database.dart]")]
end

subgraph group_app_services["App Services"]
  node_app["App shell<br/>[app.dart]"]
  node_bootstrap["Bootstrap<br/>[main.dart]"]
  node_settings["App settings<br/>[app_settings.dart]"]
  node_settings_ui["Settings screen"]
end

node_athlete(("Athlete"))
node_share["Native share sheet"]
node_downloads["Downloads folder"]

node_athlete -->|"starts recording"| node_record_ui
node_record_ui -->|"controls"| node_record_ctrl
node_record_ctrl -->|"reads GPS"| node_location
node_record_ctrl -->|"tracks in background"| node_background_location
node_record_ui -->|"shows route"| node_map
node_athlete -->|"reviews activity"| node_finish
node_finish -->|"confirms save"| node_confirm_widget
node_finish -->|"saves activity"| node_activity_repo
node_bootstrap -->|"opens database"| node_database
node_bootstrap -->|"runs app"| node_app
node_activities_ui -->|"loads history"| node_activity_repo
node_activity_detail -->|"loads activity"| node_activity_repo
node_activity_detail -->|"opens export"| node_export
node_export -->|"captures card"| node_export_card
node_export -->|"saves PNG"| node_downloads
node_export -->|"shares image"| node_share
node_gear -->|"updates distance on save"| node_activity_repo
node_segments -->|"defines segments"| node_matcher
node_finish -->|"triggers matching after save"| node_matcher
node_matcher -->|"computes and persists efforts"| node_efforts
node_settings_ui -->|"changes appearance"| node_settings
node_settings -->|"stores preferences"| node_database

click node_app "https://github.com/lungmen-hkm/traincenter/blob/main/lib/app.dart"
click node_bootstrap "https://github.com/lungmen-hkm/traincenter/blob/main/lib/main.dart"
click node_record_ui "https://github.com/lungmen-hkm/traincenter/blob/main/lib/features/record/record_screen.dart"
click node_record_ctrl "https://github.com/lungmen-hkm/traincenter/blob/main/lib/features/record/record_controller.dart"
click node_location "https://github.com/lungmen-hkm/traincenter/blob/main/lib/core/services/location_service.dart"
click node_background_location "https://github.com/lungmen-hkm/traincenter/blob/main/lib/core/services/background_location_service.dart"
click node_map "https://github.com/lungmen-hkm/traincenter/blob/main/lib/core/widgets/train_center_map.dart"
click node_finish "https://github.com/lungmen-hkm/traincenter/blob/main/lib/features/finish/finish_screen.dart"
click node_confirm_widget "https://github.com/lungmen-hkm/traincenter/blob/main/lib/core/widgets/slide_to_confirm.dart"
click node_activities_ui "https://github.com/lungmen-hkm/traincenter/blob/main/lib/features/activities/activities_screen.dart"
click node_activity_detail "https://github.com/lungmen-hkm/traincenter/blob/main/lib/features/activities/activity_detail_screen.dart"
click node_export "https://github.com/lungmen-hkm/traincenter/blob/main/lib/features/export/export_sheet.dart"
click node_export_card "https://github.com/lungmen-hkm/traincenter/blob/main/lib/features/export/activity_export_card.dart"
click node_gear "https://github.com/lungmen-hkm/traincenter/blob/main/lib/features/gear/gear_screen.dart"
click node_segments "https://github.com/lungmen-hkm/traincenter/blob/main/lib/features/segments/segments_screen.dart"
click node_matcher "https://github.com/lungmen-hkm/traincenter/blob/main/lib/domain/services/segment_matcher.dart"
click node_efforts "https://github.com/lungmen-hkm/traincenter/blob/main/lib/data/services/segment_effort_service.dart"
click node_activity_repo "https://github.com/lungmen-hkm/traincenter/blob/main/lib/data/repositories/activity_repository.dart"
click node_database "https://github.com/lungmen-hkm/traincenter/blob/main/lib/core/db/app_database.dart"
click node_settings "https://github.com/lungmen-hkm/traincenter/blob/main/lib/features/settings/app_settings.dart"
click node_settings_ui "https://github.com/lungmen-hkm/traincenter/blob/main/lib/features/settings/settings_screen.dart"

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_record_ui,node_record_ctrl,node_location,node_background_location,node_map,node_finish,node_confirm_widget toneBlue
class node_activities_ui,node_activity_detail,node_export,node_export_card,node_gear,node_segments toneAmber
class node_matcher,node_efforts,node_activity_repo,node_database toneMint
class node_app,node_bootstrap,node_settings,node_settings_ui toneRose
class node_athlete,node_share,node_downloads toneIndigo
```

## Components

### Recording

- [Record screen](https://github.com/lungmen-hkm/traincenter/blob/main/lib/features/record/record_screen.dart): `lib/features/record/record_screen.dart`
- [Record controller](https://github.com/lungmen-hkm/traincenter/blob/main/lib/features/record/record_controller.dart): `lib/features/record/record_controller.dart`
- [Location service](https://github.com/lungmen-hkm/traincenter/blob/main/lib/core/services/location_service.dart): `lib/core/services/location_service.dart`
- [Background tracking](https://github.com/lungmen-hkm/traincenter/blob/main/lib/core/services/background_location_service.dart): `lib/core/services/background_location_service.dart`
- [Training map](https://github.com/lungmen-hkm/traincenter/blob/main/lib/core/widgets/train_center_map.dart): `lib/core/widgets/train_center_map.dart`
- [Finish confirmation](https://github.com/lungmen-hkm/traincenter/blob/main/lib/features/finish/finish_screen.dart): `lib/features/finish/finish_screen.dart`
- [Slide to confirm](https://github.com/lungmen-hkm/traincenter/blob/main/lib/core/widgets/slide_to_confirm.dart): `lib/core/widgets/slide_to_confirm.dart`

### Activities

- [Activity history](https://github.com/lungmen-hkm/traincenter/blob/main/lib/features/activities/activities_screen.dart): `lib/features/activities/activities_screen.dart`
- [Activity detail](https://github.com/lungmen-hkm/traincenter/blob/main/lib/features/activities/activity_detail_screen.dart): `lib/features/activities/activity_detail_screen.dart`
- [PNG export](https://github.com/lungmen-hkm/traincenter/blob/main/lib/features/export/export_sheet.dart): `lib/features/export/export_sheet.dart`
- [Export card](https://github.com/lungmen-hkm/traincenter/blob/main/lib/features/export/activity_export_card.dart): `lib/features/export/activity_export_card.dart`
- [Gear management](https://github.com/lungmen-hkm/traincenter/blob/main/lib/features/gear/gear_screen.dart): `lib/features/gear/gear_screen.dart`
- [Segment management](https://github.com/lungmen-hkm/traincenter/blob/main/lib/features/segments/segments_screen.dart): `lib/features/segments/segments_screen.dart`

### Domain and Data

- [Segment matcher](https://github.com/lungmen-hkm/traincenter/blob/main/lib/domain/services/segment_matcher.dart): `lib/domain/services/segment_matcher.dart`
- [Effort service](https://github.com/lungmen-hkm/traincenter/blob/main/lib/data/services/segment_effort_service.dart): `lib/data/services/segment_effort_service.dart`
- [Activity repository](https://github.com/lungmen-hkm/traincenter/blob/main/lib/data/repositories/activity_repository.dart): `lib/data/repositories/activity_repository.dart`
- [Local database](https://github.com/lungmen-hkm/traincenter/blob/main/lib/core/db/app_database.dart): `lib/core/db/app_database.dart`

### App Services

- [App shell](https://github.com/lungmen-hkm/traincenter/blob/main/lib/app.dart): `lib/app.dart`
- [Bootstrap](https://github.com/lungmen-hkm/traincenter/blob/main/lib/main.dart): `lib/main.dart`
- [App settings](https://github.com/lungmen-hkm/traincenter/blob/main/lib/features/settings/app_settings.dart): `lib/features/settings/app_settings.dart`
- [Settings screen](https://github.com/lungmen-hkm/traincenter/blob/main/lib/features/settings/settings_screen.dart): `lib/features/settings/settings_screen.dart`

### Other components

- **Athlete**
- **Native share sheet**
- **Downloads folder**

## Connections

- Athlete → Record screen: starts recording (evidence: `README.md`)
- Record screen → Record controller: controls (evidence: `README.md`)
- Record controller → Location service: reads GPS (evidence: `README.md`)
- Record controller → Background tracking: tracks in background (evidence: `README.md`)
- Record screen → Training map: shows route (evidence: `README.md`)
- Athlete → Finish confirmation: reviews activity (evidence: `README.md`)
- Finish confirmation → Slide to confirm: confirms save (evidence: `README.md`)
- Finish confirmation → Activity repository: saves activity (evidence: `README.md`)
- Bootstrap → Local database: opens database (evidence: `README.md`)
- Bootstrap → App shell: runs app (evidence: `README.md`)
- Activity history → Activity repository: loads history (evidence: `README.md`)
- Activity detail → Activity repository: loads activity (evidence: `README.md`)
- Activity detail → PNG export: opens export (evidence: `README.md`)
- PNG export → Export card: captures card (evidence: `README.md`)
- PNG export → Downloads folder: saves PNG (evidence: `README.md`)
- PNG export → Native share sheet: shares image (evidence: `README.md`)
- Gear management → Activity repository: updates distance on save (evidence: `README.md`)
- Segment management → Segment matcher: defines segments (evidence: `README.md`)
- Finish confirmation → Segment matcher: triggers matching after save (evidence: `README.md`)
- Segment matcher → Effort service: computes and persists efforts (evidence: `README.md`)
- Settings screen → App settings: changes appearance (evidence: `README.md`)
- App settings → Local database: stores preferences (evidence: `README.md`)
