Skip to content
This repository was archived by the owner on Feb 28, 2026. It is now read-only.

the-governor-hq/Wearabridge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

WearaBridge πŸ₯πŸ“±

Cross-platform mobile health data sync application. WearaBridge connects to Health Connect (Android) and HealthKit (iOS) to automatically sync health data to your backend in the background.

Overview

WearaBridge is a simple Flutter mobile app that:

  • βœ… Auto-generates unique device ID on first launch
  • βœ… Syncs health data automatically every 30 minutes (no login required)
  • βœ… Shows 5-digit pairing code that refreshes every 30 seconds
  • βœ… Users claim devices via web dashboard using the code
  • βœ… Works with any backend - see API_REQUIREMENTS.md

Quick Start

  1. Configure backend URL in lib/core/config/app_config.dart:

    static const String apiBaseUrl = 'https://your-backend.com';
  2. Backend Integration - Share API_REQUIREMENTS.md with your backend team

  3. Install dependencies:

    flutter pub get
  4. Run:

    flutter run

How Pairing Works

  1. App generates unique device ID (UUID) on first launch
  2. App starts syncing health data immediately with device IDin header
  3. User opens pairing screen, app requests 5-digit code from backend
  4. Backend generates code (valid 30 seconds) linked to device ID
  5. User enters code in web dashboard to claim device
  6. Backend associates device ID with user account
  7. Historical data now visible under user's account

Architecture

wearabridge/
β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ main.dart                          # App entry point
β”‚   β”œβ”€β”€ core/
β”‚   β”‚   β”œβ”€β”€ config/app_config.dart        # API endpoints & configuration
β”‚   β”‚   β”œβ”€β”€ constants/health_data_types.dart
β”‚   β”‚   └── network/api_client.dart       # HTTP client with auth
β”‚   β”œβ”€β”€ data/
β”‚   β”‚   β”œβ”€β”€ datasources/
β”‚   β”‚   β”‚   β”œβ”€β”€ health_datasource.dart    # Health Connect/HealthKit wrapper
β”‚   β”‚   β”‚   └── api_datasource.dart       # Backend API calls
β”‚   β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”‚   └── health_data_point.dart    # Data models
β”‚   β”‚   └── repositories/
β”‚   β”‚       └── health_repository.dart    # Business logic layer
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”œβ”€β”€ background_sync_service.dart  # WorkManager background tasks
β”‚   β”‚   └── auth_service.dart             # Authentication
β”‚   └── presentation/
β”‚       β”œβ”€β”€ screens/                      # UI screens
β”‚       β”œβ”€β”€ widgets/                      # Reusable widgets
β”‚       └── providers/                    # Riverpod state management

Health Data Types Supported

  • Steps - Daily step count
  • Heart Rate - Continuous heart rate measurements
  • Sleep - Sleep sessions with quality data
  • Workouts - Exercise activities
  • Distance - Distance traveled
  • Active Calories - Calories burned during activity
  • Blood Oxygen - SpO2 readings
  • Resting Heart Rate - RHR measurements

Setup

Prerequisites

  • Flutter SDK 3.9.2+
  • Android Studio (for Android development)
  • Xcode (for iOS development)

Installation

  1. Install dependencies:

    cd wearabridge
    flutter pub get
  2. Configure backend URL: Edit lib/core/config/app_config.dart:

    static const String apiBaseUrl = 'https://your-backend.com'; // CHANGE THIS
  3. Backend Setup:

    • Share API_REQUIREMENTS.md with your backend team
    • Backend needs to implement 4 endpoints (see API_REQUIREMENTS.md)
    • No authentication on mobile app side - device ID only
  4. Android Setup:

    • Health Connect requires Android 14+ or the Health Connect APK
    • Permissions configured in AndroidManifest.xml
  5. iOS Setup:

    • HealthKit permissions configured in Info.plist
    • Requires iOS 13.0+
  6. Run:

    flutter run

Background Sync

The app uses WorkManager to schedule periodic background syncs:

  • Frequency: Every 30 minutes (configurable)
  • Constraints: Requires network connection, battery not low
  • Retry Policy: Exponential backoff on failure
  • Data: Syncs data since last successful sync (up to 7 days lookback)

