← Back to Projects
Gains

Gains

A fast workout tracker for the gym floor that coaches with clear, explainable rules and shows its reasoning.

Next.jsTypeScriptReactZustandTailwind CSSPythonFastAPISQLAlchemyPostgreSQLAlembicVitestPlaywright
210+
automated backend tests
300+
frontend tests
21
browser tests run against a real backend
18
database migrations

The problem

Most fitness apps are cluttered, and logging a set during a short rest is slow, in gyms that often have poor signal. Gains is built to be quick and distraction-free, keeps the live workout safe on the device until it is finished, and explains every piece of coaching with the numbers behind it. I built it for my own training and have used it for several months.

What it does

Progression Suggestions

Suggests the next weight and rep target for each exercise from how the last session went, so progress comes one sensible step at a time.

Burnout Checker

Spots several lifts stalling, or effort staying very high, and suggests an easier week with the exact numbers shown as the reason.

Performance Stats

Charts show hard sets per muscle group each week, how recovered each one is, and how strength compares to where it was.

Milestones and Records

Fourteen milestones, plus a history of personal bests and weekly streaks, each awarded the moment it is earned.

Built for the Gym Floor

Warm-ups, drop sets, supersets and rest timers in one live workout that survives a page refresh or a dropped signal.

Templates and an AI Routine Builder

Pick a ready-made programme, or describe the training you want and review the AI's routine before saving it.

See it working

A live workout showing four sets of lever chest press with a suggested next weight and reps.
The live workout suggests the next weight and reps for each exercise.
A list of routines: push day, pull day, legs and core, and cardio and core.
Routines start a workout in one tap.
A stats overview with workouts, volume, time trained, sets and a weekly trend chart.
Stats compare each period with the one before it.
A grid of achievements, including personal records and milestones.
Personal records and milestones are awarded when a workout is saved.

How it's built

How Gains fits together: a Next.js front end with local storage for the live workout, Next.js server code, and a FastAPI service layer over PostgreSQL, with an AI provider used only for the routine builder.

Frontend

  • Next.js App Router with TypeScript. Server components fetch the data for pages, and server actions handle every write.
  • Zustand holds the live workout, which is also saved to local storage on every change.
  • Features are organised in folders, each with its own actions, validation schema and types.

Backend

  • FastAPI with thin routers (about 54 endpoints) over a services layer where the business rules live as plain, testable functions.
  • SQLAlchemy 2.0 and 18 Alembic migrations over 15 tables, on PostgreSQL in production and SQLite in development.
  • Progression, burnout, analytics and achievements are calculated on the server and sent to the browser ready to display.

AI and security

  • Only the routine builder calls an AI model, Gemini first with Groq as a fallback.
  • JWT in an HTTP-only cookie, bcrypt password hashing, and rate limits on sign-in and registration.

Key decisions and tradeoffs

  • Coaching runs on rules, not an AI model

    Progression, burnout and milestone logic are plain rules. They cost nothing to run, give the same answer every time, and each one reports the numbers behind it. Only the routine builder uses an AI model.

    The cost: The coaching is only as smart as the thresholds I wrote, and it cannot adapt to an individual the way a learned model could.

    Technical detail

    Progression is double progression, with increments by unit, body region and equipment, gated on how manageable the last session's RPE or reps in reserve were.

  • Keep every personal best as its own record

    Each time a set beats a previous best, or a streak gets longer, it is saved as a new entry instead of overwriting one record. The current best is worked out from that history, so a workout page can show exactly which records it broke.

    The cost: Looking up the current bests is a slightly heavier query than reading one stored value.

    Technical detail

    The current best per lift comes from a window query (ROW_NUMBER over a partition). Because the history is append-only, a backfill can replay it through the same award functions the live app uses.

  • Store kilograms, convert in one place

    The database holds kilograms only, and conversion to pounds lives in one module. That avoids rounding drift from converting back and forth, and history stays consistent when someone switches units.

    The cost: Every screen and every input has to go through the converter, so a missed call shows the wrong unit.

    Technical detail
    Code: units.ts
  • Save the live workout on the device first

    Gyms often have poor signal. The active workout is saved to local storage on every change and only sent to the server when it is finished, so a refresh, a crash or a dropped connection never loses a set.

    The cost: The workout lives on one device until it is finished, and the rest of the app still needs a connection, so this is not a full offline mode.

  • Check AI output, then save it all or not at all

    The routine builder's reply is untrusted text. It is validated and shown as a preview, and the saved routines go in as one batch, so a model error can never leave a half-written plan.

    The cost: Invalid parts are dropped rather than repaired, so a routine can arrive thinner than the model intended. Without any AI key the feature returns an error and the app points to the ready-made programmes instead.

    Technical detail

    The model only sees a restricted exercise catalogue. Its JSON is validated with Pydantic, values are clamped, unknown exercise IDs are dropped, and the batch endpoint saves everything in one transaction.

Hard problems I solved

  • Turning one vague warning into two measurable ones

    The problem
    The first burnout checker mixed 'your lifts have stopped improving' with 'you have been training hard for weeks' into one fuzzy suggestion with no clear number behind it.
    What I did
    I split it into two independent checks. Strength is each lift's estimated one-rep max over its last four sessions: a lift counts as stalled if that estimate has not grown, or has dropped by 5% or more, and the warning needs at least two tracked lifts with 40% or more stalled. Effort is the average RPE (a 1 to 10 score the user logs for how hard a set felt), and an average of 9 or more over two weeks across at least three workouts counts as the second warning. A two-week cooldown stops it nagging.
    The result
    Either check can suggest an easier week on its own, and the exact numbers behind it are shown, so the user sees why they are being told to ease off.
    Code: deload.py
  • Giving existing users their achievements retroactively

    The problem
    When the achievement system launched, existing users had months of history and nothing to show for it.
    What I did
    I wrote a tool that replays a user's whole history, workout by workout, through the same functions that award achievements live, rather than separate one-off catch-up logic.
    The result
    Past achievements come out as they would have live. The one compromise is that they are stamped with the day of the catch-up, not the original workout date.
  • Designing every state before writing code

    The problem
    I was learning the Next.js App Router, including when to use server or client components, while also needing the interface to be clear under pressure at the gym.
    What I did
    I designed the main screens in Figma first, including empty, loading and error states, to settle the layout and flows before building them.
    The result
    The empty, loading and error states are part of every screen from the start, not added afterwards.

Testing and quality

About 215 backend tests, about 300 Vitest tests and 21 Playwright tests.

GitHub Actions runs pytest, lint, Vitest and a build, then the Playwright tests against an isolated real backend, plus an advisory dependency audit.

  • 18 Alembic migrations.
  • Sign-in and registration rate limits that read the client address safely behind a proxy.
  • CSV export is sanitised against spreadsheet formula injection.

Known limitations

  • It is not a full offline mode. The live workout survives a dropped signal, but the rest of the app needs a connection.
  • Achievements awarded by the catch-up tool carry the catch-up date, not the original workout date.
  • Lift goals and routine weight targets are unfinished.
  • I have no performance benchmarks or other users' metrics, only my own months of use.

Database model

Schema for Gains

Use and further reading

I have used Gains consistently for several months as my own workout companion, tracking lifts, adjusting my programme and measuring strength against real data.

Read more in the repo: CI workflow