Skip to content

deancochran/turbo-fit

Repository files navigation

TurboFit πŸƒβ€β™‚οΈ

A sophisticated, enterprise-grade fitness tracking platform built with modern local-first architecture. TurboFit delivers seamless offline-first experiences with intelligent cloud synchronization, real-time analytics, and cross-platform consistency.


πŸ—οΈ Architecture Overview

TurboFit is organized as a Turborepo monorepo with modular packages:

πŸ“¦ Core Package (packages/core)

The heart of TurboFit, shared across web, mobile, and backend apps. Completely independent of database or ORM dependencies.

Responsibilities:

  • Type Definitions & Schemas β€” Zod validation for profiles, activities, activities, and flexible JSON structures
  • Calculations & Analytics β€” Training zones, TSS, normalized power, compliance scoring, CTL/ATL/TSB
  • Business Logic β€” Activity plan validation, progression, and adaptive algorithms
  • Utilities β€” Time/duration helpers, unit conversions, constants
  • Platform Agnostic β€” Pure TypeScript with no database, ORM, or platform-specific dependencies

Key Benefit: Single source of truth ensures consistent calculations, type safety, and validation across all applications while remaining completely portable and testable in isolation.


πŸ“¦ Drizzle Backend Package (packages/drizzle)

A centralized backend layer providing type-safe database interactions.

Responsibilities:

  • Schema Definition β€” Table structures and relations managed via Drizzle
  • Migrations β€” Database versioning and schema updates fully controlled
  • Queries & Transactions β€” Type-safe interactions with PostgreSQL
  • Integration β€” Powers both web and mobile apps with a single database interface

Key Benefit: Decouples applications from direct database dependencies while providing type-safe data operations.


πŸ“¦ TypeScript Config Package (packages/typescript-config)

A shared TypeScript configuration used across all apps and packages in the TurboFit monorepo.

