Architecture
Designing a Database Schema for Workouts
Workouts are hierarchical. If you mess up the schema early, migrations will kill you.
A workout is not a flat list of exercises. It's a nested hierarchy of routines, supersets, exercises, and sets.
The Relational Approach (PostgreSQL)
You need at least four core tables:
workouts: id, user_id, start_time, end_time, notesworkout_exercises: id, workout_id, exercise_id, order_index, superset_id (nullable)sets: id, workout_exercise_id, set_type (warmup, normal, drop), weight, reps, rpe (rate of perceived exertion)exercises: id, name, muscle_group, equipment_type
Handling Supersets
Supersets are notoriously difficult to model. The simplest approach is a superset_id grouping on the workout_exercises table. If two exercises share the same superset_id within a workout, they are rendered together in the UI.
More Guides
- How much does it cost to build a fitness app in 2024?
- Integrating Apple HealthKit: The Right Way
- Retention: Why your fitness app bleeds users
- ASO for Fitness Apps in 2024
- Monetization: Subscriptions vs. One-Time Purchases
- Building for WatchOS: The Constraints
- AI Coaching: Gimmick or Future?
- Building a Community That Isn't Toxic
- Adding Nutrition: Don't Do It