CompileStrength
An AI-powered fitness SaaS. Users chat with an agent that generates personalized, science-based workout programs — and tracks sessions over time as training adapts.
Overview
CompileStrength is a subscription SaaS product for serious lifters who want programming grounded in training science, not generic templates. The core product is an AI agent that asks about training history, goals, and constraints — then generates a full periodized program.
Beyond generation, users track sessions, log progress, and watch their program adapt over time. The product includes a public calculator suite for acquisition and a subscription billing layer for monetization.
Problem
Fitness apps either give you rigid templates or put you in front of a generic chatbot. Neither produces a coherent, periodized program. The people who actually know programming — coaches — don't scale. The people who want good programming — intermediate and advanced lifters — don't have access to them.
The technical challenge was building an AI agent that produces structured, valid workout programs rather than conversational text. Output needed to be machine-readable, consistent, and safe to display — not just coherent prose.
Solution
We built the AI layer on Mastra — an agent framework that lets you define workflows with structured input/output schemas, not just free-form prompts. The workout compiler agent follows a fixed workflow: gather context, validate constraints, generate program blocks, validate output structure, return to the user.
Billing (LemonSqueezy) and auth (Better Auth) were integrated as first-class concerns from the start. The agent's generation limits are gated by subscription tier, and session tracking is tied to the user's program history — not a separate data model.
Technical approach
The entire backend runs on Cloudflare Workers via OpenNext.js. This means no traditional server, no cold starts, and global edge distribution — but it also means a constrained runtime. The Node.js API surface available on Workers is limited, which ruled out several common libraries.
Neon PostgreSQL with Drizzle ORM was chosen specifically for its HTTP-based driver, which works inside the Workers runtime where standard TCP database connections don't. Drizzle handles schema, migrations, and queries — all with full TypeScript inference.
State management (Zustand) is limited to client-side concerns: active workout session UI, animation state, user preferences. No server state is duplicated client-side.
Stack
Results
End-to-end SaaS
Fully subscription-ready — billing, auth, AI, and edge deploy all integrated
Zero cold starts
Cloudflare Workers edge runtime, globally distributed from launch
Structured AI output
Agent generates valid, machine-readable programs — not conversational text
Key takeaways
Edge-first from day one
Running on Cloudflare Workers means no cold starts and global distribution without infrastructure management. The tradeoff is a constrained runtime — no Node.js APIs, limited native modules. We scoped the stack around that constraint, not against it.
AI as a feature, not a proof of concept
The Mastra agent doesn't just call a model — it follows a structured workflow, validates outputs, and falls back gracefully when generation fails. Users don't see the model; they see a workout program.
Billing integrated from the start
LemonSqueezy webhook handling was part of the initial build, not retrofitted. Subscription state flows into the UI and the AI agent's usage limits from the same source of truth.
Building something similar?
AI products, SaaS subscriptions, edge-deployed systems — let's talk about your project.