How it Works

  1. App registers periodic background task on login
  2. Task wakes up every 30 minutes
  3. Fetches new health data from Health Connect/HealthKit
  4. Batches data and sends POST request to /v1/health/sync
  5. Updates last sync timestamp
  6. Retries on failure with exponential backoff

API Integration

Backend Endpoint

The app syncs to: POST /v1/health/sync

Request Body:

{
  "userId": "user_123",
  "deviceType": "android",
  "syncedAt": "2026-02-26T10:30:00Z",
  "lastSyncTime": "2026-02-26T10:00:00Z",
  "data": [
    {
      "type": "STEPS",
      "value": "1250",
      "unit": "count",
      "dateFrom": "2026-02-26T10:00:00Z",
      "dateTo": "2026-02-26T10:30:00Z",
      "sourcePlatform": "HEALTH_CONNECT",
      "sourceDevice": "Pixel 8",
      "metadata": {}
    }
  ]
}

Response (201):

{
  "success": true,
  "stored": 1,
  "syncedAt": "2026-02-26T10:30:00Z"
}

Screens

1. Splash Screen

  • Auto-navigates to Login or Home based on auth state

2. Login Screen

  • Email/password authentication
  • Connects to existing bodypress-backend auth system

3. Home Screen (Dashboard)

  • Shows sync status and last sync time
  • Displays today's stats (steps, heart rate, sleep)
  • Pull-to-refresh for manual sync
  • Requests permissions if not granted

4. Settings Screen

  • Manage sync frequency
  • Toggle background sync on/off
  • View/request health permissions
  • Logout

Security

  • πŸ” Auth tokens stored in flutter_secure_storage
  • πŸ”’ API calls authenticated with Bearer token
  • ⚠️ Health data never stored locally except in platform's secure health storage
  • 🌐 HTTPS required for all API communication
  • 🚫 No third-party analytics or tracking

Platform Requirements

Android

  • Minimum SDK: 26 (Android 8.0)
  • Target SDK: 34 (Android 14)
  • Health Connect installed (built-in on Android 14+)
  • Permissions declared in AndroidManifest.xml

iOS

  • Minimum: iOS 13.0
  • HealthKit capability enabled
  • Privacy strings in Info.plist
  • Background modes: fetch, processing

Development

Running in Debug Mode

flutter run --debug

Building for Release

Android:

flutter build apk --release
# or
flutter build appbundle --release

iOS:

flutter build ios --release

Code Generation

For Freezed models and Riverpod providers:

flutter pub run build_runner build --delete-conflicting-outputs

Testing

Unit Tests

flutter test

Integration Tests

flutter test integration_test

Deployment

Android (Play Store)

  • Requires Health Connect certification from Google
  • Submit app for review with health permissions usage explanation

iOS (App Store)

  • Requires clear explanation of HealthKit usage in App Review
  • Privacy policy mandatory

Configuration Options

Edit lib/core/config/app_config.dart:

// Sync every 15 minutes instead of 30
static const Duration syncInterval = Duration(minutes: 15);

// Change batch size
static const int batchSize = 50;

// Adjust retry attempts
static const int maxRetries = 5;

Troubleshooting

Android: Health Connect not found

  • Install Health Connect from Play Store
  • Or use Android 14+ which has it built-in

iOS: Permissions not showing

  • Check Info.plist has NSHealthShareUsageDescription
  • Rebuild the app after adding permissions

Background sync not working

  • Check battery optimization settings
  • Ensure network connectivity
  • View logs: flutter logs

API authentication failing

  • Verify backend is running
  • Check API endpoint in app_config.dart
  • Ensure user is logged in

Future Enhancements

  • Selective data type sync
  • Sync frequency customization in UI
  • Offline data visualization
  • Export health data
  • Multi-account support
  • Dark/light theme toggle

Tech Stack

  • Framework: Flutter 3.9.2+
  • Language: Dart
  • State Management: Riverpod
  • HTTP Client: Dio
  • Health Data: health package
  • Background Tasks: workmanager
  • Local Storage: flutter_secure_storage, shared_preferences
  • Database (Backend): PostgreSQL + Prisma

Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open Pull Request

License

MIT

A

About

Wearabridge is a Flutter companion app that syncs wearable/health data from HealthKit and Health Connect to your backend via a stable, vendor-independent ingest API.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors