Project Details
A weekly training plan built from the athlete's own recent Strava rides, plus a short racing brief. The working app lives at /training. There is no account and no database. The Strava token lasts for the browser session, then it is gone.
A rider who already logs everything on Strava still has to translate that history into a week of training. Generic plans ignore last month's volume, the longest recent ride, and whether the next event is a climb, a flat race, or a mix. A full coaching product — accounts, stored tokens, a riders table — is a lot of infrastructure for a plan you regenerate when the week changes.
The product question was narrower. Can the plan be personal, and can the Strava credential stay off the server, if the only persistence is an encrypted cookie in the browser that requested it?
Signed out, the page is a connect card. Strava's authorize URL is built server-side. After the athlete approves, the callback exchanges the code, seals the tokens, and returns to the coach. Denied access, a failed token exchange, and missing environment variables each get their own message. The page does not sit on a spinner.
Read-only OAuth. Scopes are read and activity:read_all.
Access and refresh tokens go into an encrypted httpOnly cookie. Nothing is written to a database.
The last 60 activities. Rides and virtual rides become a 30-day summary.
FTP, hours per week, A and B races, racing type, and course style.
Claude returns either a flexible interval menu or a day-by-day plan.
With a valid session, the server reads the cookie and fetches the athlete profile plus the latest 60 activities directly from Strava. Rides and virtual rides are kept. The setup screen shows a 30-day summary: hours, ride count, and the longest ride. If Strava has a weight on the profile, the form pre-fills it in pounds. Power rides that recorded device watts are listed with average and weighted-average watts.
The athlete then sets FTP, available hours (the form starts at 8), and two questions about racing: endurance, sprint and punch, or both; and climbing, flat, rolling, or mixed. Races are a name, a date, and an A or B priority. The form opens with Unbound 100 as an editable placeholder, not a fixed event. A flexible menu needs an FTP. A day-by-day week also needs a weight and at least one race.
Generate posts that brief to the plan API. The model has to call a tool and return a structured object, so the UI can render it instead of scraping a paragraph. Either plan can be downloaded as CSV or printed to PDF. If the model key is missing, the app says the plan is not configured. It does not pretend a plan is on the way.
The default. A short philosophy, a loose weekly rhythm, volume guidance, and five to eight interval options tagged by how the athlete feels that day, including a genuinely easy option. Each option has a watt target, a session length, a coaching note, and a power-and-time bar. The prompt asks for about two quality sessions plus easy riding, chosen by feel, for events in the two-to-four-hour range.
One week, Monday through Sunday. Phase, target volume, the week's focus, a limiter, insights, and a note on the following week. Each day has a zone, a session, intervals, and a fueling note. The summary also includes a field the UI labels "Unbound target pace," carried over from the original gravel brief.
Both prompts bias the work toward the racing type and the course. Climbing courses pull toward sustained efforts. A sprint focus pulls toward short hard repeats. With no rides in the last 30 days, the flexible prompt tells the model to stay conservative.
The Strava access token and refresh token live in a cookie named training_strava. It is httpOnly, SameSite=Lax, and Secure in production, so page scripts cannot read it and it is not sent on cross-site requests. The value is AES-256-GCM ciphertext. The key is the SHA-256 hash of TRAINING_SESSION_SECRET. A tampered cookie fails to open.
The cookie holds the access token, the refresh token, the Strava expiry, the athlete id, and an absolute session deadline. That deadline is 14 days from sign-in. Refreshing the Strava token writes a new cookie and does not extend the deadline. If the access token is inside five minutes of expiry, the server refreshes it in place before calling Strava. A failed refresh clears the cookie and the athlete connects again. There is no riders table and no token table for this app. When the cookie expires, or the browser drops it, the session is over.
An earlier version of the race tracker stored Strava tokens in Supabase and read them back on each visit. On the free tier that project kept pausing. A login that depends on a paused database fails even when the environment variables are set, and it fails as a network error rather than a clear message. For a portfolio piece that has to keep working, that was the wrong dependency.
Training Coach dropped server-side storage. The tradeoff is the product: there is no saved history of generated plans, no account to come back to, and the session ends with the cookie. The race tracker on this site made the same call from the other direction. The public page is now a static demo with bundled sample riders, so it still renders when Supabase is paused and when no environment variables are set. The original tracker did use Strava and Supabase. This portfolio copy does not.
/api/strava/callback.claude-sonnet-5-5, overridable with ANTHROPIC_MODEL. The plan is requested with tool use so the response matches the menu or the week schema.Two different uses, and they stay separate. At runtime, Claude drafts the week from the Strava summary and the form. The app around that call — the OAuth callback, the sealed cookie, the form, the error states — was built in Cursor while learning to ship software with an AI coding agent. The constraint that shaped it was a coach that works without a database, and a page that says what is wrong when a token or a key is missing.
Product framing, the decision to keep tokens in the session, the choice between a flexible menu and a scheduled week, and the implementation.