Running Days Docs
GitHub

Business Logic

The @running-days/business-logic package contains pure functions for all core calculations. It has no I/O, no database access - just algorithms and transformations.

Philosophy

All business logic is:

  • Pure: Same inputs always produce same outputs
  • Testable: No external dependencies to mock
  • Portable: Can run in Node.js, browser, or edge runtime

Modules

ModuleDescription
Workout ProcessorParse, validate, and aggregate workout data
Streak CalculatorCalculate current, longest, and historical streaks
Achievement ServiceMilestone detection and progress tracking

Installation

bash
pnpm add @running-days/business-logic

Usage

typescript
import {
  processWorkout,
  calculateStreaks,
  detectNewMilestones
} from '@running-days/business-logic';

// Process a raw workout from HealthKit
const workout = processWorkout(rawWorkout);

// Calculate streaks from daily stats
const streaks = calculateStreaks(dailyStats);

// Check for new achievement milestones
const newMilestones = detectNewMilestones(previousDays, currentDays);

Type Safety

All functions are fully typed. Import types from @running-days/types:

typescript
import type { Workout, DailyStats, Goal } from '@running-days/types';

Testing

The package has comprehensive unit tests:

bash
pnpm --filter @running-days/business-logic test

Tests cover:

  • Edge cases (timezone boundaries, leap years)
  • Invalid input handling
  • Performance with large datasets