# tianshang301/tianshanghealth architecture

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

- Interactive diagram: https://gitdiagram.com/tianshang301/tianshanghealth
- Repository: https://github.com/tianshang301/tianshanghealth

## Overview

TianshangHealth is a privacy-first, offline Android health companion. Users enter through the app’s navigation, set up a profile, then log and review period, activity, sleep, and nutrition data; the dashboard and analysis features turn those records into insights and predictions. A local encrypted database underpins the health domains, while optional BLE watch integration adds wearable readings and anomaly events. The README documents the major capabilities and module layout; several feature paths below identify directories because their implementations were not sampled.

Main entry points: [`app/src/main/java/com/tianshang/health/navigation/MainNavigation.kt`](https://github.com/tianshang301/tianshanghealth/blob/main/app/src/main/java/com/tianshang/health/navigation/MainNavigation.kt) (App navigation), [`core/database/src/main/java/com/tianshang/health/core/database/TianshangDatabase.kt`](https://github.com/tianshang301/tianshanghealth/blob/main/core/database/src/main/java/com/tianshang/health/core/database/TianshangDatabase.kt) (Encrypted health store), [`feature/analysis/src/main/java/com/tianshang/health/feature/analysis/domain/CrossDimensionEngine.kt`](https://github.com/tianshang301/tianshanghealth/blob/main/feature/analysis/src/main/java/com/tianshang/health/feature/analysis/domain/CrossDimensionEngine.kt) (Health analysis), [`feature/period/src/main/java/com/tianshang/health/feature/period`](https://github.com/tianshang301/tianshanghealth/tree/main/feature/period/src/main/java/com/tianshang/health/feature/period) (Period tracking)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["App and shared UI"]
  node_nav["App navigation<br/>[MainNavigation.kt]"]
  node_shared["Shared UI"]
end

subgraph group_health["Health tracking"]
  node_onboarding["Profile setup"]
  node_period["Period tracking"]
  node_steps["Step tracking"]
  node_fitness["Fitness logging"]
  node_sleep["Sleep tracking"]
  node_nutrition["Nutrition logging"]
  node_watch["Watch companion<br/>[WatchBleService.kt]"]
end

subgraph group_insights["Insights and prediction"]
  node_dashboard["Health dashboard"]
  node_periodengine["Cycle prediction"]
  node_analysis["Health analysis"]
  node_ml["On-device ML<br/>[TFLiteManager.kt]"]
  node_reports["Medical reports"]
end

subgraph group_platform["Local platform"]
  node_database[("Encrypted health store")]
  node_security["Device security<br/>[KeystoreManager.kt]"]
end

node_person(("User"))
node_wearable(("TianshangPulse"))

node_person -->|"opens"| node_nav
node_nav -->|"routes to"| node_onboarding
node_nav -->|"routes to"| node_dashboard
node_nav -->|"routes to"| node_period
node_nav -->|"routes to"| node_steps
node_nav -->|"routes to"| node_fitness
node_nav -->|"routes to"| node_sleep
node_nav -->|"routes to"| node_nutrition
node_nav -->|"routes to"| node_watch
node_nav -->|"routes to"| node_analysis
node_onboarding -.->|"stores profile"| node_database
node_period -->|"stores records"| node_database
node_steps -->|"syncs steps"| node_database
node_fitness -->|"stores workouts"| node_database
node_sleep -->|"stores sleep"| node_database
node_nutrition -->|"stores meals"| node_database
node_watch -->|"reads BLE"| node_wearable
node_watch -->|"persists events"| node_database
node_period -->|"predicts cycles"| node_periodengine
node_periodengine -.->|"uses cycle records"| node_database
node_dashboard -->|"reads health data"| node_database
node_analysis -->|"analyzes records"| node_database
node_analysis -->|"enhances predictions"| node_ml
node_analysis -->|"generates reports"| node_reports
node_security -->|"protects storage"| node_database
node_shared -.->|"supports interface"| node_nav

click node_nav "https://github.com/tianshang301/tianshanghealth/blob/main/app/src/main/java/com/tianshang/health/navigation/MainNavigation.kt"
click node_shared "https://github.com/tianshang301/tianshanghealth/tree/main/core/common/src/main/java/com/tianshang/health/core/common/ui/components"
click node_onboarding "https://github.com/tianshang301/tianshanghealth/tree/main/feature/onboarding/src/main/java/com/tianshang/health/feature/onboarding"
click node_period "https://github.com/tianshang301/tianshanghealth/tree/main/feature/period/src/main/java/com/tianshang/health/feature/period"
click node_steps "https://github.com/tianshang301/tianshanghealth/blob/main/feature/steps/src/main/java/com/tianshang/health/feature/steps/service/StepCounterService.kt"
click node_fitness "https://github.com/tianshang301/tianshanghealth/tree/main/feature/fitness/src/main/java/com/tianshang/health/feature/fitness"
click node_sleep "https://github.com/tianshang301/tianshanghealth/tree/main/feature/sleep/src/main/java/com/tianshang/health/feature/sleep"
click node_nutrition "https://github.com/tianshang301/tianshanghealth/blob/main/feature/nutrition/src/main/java/com/tianshang/health/feature/nutrition/data/repository/NutritionRepository.kt"
click node_watch "https://github.com/tianshang301/tianshanghealth/blob/main/feature/watch/src/main/java/com/tianshang/health/feature/watch/service/WatchBleService.kt"
click node_dashboard "https://github.com/tianshang301/tianshanghealth/tree/main/feature/dashboard/src/main/java/com/tianshang/health/feature/dashboard"
click node_periodengine "https://github.com/tianshang301/tianshanghealth/blob/main/feature/period/src/main/java/com/tianshang/health/feature/period/engine/PredictionEngine.kt"
click node_analysis "https://github.com/tianshang301/tianshanghealth/blob/main/feature/analysis/src/main/java/com/tianshang/health/feature/analysis/domain/CrossDimensionEngine.kt"
click node_ml "https://github.com/tianshang301/tianshanghealth/blob/main/feature/analysis/src/main/java/com/tianshang/health/feature/analysis/ml/TFLiteManager.kt"
click node_reports "https://github.com/tianshang301/tianshanghealth/blob/main/feature/analysis/src/main/java/com/tianshang/health/feature/analysis/domain/report/MedicalReportGenerator.kt"
click node_database "https://github.com/tianshang301/tianshanghealth/blob/main/core/database/src/main/java/com/tianshang/health/core/database/TianshangDatabase.kt"
click node_security "https://github.com/tianshang301/tianshanghealth/blob/main/core/security/src/main/java/com/tianshang/health/core/security/encryption/KeystoreManager.kt"

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_nav,node_shared,node_person toneBlue
class node_onboarding,node_period,node_steps,node_fitness,node_sleep,node_nutrition,node_watch toneAmber
class node_dashboard,node_periodengine,node_analysis,node_ml,node_reports toneMint
class node_database,node_security toneRose
class node_wearable toneIndigo
```

## Components

### App and shared UI

- [App navigation](https://github.com/tianshang301/tianshanghealth/blob/main/app/src/main/java/com/tianshang/health/navigation/MainNavigation.kt): `app/src/main/java/com/tianshang/health/navigation/MainNavigation.kt`
- [Shared UI](https://github.com/tianshang301/tianshanghealth/tree/main/core/common/src/main/java/com/tianshang/health/core/common/ui/components): `core/common/src/main/java/com/tianshang/health/core/common/ui/components`

### Health tracking

- [Profile setup](https://github.com/tianshang301/tianshanghealth/tree/main/feature/onboarding/src/main/java/com/tianshang/health/feature/onboarding): `feature/onboarding/src/main/java/com/tianshang/health/feature/onboarding`
- [Period tracking](https://github.com/tianshang301/tianshanghealth/tree/main/feature/period/src/main/java/com/tianshang/health/feature/period): `feature/period/src/main/java/com/tianshang/health/feature/period`
- [Step tracking](https://github.com/tianshang301/tianshanghealth/blob/main/feature/steps/src/main/java/com/tianshang/health/feature/steps/service/StepCounterService.kt): `feature/steps/src/main/java/com/tianshang/health/feature/steps/service/StepCounterService.kt`
- [Fitness logging](https://github.com/tianshang301/tianshanghealth/tree/main/feature/fitness/src/main/java/com/tianshang/health/feature/fitness): `feature/fitness/src/main/java/com/tianshang/health/feature/fitness`
- [Sleep tracking](https://github.com/tianshang301/tianshanghealth/tree/main/feature/sleep/src/main/java/com/tianshang/health/feature/sleep): `feature/sleep/src/main/java/com/tianshang/health/feature/sleep`
- [Nutrition logging](https://github.com/tianshang301/tianshanghealth/blob/main/feature/nutrition/src/main/java/com/tianshang/health/feature/nutrition/data/repository/NutritionRepository.kt): `feature/nutrition/src/main/java/com/tianshang/health/feature/nutrition/data/repository/NutritionRepository.kt`
- [Watch companion](https://github.com/tianshang301/tianshanghealth/blob/main/feature/watch/src/main/java/com/tianshang/health/feature/watch/service/WatchBleService.kt): `feature/watch/src/main/java/com/tianshang/health/feature/watch/service/WatchBleService.kt`

### Insights and prediction

- [Health dashboard](https://github.com/tianshang301/tianshanghealth/tree/main/feature/dashboard/src/main/java/com/tianshang/health/feature/dashboard): `feature/dashboard/src/main/java/com/tianshang/health/feature/dashboard`
- [Cycle prediction](https://github.com/tianshang301/tianshanghealth/blob/main/feature/period/src/main/java/com/tianshang/health/feature/period/engine/PredictionEngine.kt): `feature/period/src/main/java/com/tianshang/health/feature/period/engine/PredictionEngine.kt`
- [Health analysis](https://github.com/tianshang301/tianshanghealth/blob/main/feature/analysis/src/main/java/com/tianshang/health/feature/analysis/domain/CrossDimensionEngine.kt): `feature/analysis/src/main/java/com/tianshang/health/feature/analysis/domain/CrossDimensionEngine.kt`
- [On-device ML](https://github.com/tianshang301/tianshanghealth/blob/main/feature/analysis/src/main/java/com/tianshang/health/feature/analysis/ml/TFLiteManager.kt): `feature/analysis/src/main/java/com/tianshang/health/feature/analysis/ml/TFLiteManager.kt`
- [Medical reports](https://github.com/tianshang301/tianshanghealth/blob/main/feature/analysis/src/main/java/com/tianshang/health/feature/analysis/domain/report/MedicalReportGenerator.kt): `feature/analysis/src/main/java/com/tianshang/health/feature/analysis/domain/report/MedicalReportGenerator.kt`

### Local platform

- [Encrypted health store](https://github.com/tianshang301/tianshanghealth/blob/main/core/database/src/main/java/com/tianshang/health/core/database/TianshangDatabase.kt): `core/database/src/main/java/com/tianshang/health/core/database/TianshangDatabase.kt`
- [Device security](https://github.com/tianshang301/tianshanghealth/blob/main/core/security/src/main/java/com/tianshang/health/core/security/encryption/KeystoreManager.kt): `core/security/src/main/java/com/tianshang/health/core/security/encryption/KeystoreManager.kt`

### Other components

- **User**
- **TianshangPulse**

## Connections

- User → App navigation: opens (evidence: `README.md`)
- App navigation → Profile setup: routes to (evidence: `README.md`)
- App navigation → Health dashboard: routes to (evidence: `README.md`)
- App navigation → Period tracking: routes to (evidence: `README.md`)
- App navigation → Step tracking: routes to (evidence: `README.md`)
- App navigation → Fitness logging: routes to (evidence: `README.md`)
- App navigation → Sleep tracking: routes to (evidence: `README.md`)
- App navigation → Nutrition logging: routes to (evidence: `README.md`)
- App navigation → Watch companion: routes to (evidence: `README.md`)
- App navigation → Health analysis: routes to (evidence: `README.md`)
- Profile setup → Encrypted health store: stores profile
- Period tracking → Encrypted health store: stores records (evidence: `README.md`)
- Step tracking → Encrypted health store: syncs steps (evidence: `feature/steps/src/main/java/com/tianshang/health/feature/steps/service/StepCounterService.kt`)
- Fitness logging → Encrypted health store: stores workouts (evidence: `README.md`)
- Sleep tracking → Encrypted health store: stores sleep (evidence: `README.md`)
- Nutrition logging → Encrypted health store: stores meals (evidence: `feature/nutrition/src/main/java/com/tianshang/health/feature/nutrition/data/repository/NutritionRepository.kt`)
- Watch companion → TianshangPulse: reads BLE (evidence: `README.md`)
- Watch companion → Encrypted health store: persists events (evidence: `feature/watch/src/main/java/com/tianshang/health/feature/watch/service/WatchBleService.kt`)
- Period tracking → Cycle prediction: predicts cycles (evidence: `README.md`)
- Cycle prediction → Encrypted health store: uses cycle records
- Health dashboard → Encrypted health store: reads health data (evidence: `README.md`)
- Health analysis → Encrypted health store: analyzes records (evidence: `feature/analysis/src/main/java/com/tianshang/health/feature/analysis/domain/CrossDimensionEngine.kt`)
- Health analysis → On-device ML: enhances predictions (evidence: `README.md`)
- Health analysis → Medical reports: generates reports (evidence: `README.md`)
- Device security → Encrypted health store: protects storage (evidence: `README.md`)
- Shared UI → App navigation: supports interface
