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, notes
  • workout_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.