Skip to content

jermzblake/gainplan

Repository files navigation

gAInplan

A TypeScript monorepo powering gAInplan — an AI-driven fitness coach that builds personalized workouts from your equipment, goals, and constraints, then guides you through set-by-set execution with real-time feedback.

Your gear. Your goals. Your plan — generated in seconds, grounded in a curated exercise database, and validated by a background audit agent before you train.

Source visibility: This repository is temporarily public for transparency and portfolio purposes. It is not open source — all rights are reserved, and no license is granted to use, copy, modify, or distribute the code. Third-party exercise data and imagery remain subject to their respective licenses; see Acknowledgments.


Screenshots

Landing & auth

Onboarding with frictionless, anonymous start, plus email and social sign-in.

Welcome screen Sign in
Welcome — landing screen Auth — sign in

Workout planner

Four-step wizard to capture equipment, training focus, target area, and session details.

Target area selection Session details
Planner — target area selection Planner — session details

AI generation & plan review

Streaming workflow progress, generated workout cards, and background audit verification.

Live workflow stream Audit-verified plan
Building workout — agent workflow Generated workout — audit verified

Generated workout detail

Active session

Guided execution with exercise imagery, set tracking, rest timers, and effort logging.

Set-by-set tracking Workout overview
Active workout — set tracking Workout in progress — overview

Set complete — progress capture


Features

AI workout planning

  • 4-step planner wizard — equipment, training objectives, target area (with optional muscle-group refinement), duration, and free-form notes.
  • Context-aware suggestions — target-area recommendations based on prior equipment selections.
  • RAG-powered exercise retrieval — semantic search over a pgvector-indexed exercise catalog, constrained by available equipment.
  • Structured output — every agent response validated through shared Zod schemas in @repo/schema.
  • Live generation stream — NDJSON workflow events surfaced in the mobile UI (planretrievecompose).

Background quality assurance

  • Detached audit workflow — critique agent evaluates duration and joint-safety constraints after the fast path returns.
  • Smart repair loop — rejected exercises are swapped from the original movement pool without blocking the user.
  • Realtime notifications — Supabase Realtime pushes audit results to the client when plans are updated.
  • Durable outbox — Postgres-backed job queue with retries, dead-letter handling, and compensating scanner (no Redis required).

Training session

  • Active workout mode — set-by-set progression with exercise imagery and coaching cues.
  • Rest timer — automatic countdown between sets with optional progress capture.
  • Effort & load logging — record actual reps, optional load (kg), and perceived effort per set.
  • Session resume — pick up an in-progress workout from the overview screen.
  • Workout completion — structured completion payloads persisted to the API.

Account & preferences

  • Frictionless onboarding — anonymous sessions with optional conversion to email, Google, or Apple sign-in.
  • Profile preferences — equipment defaults and fitness level synced via authenticated API routes.
  • Type-safe client — Hono RPC client shared between mobile and API for end-to-end TypeScript contracts.

Agentic AI flow

gAInplan separates fast user-facing generation from slow background validation, orchestrated by Mastra workflows and specialized agents.

sequenceDiagram
    participant User
    participant App as Expo Mobile App
    participant API as Hono API (Bun)
    participant WF as generateWorkoutWorkflow
    participant DB as Supabase (Postgres + pgvector)
    participant LLM as LLM Provider
    participant Outbox as Outbox Worker
    participant Audit as backgroundAuditWorkflow

    User->>App: Configure equipment, focus, target, duration, notes
    App->>API: POST /api/v1/workout/generate-plan
    API->>WF: plan → retrieve → compose

    rect rgb(30, 40, 60)
        note right of WF: Plan step
        WF->>LLM: Planner agent — structural blueprint (movement patterns, sets, reps)
        LLM-->>WF: Blueprint JSON
    end

    rect rgb(30, 50, 40)
        note right of WF: Retrieve step
        WF->>DB: pgvector hybrid search per movement pattern
        DB-->>WF: Top-3 exercise candidates per pattern
    end

    rect rgb(50, 40, 30)
        note right of WF: Compose step
        WF->>LLM: Composer agent — select exercises from candidate pool
        LLM-->>WF: Composed workout JSON
    end

    API->>DB: Persist draft workout (status: generated)
    API->>Outbox: Enqueue audit job (best-effort)
    API-->>App: Return workout immediately (~2–4s)

    Outbox->>Audit: Critique → repair loop (if needed)
    Audit->>LLM: Critique agent — duration & joint-safety audit
    Audit->>DB: Update workout + audit metrics
    DB-->>App: Realtime audit notification
Loading

Agents

Agent Role
Planner Builds a biomechanical blueprint from user constraints — movement patterns, sets, and rep ranges — without naming specific exercises.
Composer Selects exactly one database-backed exercise per pattern from the retrieved candidate pool and titles the session.
Critique Audits the draft for duration overflow and joint/fatigue safety; flags specific exercises for replacement.