Responsibilities:

  • Centralized TS Configuration β€” Base tsconfig defines compiler options, strict type checking, and module resolution
  • Standardized Paths & Aliases β€” Ensures consistent @/* imports across apps
  • Extensible per App β€” Apps can extend the base config for Next.js, Expo, or library-specific overrides
  • Version Control β€” Single source of truth for TypeScript settings to reduce discrepancies and errors

Key Benefit: All apps and packages share a consistent TypeScript environment, simplifying cross-package type safety and refactoring.


πŸ“¦ ESLint Config Package (packages/eslint-config)

A shared ESLint configuration used across all apps and packages in the TurboFit monorepo.

Responsibilities:

  • Centralized Linting Rules β€” Base ESLint rules and plugins (@eslint/js, typescript-eslint, eslint-config-prettier) applied across all apps
  • Next.js & React Support β€” Optional per-app overrides for Next.js or React library requirements
  • Custom Plugins β€” Turbo-specific rules, eslint-plugin-only-warn, and other shared rules enforced consistently
  • Ignored Paths β€” Standard exclusions for dist, .next, and build artifacts

Key Benefit: Provides uniform code quality standards across all apps and packages, making maintenance and onboarding simpler.


πŸ“± Mobile App (apps/mobile)

  • Expo + React Native
  • Local-first storage with SQLite for offline recording
  • Powered by @turbofit/core for validation and calculations (database-independent)
  • Cloud sync handled via API endpoints

🌐 Web Dashboard (apps/web)

  • Next.js + React
  • Real-time analytics and dashboards
  • Powered by @turbofit/core for calculations and validation
  • Database access via Drizzle-powered API endpoints

πŸ”— Shared Infrastructure

  • Turborepo + TypeScript throughout
  • Core package for shared business logic (database-independent)
  • Drizzle package for centralized database operations
  • Local-first recording + intelligent sync ensures offline usability and data integrity

πŸ§‘β€πŸ’» Profiles & Preferences

User-centric design anchors the system around profiles extended from auth.users. The core package provides enhanced profile interfaces and validation schemas for athlete-specific metrics:

Field Description
id Primary key, UUID, FK β†’ auth.users.id
threshold_hr Threshold heart rate (bpm); nullable for new users
ftp Functional Threshold Power (watts); nullable
weight_kg Athlete's weight for power-to-weight calculations
gender Used in predictive models and analytics
dob Date of birth; calculates age-based zones & targets
username Unique public-facing handle
language Preferred UI language/locale
preferred_units Metric vs imperial
avatar_url Optional profile picture/avatar
bio Optional short biography

The core package handles profile validation, training zone calculations, and unit conversions for personalized experiences.


πŸ“‹ Training Plans & Planned Activities

Profile Plans

profile_plans stores personalized training plans generated from library templates. The core package provides plan validation, progression algorithms, and adaptation logic.

Planned Activities

planned_activities contains scheduled activities with flexible JSON structures validated by the core package:

  • structure β€” Complex JSON objects defining activity steps
  • structure_version β€” Version tracked by core package
  • requires_threshold_hr / requires_ftp β€” Validated against core profile requirements
  • Performance estimates calculated by core algorithms

Activity Structure Features:

  • Nested repetitions and complex step sequences
  • Multiple intensity target types with validation
  • Duration units (time, distance, repetition)
  • Intensity classes with core classification logic
  • Portable format compatible with major training platforms

The core package ensures valid activity structures, calculates estimated durations and training stress, and provides compliance scoring algorithms.


πŸƒ Activity Storage & Performance Analysis

JSON-First Activity Architecture

TurboFit uses a JSON-first approach where all activity data is stored as the single source of truth:

  • Primary Storage β€” Complete activity data stored as JSON in Supabase Storage
  • Local Recording β€” Activities initially captured locally in SQLite as JSON
  • Cloud Sync β€” JSON objects uploaded to Supabase Storage when network available
  • Metadata Generation β€” Activity records created locally and synced after JSON storage
  • Stream Processing β€” Activity streams generated from JSON after successful upload

Data Flow:

  1. Record β†’ Local SQLite stores complete activity as JSON
  2. Upload β†’ JSON object uploaded to Supabase Storage (source of truth)
  3. Process β†’ Activity metadata record generated locally and inserted
  4. Streams β†’ Activity streams generated and inserted after JSON processing
  5. Analytics β€” Core package processes JSON for performance calculations

Performance Analysis

Activity data flows through the core package for consistent analysis:

  • Performance Metrics β€” TSS, normalized power, intensity factors calculated from JSON
  • Training Load Analytics β€” CTL, ATL, TSB derived from activity metadata
  • Compliance Scoring β€” Activity matching algorithms using JSON activity structure
  • Zone Analysis β€” Training zone calculations using core package algorithms

Activity Streams

Time-series data processed from JSON source through core package utilities:

  • Generated from JSON β€” All streams derived from primary JSON activity data
  • Standardized Metrics β€” Core package ensures consistent metric types and validation
  • Performance Curves β€” Power/HR curves calculated from JSON streams
  • Real-time Processing β€” Stream aggregation during activity recording

πŸ”„ Local-First Architecture

  • Record Locally β€” Expo-SQLite captures complete activities as JSON with core package validation
  • JSON Source of Truth β€” All activity data stored primarily as JSON objects
  • Background Sync β€” Core package ensures data integrity during upload process
  • Metadata Derivation β€” Activity records and streams generated from JSON post-upload
  • Conflict Resolution β€” Smart merging using JSON timestamps and core validation

✨ Key Features

πŸ”„ Shared Business Logic via Core Package

  • Database Independent β€” Core package has zero database dependencies
  • Consistent Calculations β€” Same algorithms across platforms
  • Unified Validation β€” JSON schema validation using Zod
  • Type Safety β€” Full TypeScript support without ORM coupling
  • Client-side Performance β€” Instant calculations without API calls

πŸ“Š Advanced Analytics

  • JSON-Derived Metrics β€” All analytics calculated from JSON source data
  • Training Load Models β€” CTL/ATL/TSB from activity metadata
  • Performance Analytics β€” Power curves, trends from JSON streams
  • Compliance Tracking β€” Plan adherence using JSON activity structures
  • Zone Analysis β€” Heart rate and power zones from core calculations

πŸ” Enterprise Security

  • Validated Data Integrity β€” Core package schemas ensure data quality
  • Row Level Security β€” Database-level access control
  • Encrypted Storage β€” Secure local and cloud storage
  • Audit Logging β€” Complete activity history preservation

πŸš€ Developer Experience

  • Independent Core Package β€” Pure TypeScript, fully testable in isolation
  • End-to-end Type Safety β€” From JSON validation to UI components
  • Hot Reloading β€” Fast development iteration
  • Consistent Behavior β€” Same business logic across all platforms

πŸ› οΈ Tech Stack

Layer Mobile Web Shared
Business Logic @turbofit/core @turbofit/core Core Package
Frontend Expo 53, React Native Next.js 15, React 19 -
Local Storage Expo-SQLite (SQLite) - -
Cloud Storage Supabase Storage Supabase Storage JSON Files
Cloud Database API β†’ Drizzle API β†’ Drizzle PostgreSQL
Styling NativeWind 4.1 Tailwind CSS -
State SQLite + React Query React Query + Zustand -

πŸ“– Development Guide

Project Structure

turbofit/
β”œβ”€β”€ apps/
β”‚   β”œβ”€β”€ mobile/          # Mobile app (Expo + React Native)
β”‚   └── web/             # Web dashboard (Next.js)
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ core/            # 🌟 Database-independent business logic, types, calculations
β”‚   β”œβ”€β”€ drizzle/         # Database schema, migrations, queries

Core Package Structure

packages/core/
β”œβ”€β”€ types/               # Platform-agnostic types and interfaces
β”œβ”€β”€ schemas/             # Zod validation schemas for JSON data
β”œβ”€β”€ calculations/        # Performance and training calculations
β”œβ”€β”€ validators/          # Data validation utilities
└── utils/               # Shared utilities and constants

Common Commands

Root level:

bun dev      # Start all development servers
bun build    # Build all applications including core package
bun lint     # Lint all code
bun test     # Run all tests including core package tests

Core package development:

cd packages/core
bun build    # Build core package
bun test     # Test core package (no database dependencies)
bun dev      # Watch mode for core package development

πŸ” Authentication Flow

  1. Supabase authentication with JWT tokens
  2. Profile enhancement using core package type extensions
  3. Data validation through core package schemas
  4. Secure sync with core package integrity checks

πŸ“± Mobile & 🌐 Web Dashboard Features

  • JSON-First Storage β€” Single source of truth for all activity data
  • Real-time Validation β€” Core package schemas ensure data quality
  • Client-side Analytics β€” Performance calculations without server dependencies
  • Consistent Training Zones β€” Core package algorithms across platforms
  • Intelligent Offline-first Sync β€” JSON-based conflict resolution

πŸ§ͺ Testing Strategy

Core Package Testing:

  • Algorithm Validation β€” Mathematical correctness of calculations
  • Schema Testing β€” JSON validation and type safety
  • Pure Function Testing β€” No database mocking required
  • Cross-platform Consistency β€” Same results across mobile and web

Application Testing:

  • Integration Tests β€” JSON storage and retrieval workflows
  • E2E User Journeys β€” Complete activity recording and analysis flows
  • Performance Tests β€” Large JSON processing and analytics

πŸš€ Deployment

Mobile App (Expo/EAS):

# Production builds
eas build --platform all --profile production

# Over-the-air updates
eas update --branch production --message "Feature update"

Web Dashboard (Vercel):

# Automatic deployment on push to main
git push origin main

# Manual deployment
vercel --prod

🀝 Contributing

  • Fork the repository and create a feature branch
  • Make your changes with tests and documentation
  • Run quality checks: bun lint && bun test
  • Submit a pull request with clear description

πŸ“„ Documentation


πŸ“ License

This project is licensed under the MIT License.


πŸ™ Acknowledgments

Built with modern tools and technologies:

  • Expo β€” Cross-platform mobile development
  • Next.js β€” React web framework
  • Supabase β€” Backend-as-a-service
  • Turborepo β€” Monorepo build system

TurboFit β€” Enterprise-grade fitness tracking with JSON-first, local-first architecture πŸš€

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages