Élite Trainer
An AI personal trainer that designs your workouts and diets and tracks your progress workout by workout. Focused on tool calling and cost control.
A React Native app designed for iPhone and on its way to the App Store, to log workouts, meals, steps and weight, with an AI trainer that works on that data. I built it end to end, with Claude integrated directly on the Anthropic SDK, with no agent frameworks.
The challenge wasn't connecting a chat to an LLM, but getting it to answer with real data, making what it generates fit into the app, and having every call measured and capped.
Tool calling
- Custom agent loop — 12 tools to query the history and the catalogs and to propose plans. Up to 6 turns per message; on the last one the answer is forced with tool_choice: none.
- The model proposes, the server decides — Inputs are validated with Zod before anything runs. No tool receives the user ID: the server sets it, so the model cannot choose whose data it is.
- Controlled side effects — Tools run sequentially, with a single proposal per message. Nothing becomes one of the user's plans until they accept it, and acceptance is atomic so it can't be duplicated.
- Designing and translating separately — The agent designs freely, and a second call, the only one that knows the app's constraints, converts the design into its format. Code validates the result.
- Business rules in code — The model doesn't calculate calories or macros. A diet below the safe minimum is not saved: the reason goes back as a tool result so the model can fix it.
- Structured output — The review of each workout is delivered through a tool in strict mode, with one retry if it doesn't match the format.
Cost control
- Per-call metering — User, model, stop reason and tokens, including tool turns, translations, reviews and responses that fail midway.
- Quotas per plan — A monthly token cap, checked on the server before starting and on every new turn of the agent.
- Per-request limits — max_tokens on every call, a bounded number of turns, history trimmed to about 6,000 estimated tokens and low reasoning effort.
- Minimal context — The model gets a short profile generated by code and requests details through tools, instead of receiving the whole history.
- Visibility — An admin panel with tokens and estimated cost per user and per month.
Architecture
- Streaming over an asynchronous chat — The API replies with an ID and generates in the background, receiving Claude's response as a stream; the app polls the progress and displays it as it goes. This way a long generation doesn't hit API Gateway's 30-second limit.
- TypeScript end to end — A monorepo with an Expo (React Native) app, a NestJS API and shared types and Zod validations. AWS infrastructure with CDK.
Technologies
- TypeScript
- Claude API (Anthropic SDK)
- Tool calling
- Zod
- NestJS
- MongoDB Atlas
- Expo
- React Native
- AWS ECS Fargate
- API Gateway
- Cognito
- AWS CDK
- Docker