Design principles

  1. Never hallucinate exercises — the composer can only choose from pgvector-retrieved candidates with real database IDs.
  2. Return fast, validate async — users get a usable plan immediately; the audit agent refines it in the background.
  3. Shared contracts@repo/schema Zod types flow from API validation through agent structured output to the mobile client.

See also: docs/sequence-diagram-init.mmd, docs/sequence-diagram-outbox-worker.mmd, and apps/api/docs/outbox-worker-e2e.md.


Tech stack

Layer Technologies
Monorepo Turborepo, Bun workspaces
Mobile Expo 54, React Native, Expo Router, NativeWind, Zustand
API Bun runtime, Hono, Drizzle ORM
Database Supabase (Postgres, Auth, Realtime), pgvector
AI orchestration Mastra, OpenAI embeddings & completions, structured output via Zod
Shared packages @repo/schema (Zod contracts), @repo/ui, @repo/eslint-config, @repo/typescript-config
CI/CD GitHub Actions, EAS Build for mobile

Repository structure

kinetiq/
├── apps/
│   ├── mobile/          # gAInplan — Expo React Native app
│   ├── api/             # Hono API, Mastra workflows, outbox worker
│   ├── web/             # Next.js (scaffold)
│   └── docs/            # Next.js docs site (scaffold)
├── packages/
│   ├── schema/          # Shared Zod schemas & domain types
│   ├── ui/              # Shared React components
│   ├── eslint-config/
│   └── typescript-config/
├── assets/screenshots/  # App screenshots for documentation
└── docs/                # Architecture & sequence diagrams

Getting started

Prerequisites

  • Bun >= 1.3.14
  • Node.js >= 18
  • Supabase project with Postgres + pgvector enabled
  • OpenAI API key (embeddings + agent completions)

Install

bun install

Environment

Copy the example env files and fill in your own values:

cp apps/api/.env.example apps/api/.env
cp apps/mobile/.env.example apps/mobile/.env

At minimum the API requires:

  • DATABASE_URL, APP_USER_DATABASE_URL
  • SUPABASE_URL, SUPABASE_ANON_KEY, SUPABASE_SERVICE_ROLE_KEY
  • OPENAI_API_KEY, OPENAI_EMBEDDING_MODEL, OPENAI_COMPLETION_MODEL
  • Agent model overrides: PLANNER_AGENT_MODEL, COMPOSE_AGENT_MODEL, CRITIQUE_AGENT_MODEL

See apps/api/.env.example and apps/mobile/.env.example for the full list of supported variables.

Develop

# Run all apps in parallel
bun run dev

# API only (http://localhost:4004)
bun run dev --filter=@kinetiq/api

# Mobile only
bun run dev --filter=mobile

Test & validate

bun run lint
bun run check-types
bun run test:unit

Import exercises

Exercise data is imported from a JSON array matching the schema expected by the import script:

cd apps/api
bun run import:exercises ../exercise-data/exercises.json --dry-run
bun run import:exercises ../exercise-data/exercises.json

See apps/api/README.md for additional scripts (test tokens, embedding tests, planner agent debugging).

Docker

docker compose up --build

Acknowledgments

gAInplan would not be possible without the open datasets and tooling maintained by the following contributors.

Exercise data

Structured exercise metadata — names, muscle groups, equipment, instructions, and search summaries — is derived from the excellent free-exercise-db project by Jonas (@yuhonas), which in turn builds on the original exercises.json corpus by Ollie Jennings (@OllieJennings).

Thank you for making a high-quality, open exercise dataset available to the community.

Exercise imagery

Demonstration images shown during workouts are sourced from the free-exercise-db image collection and hosted via GitHub raw assets. gAInplan imports and stores these URLs alongside exercise records during the database seeding pipeline.

Thank you to Jonas and the upstream contributors who curated and published this imagery under an open license.


Icebox

Planned and deferred work — not yet shipped, but on the radar:

  • Workout library — evolve the Library tab from a component proving ground into a full saved-workout history with search and favorites.
  • Progress analytics — volume tracking, trend charts, and longitudinal performance insights (surfaced on the welcome screen roadmap).
  • Post-completion intelligence — async processing of completion data for adaptive coaching tips and preference learning.
  • Expo home-screen widgets — glanceable active-session and rest-timer surfaces (noted in architecture diagrams).
  • Retrieval tuning — dynamic pgvector similarity thresholds and optional force/mechanic filtering (push/pull, compound/isolation).
  • Settings expansion — unit preferences (kg/lb), account deletion, and additional profile controls.
  • Admin & recovery tooling — manual audit overrides and CDC-style catch-up for terminal audit states.
  • Web client — production-ready Next.js experience beyond the current Turborepo scaffold.

License

All rights reserved. This repository is source-visible, not open source — no license is granted to use, copy, modify, or distribute the software. Third-party exercise data and imagery are subject to their respective open licenses; see Acknowledgments.

About

Agentic Fitness App

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors