Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

feat: add additional starter plan definitions

Luke M89fdd1b787ba
diff --git a/frontend/src/lib/starter.js b/frontend/src/lib/starter.js
index 33d38b837..e8ba7041a 100644
--- a/frontend/src/lib/starter.js
+++ b/frontend/src/lib/starter.js
@@ -1,13 +1,68 @@
-// The Push/Pull/Legs starter plan. Shared by the "Load starter plan" action in Settings
-// and by the demo build, which seeds a history on top of exactly these routines.
+// The starter-plan catalog. Training data only: the chooser's plan names and descriptions are
+// written as string literals inside t() calls in sheets.jsx, because check-source-strings.mjs
+// only finds them there — copy parked in here would silently ship English in every language.
+//
+// A routine is [key, name, emoji, [[exerciseId, sets, reps], …]]. The key is what a plan's
+// schedule points at, so a weekday never depends on the position of a routine in the array.
+// Names stay canonical English — they become ordinary user routines, which are not translated.
import { uid } from './format.js'
-const SPEC = [
- ['Push Day', 'barbell', [['0025', 4, 8], ['0047', 3, 10], ['0426', 3, 10], ['0334', 3, 12], ['0241', 3, 12], ['0251', 3, 10]]],
- ['Pull Day', 'pullup', [['2330', 4, 10], ['0027', 4, 8], ['1323', 3, 10], ['0031', 3, 10], ['0313', 3, 12]]],
- ['Leg Day', 'legs', [['0043', 4, 8], ['0085', 3, 10], ['0739', 3, 12], ['0585', 3, 12], ['0586', 3, 12], ['0605', 4, 15]]]
+const PPL = [
+ ['push', 'Push Day', 'barbell', [['0025', 4, 8], ['0047', 3, 10], ['0426', 3, 10], ['0334', 3, 12], ['0241', 3, 12], ['0251', 3, 10]]],
+ ['pull', 'Pull Day', 'pullup', [['2330', 4, 10], ['0027', 4, 8], ['1323', 3, 10], ['0031', 3, 10], ['0313', 3, 12]]],
+ ['legs', 'Leg Day', 'legs', [['0043', 4, 8], ['0085', 3, 10], ['0739', 3, 12], ['0585', 3, 12], ['0586', 3, 12], ['0605', 4, 15]]]
]
-// Fresh routine objects (new ids) — [push, pull, legs].
-export const starterRoutines = () =>
- SPEC.map(([name, emoji, list]) => ({ id: uid(), name, emoji, ex: list.map(([id, sets, reps]) => ({ id, sets, reps, weight: 0 })) }))
+const UPPER_LOWER = [
+ ['upper-a', 'Upper A', 'barbell', [['0025', 3, 8], ['2330', 3, 10], ['0047', 2, 10], ['1323', 2, 10], ['0334', 2, 12], ['0241', 2, 12], ['0031', 2, 12]]],
+ ['lower-a', 'Lower A', 'legs', [['0043', 3, 8], ['0085', 3, 8], ['0739', 2, 10], ['0586', 2, 12], ['0605', 3, 15]]],
+ ['upper-b', 'Upper B', 'barbell', [['0047', 3, 8], ['0027', 3, 8], ['0426', 2, 10], ['2330', 2, 10], ['0334', 2, 12], ['0241', 2, 12], ['0313', 2, 12]]],
+ ['lower-b', 'Lower B', 'legs', [['0739', 3, 10], ['0085', 2, 10], ['0585', 2, 12], ['0586', 3, 12], ['0605', 3, 15]]]
+]
+
+const FULL_BODY = [
+ ['fb-a', 'Full Body A', 'figureStrength', [['0043', 3, 8], ['0025', 3, 8], ['2330', 3, 10], ['0586', 3, 12], ['0334', 2, 12], ['0031', 2, 12]]],
+ ['fb-b', 'Full Body B', 'figureStrength', [['0085', 3, 8], ['0047', 3, 10], ['1323', 3, 10], ['0585', 3, 12], ['0334', 2, 12], ['0241', 2, 12]]],
+ ['fb-c', 'Full Body C', 'figureStrength', [['0739', 3, 10], ['0025', 2, 10], ['0027', 3, 10], ['0426', 2, 10], ['0586', 3, 12], ['0605', 3, 15]]]
+]
+
+const FIVE_BY_FIVE = [
+ ['5x5-a', '5×5 A', 'barbell', [['0043', 5, 5], ['0025', 5, 5], ['0027', 5, 5]]],
+ ['5x5-b', '5×5 B', 'barbell', [['0085', 5, 5], ['0426', 5, 5], ['2330', 5, 5]]],
+ ['5x5-c', '5×5 C', 'barbell', [['0739', 5, 5], ['0047', 5, 5], ['1323', 5, 5]]]
+]
+
+// [weekday, routineKey] — weekday is a DAYN index, so 1 is Monday. Fixed weeks only: every
+// plan repeats the same seven days, which is all the weekly plan model can represent.
+const PLANS = {
+ ppl: { routines: PPL, schedule: [[1, 'push'], [3, 'pull'], [5, 'legs']] },
+ 'upper-lower': { routines: UPPER_LOWER, schedule: [[1, 'upper-a'], [2, 'lower-a'], [4, 'upper-b'], [5, 'lower-b']] },
+ 'full-body': { routines: FULL_BODY, schedule: [[1, 'fb-a'], [3, 'fb-b'], [5, 'fb-c']] },
+ '5x5': { routines: FIVE_BY_FIVE, schedule: [[1, '5x5-a'], [3, '5x5-b'], [5, '5x5-c']] }
+}
+
+const build = routines =>
+ routines.map(([, name, emoji, list]) => ({ id: uid(), name, emoji, ex: list.map(([id, sets, reps]) => ({ id, sets, reps, weight: 0 })) }))
+
+// Fresh routine objects (new ids) — [push, pull, legs]. The demo build seeds a history on
+// top of exactly these three, so this entry point keeps its shape.
+export const starterRoutines = () => build(PPL)
+
+// [{ id, days }] for the chooser. The day count is read off the schedule rather than stored
+// beside it, so the two can never disagree.
+export const starterPlanOptions = () =>
+ Object.entries(PLANS).map(([id, { schedule }]) => ({ id, days: schedule.length }))
+
+// The weekdays a plan would claim, or null for an unknown id.
+export const starterPlanDays = id => PLANS[id]?.schedule.map(([day]) => day) ?? null
+
+// Fresh routines plus the weekdays to put them on, or null for an unknown id — a caller that
+// treats null as "change nothing" can never half-apply a plan.
+export const buildStarterPlan = id => {
+ const plan = PLANS[id]
+ if (!plan) return null
+ const routines = build(plan.routines)
+ // key → the id just minted for it, so the schedule below names its routine
+ const byKey = Object.fromEntries(plan.routines.map(([key], i) => [key, routines[i].id]))
+ return { routines, schedule: plan.schedule.map(([day, key]) => ({ day, routineId: byKey[key] })) }
+}
diff --git a/frontend/src/lib/starter.test.js b/frontend/src/lib/starter.test.js
new file mode 100644
index 000000000..804c021f3
--- /dev/null
+++ b/frontend/src/lib/starter.test.js
@@ -0,0 +1,104 @@
+import { describe, expect, it } from 'vitest'
+import { EXIDX } from './exercises.js'
+import { buildStarterPlan, starterPlanDays, starterPlanOptions, starterRoutines } from './starter.js'
+
+// The approved prescription, written out again rather than imported: a test that reads the
+// same table as the code would pass no matter what that table said. [weekday, name, sets].
+const APPROVED = {
+ ppl: [
+ [1, 'Push Day', [['0025', 4, 8], ['0047', 3, 10], ['0426', 3, 10], ['0334', 3, 12], ['0241', 3, 12], ['0251', 3, 10]]],
+ [3, 'Pull Day', [['2330', 4, 10], ['0027', 4, 8], ['1323', 3, 10], ['0031', 3, 10], ['0313', 3, 12]]],
+ [5, 'Leg Day', [['0043', 4, 8], ['0085', 3, 10], ['0739', 3, 12], ['0585', 3, 12], ['0586', 3, 12], ['0605', 4, 15]]],
+ ],
+ 'upper-lower': [
+ [1, 'Upper A', [['0025', 3, 8], ['2330', 3, 10], ['0047', 2, 10], ['1323', 2, 10], ['0334', 2, 12], ['0241', 2, 12], ['0031', 2, 12]]],
+ [2, 'Lower A', [['0043', 3, 8], ['0085', 3, 8], ['0739', 2, 10], ['0586', 2, 12], ['0605', 3, 15]]],
+ [4, 'Upper B', [['0047', 3, 8], ['0027', 3, 8], ['0426', 2, 10], ['2330', 2, 10], ['0334', 2, 12], ['0241', 2, 12], ['0313', 2, 12]]],
+ [5, 'Lower B', [['0739', 3, 10], ['0085', 2, 10], ['0585', 2, 12], ['0586', 3, 12], ['0605', 3, 15]]],
+ ],
+ 'full-body': [
+ [1, 'Full Body A', [['0043', 3, 8], ['0025', 3, 8], ['2330', 3, 10], ['0586', 3, 12], ['0334', 2, 12], ['0031', 2, 12]]],
+ [3, 'Full Body B', [['0085', 3, 8], ['0047', 3, 10], ['1323', 3, 10], ['0585', 3, 12], ['0334', 2, 12], ['0241', 2, 12]]],
+ [5, 'Full Body C', [['0739', 3, 10], ['0025', 2, 10], ['0027', 3, 10], ['0426', 2, 10], ['0586', 3, 12], ['0605', 3, 15]]],
+ ],
+ '5x5': [
+ [1, '5×5 A', [['0043', 5, 5], ['0025', 5, 5], ['0027', 5, 5]]],
+ [3, '5×5 B', [['0085', 5, 5], ['0426', 5, 5], ['2330', 5, 5]]],
+ [5, '5×5 C', [['0739', 5, 5], ['0047', 5, 5], ['1323', 5, 5]]],
+ ],
+}
+
+const shape = r => r.ex.map(e => [e.id, e.sets, e.reps])
+
+describe('starter plan catalog', () => {
+ it('offers exactly the four plans, with the day count read off the schedule', () => {
+ expect(starterPlanOptions()).toEqual([
+ { id: 'ppl', days: 3 }, { id: 'upper-lower', days: 4 },
+ { id: 'full-body', days: 3 }, { id: '5x5', days: 3 },
+ ])
+ for (const { id, days } of starterPlanOptions()) expect(starterPlanDays(id)).toHaveLength(days)
+ })
+
+ it('changes nothing for an unknown plan id', () => {
+ expect(buildStarterPlan('nope')).toBeNull()
+ expect(buildStarterPlan(undefined)).toBeNull()
+ // A click handler wired straight to a loader would hand the event in as the plan.
+ expect(buildStarterPlan({ type: 'click' })).toBeNull()
+ expect(starterPlanDays('nope')).toBeNull()
+ })
+})
+
+describe.each(Object.keys(APPROVED))('%s', planId => {
+ const approved = APPROVED[planId]
+
+ it('builds the approved exercises, sets and reps in order', () => {
+ const { routines } = buildStarterPlan(planId)
+ expect(routines.map(r => r.name)).toEqual(approved.map(([, name]) => name))
+ routines.forEach((r, i) => expect(shape(r)).toEqual(approved[i][2]))
+ })
+
+ it('puts each routine on its approved weekday, by identity not position', () => {
+ const { routines, schedule } = buildStarterPlan(planId)
+ const nameOf = Object.fromEntries(routines.map(r => [r.id, r.name]))
+ expect(schedule.map(({ day, routineId }) => [day, nameOf[routineId]]))
+ .toEqual(approved.map(([day, name]) => [day, name]))
+ })
+
+ it('references only real exercises and starts every one at weight 0', () => {
+ for (const r of buildStarterPlan(planId).routines) {
+ for (const e of r.ex) {
+ expect(EXIDX[e.id], e.id).toBeTruthy()
+ expect(e.sets).toBeGreaterThan(0)
+ expect(e.reps).toBeGreaterThan(0)
+ expect(e.weight).toBe(0)
+ }
+ }
+ })
+
+ it('mints fresh ids and independent objects on every build', () => {
+ const first = buildStarterPlan(planId)
+ const second = buildStarterPlan(planId)
+ const ids = first.routines.map(r => r.id)
+ expect(new Set(ids).size).toBe(ids.length)
+ expect(second.routines.some(r => ids.includes(r.id))).toBe(false)
+ expect(first.routines[0].ex[0]).not.toBe(second.routines[0].ex[0])
+ // and the static definition survives a caller mutating what it got back
+ first.routines[0].ex[0].sets = 99
+ expect(buildStarterPlan(planId).routines[0].ex[0].sets).toBe(approved[0][2][0][1])
+ })
+})
+
+describe('starterRoutines (the demo build entry point)', () => {
+ it('still returns push, pull and legs unchanged', () => {
+ const routines = starterRoutines()
+ expect(routines.map(r => r.name)).toEqual(['Push Day', 'Pull Day', 'Leg Day'])
+ routines.forEach((r, i) => expect(shape(r)).toEqual(APPROVED.ppl[i][2]))
+ expect(routines.map(r => r.emoji)).toEqual(['barbell', 'pullup', 'legs'])
+ })
+
+ it('mints fresh ids on every invocation', () => {
+ const first = starterRoutines().map(r => r.id)
+ const second = starterRoutines().map(r => r.id)
+ expect(new Set([...first, ...second]).size).toBe(6)
+ })
+})