Module Overview
Architecture Diagram
Modules
API Module
The API module handles all communication with the Strava API. Key Components:StravaAPIClient(API/StravaAPIClient.swift:3): Actor-based API client for thread-safe requestsTokenManager(API/): Manages OAuth token storage and retrievalStravaConfiguration: Reads client credentials from Info.plist
- OAuth 2.0 authorization code exchange
- Automatic token refresh with race condition prevention
- Paginated activity fetching with type filtering
- Exponential backoff retry logic for failed requests
- Rate limit and error handling
Models Module
The Models module defines all data structures used throughout the library. Core Models:StravaActivity(Models/StravaActivity.swift:3): Represents a single Strava activity with distance, time, elevation, and metadataStravaToken(Models/): OAuth token with expiration trackingHeatmapDay(Models/HeatmapDay.swift:3): Aggregated activity data for a single dayHeatmapViewModel(Models/): Complete heatmap data with weeks, cells, and totalsActivityInsights(Models/): Comprehensive statistics and insightsActivityType(Models/): Enumeration of supported activity types (Run, Ride, Swim, etc.)
- All models are
Codablefor JSON serialization - All models are
Sendablefor safe concurrency - Models use snake_case to camelCase mapping for Strava API compatibility
Heatmap Module
The Heatmap module transforms activity data into GitHub-style contribution heatmaps. Key Components:HeatmapBuilder(Heatmap/HeatmapBuilder.swift:3): Static methods for generating heatmap viewsHeatmapColors(Heatmap/): Color scheme definitions for intensity levelsMonthLabelBuilder(Heatmap/): Generates month labels for heatmap headers
- Builds heatmap grids aligned to week boundaries (Heatmap/HeatmapBuilder.swift:34)
- Calculates intensity levels (0-4) based on maximum daily mileage (Heatmap/HeatmapBuilder.swift:28)
- Computes total mileage across the heatmap period
- Generates day-of-week labels
Stats Module
The Stats module computes comprehensive training insights from raw activity data. Key Components:ActivityInsightsBuilder(Stats/ActivityInsightsBuilder.swift:3): Main builder for computing all statistics
- Streaks: Current streak and longest streak (Stats/ActivityInsightsBuilder.swift:293)
- Weekly Volumes: Mileage and active days per week (Stats/ActivityInsightsBuilder.swift:174)
- Training Rhythm: Activity count by day of week and hour of day (Stats/ActivityInsightsBuilder.swift:254)
- Activity Type Breakdown: Distribution across Run, Ride, Swim, etc. (Stats/ActivityInsightsBuilder.swift:272)
- Peak Days: Top days by mileage and activity count (Stats/ActivityInsightsBuilder.swift:198)
- Peak Activities: Longest individual activities (Stats/ActivityInsightsBuilder.swift:223)
- Pace Trends: Pace over time for activities > 500m (Stats/ActivityInsightsBuilder.swift:367)
- Effort Analysis: Weekly suffer scores and trends (Stats/ActivityInsightsBuilder.swift:396)
build(): Full insights with all raw activity data (Stats/ActivityInsightsBuilder.swift:7)buildPartial(): Limited insights from cached heatmap data only (Stats/ActivityInsightsBuilder.swift:100)
Storage Module
The Storage module handles persistence and caching. Key Components:ActivityCache(Storage/ActivityCache.swift:3): Actor-based cache for activity dataTokenManager: Keychain-based token storage
- Stores activity data in App Group shared container for widget access
- Supports multiple cache buckets keyed by activity type selection
- Automatic freshness checking based on fetch timestamp (Storage/ActivityCache.swift:17)
- Atomic writes to prevent corruption
- Thread-safe access via Swift actors
Data Flow
1. Authentication Flow
2. Activity Fetch and Cache Flow
3. Heatmap Generation Flow
4. Insights Computation Flow
Concurrency Model
StratilesCore leverages Swift’s structured concurrency:- Actors:
StravaAPIClient,TokenManager, andActivityCacheare actors, ensuring thread-safe access to shared state - Async/Await: All API calls and I/O operations use async/await for clean error handling
- Task Deduplication: Token refresh uses a shared task to prevent multiple simultaneous refresh requests (API/StravaAPIClient.swift:48)
- Sendable Types: All data models conform to
Sendablefor safe transfer across concurrency boundaries
Next Steps
API Module
Explore the Strava API client
Models
View data structure definitions
Heatmap
Learn about heatmap generation
Stats
Understand activity insights