all projects

Training planner

A training plan that writes itself into my calendar and onto my Garmin watch, moves around the rest of my life, and eases off after a bad night's sleep.

  • Astro
  • TypeScript
  • Cloudflare Workers
  • Cloudflare D1
  • Google Calendar API
  • Garmin Connect
  • Claude

I like running, I do parkrun most Saturdays, and I’ve just bought a Zwift bike. I’ve also had a niggly ankle for a while. What I don’t enjoy is planning training: deciding what to do each day, moving it when plans change, and remembering the boring rehab exercises that actually keep me running.

So I built something to do that for me. I wanted to wake up and be told what to do, and have it on my watch, without ever thinking about it.

All the screenshots below use made-up example data.

What it does

The goal is ambitious but simple: get my VO2 max up, stay injury-free, and eventually run a sub-20 5k. The planner works backwards from that.

  • A plan with phases. Five weeks to reset after a marathon, then an aerobic base, a speed block, and a sub-20 block next summer. Each week has a shape: a hard Zwift session (later a hard run), an easy run, a Zwift endurance ride, parkrun, a long run, plus ankle rehab and strength work.
  • It goes in my calendar. Every session lands on a “Training” calendar, with the details in the description and a reminder before it starts.
  • It goes on my watch. Runs and rehab are sent to my Garmin with heart-rate targets. Easy runs are capped at 152 bpm, because, honestly, my “easy” runs weren’t.
  • It reads my sleep. Each morning it checks last night’s sleep score, HRV and resting heart rate. After a poor night, today’s hard session becomes an easy one. After a really bad night, it’s a rest day.
  • It moves around everything else. If something lands on top of a session, the session moves to another evening, keeping the important rules: never two hard days in a row, and never a hard session the day before parkrun.
A table of the next fortnight's training, each session with a time and a skip link. A Zwift ride is marked 'Moved from Thu 26/11 17:45 to fit around other plans'. In the week of the Riverside 10k on Sunday 06/12, sessions are marked 'Taper for Riverside 10k', Tuesday is 'Zwift openers', Saturday's parkrun is a very easy jog, and a note says the next week's hard session is dropped while recovering.
The next fortnight. A Zwift ride has moved to make room for something else, and the week before a 10k tapers down.

Races

I enter a few races a year, and the plan needs to know about them. There’s a small form: name, date, start time, distance and whether it’s an A race (the one I care about) or a B race (a hard training run with a number on).

A race list showing 'Sun 06/12 09:30 Riverside 10k, 10 km, A: goal race, in 12 days', above a form with race name, date, start time, distance and a choice between A (goal race) and B (training race).
Adding a race takes ten seconds.

The 5k plan stays in charge, and races just reshape the days around them. An A race gets a proper taper: shorter runs and rides, a short sharp session early in the week instead of the usual hard one, a jog at parkrun the day before, and no hard sessions until I’ve recovered. How long all that lasts depends on the distance: a few days either side of a 5k, nearer a fortnight around a half marathon, with no running at all for two days after it. A B race simply is that week’s hard session, with a couple of easy days before it. Races never move: everything else moves around them.

Living with other people’s plans

The bit I’m most pleased with is how it fits in with the planner I’d already built for my calendar. My partner adds things to my calendar from her phone. Now, when she does, she sees straight away what it means for my training before she taps Add. My training moves out of the way immediately, and I get a message saying what moved.

A phone screen titled 'Add to Ben's calendar' checking 'Cinema with friends' on Wednesday 18:00 to 21:00. Below it: 'Ben's training will move to fit', listing the easy run moving to Friday, strength moving earlier on Wednesday, and a Zwift ride moving later on Friday.
Adding a night out shows exactly how the week of training will shift.

The two planners agree on who gives way. Anything either of us adds by hand always wins. Quiz and games nights beat training. Training beats the flexible “time together” slots, which the other planner happily finds new homes for.

How it’s built

It lives inside this website, which runs on Cloudflare Workers, alongside the calendar planner. They share a small Cloudflare D1 database.

The scheduling engine is a set of pure functions with no network calls. Given the week’s template, my calendar and last night’s sleep, it works out where every session should go, then the smallest set of calendar changes to get there. That makes it easy to test, and it has a test for every rule I care about. A few decisions mattered:

  • Most important first. parkrun is placed first, then the hard session, the long run, the easy run and the endurance ride. Each tries its usual slot, then where it was last time, then alternatives. If the week is genuinely full, the least important session is dropped, never crammed into a later day.
  • No surprises. A moved session needs at least 12 hours’ notice, so nothing lands on me tonight because of something added this afternoon.
  • It only touches its own things. Calendar events and Garmin workouts it creates are tagged, and it checks the tag before changing or deleting anything.
  • Glitches aren’t skips. Deleting a session from my calendar counts as skipping it, but only if Google confirms it was deleted. If lots of sessions vanish at once, that’s treated as a glitch and they’re put back. I found that one the hard way while testing.

Garmin was the tricky part. There’s no public API a website can call, so a scheduled Claude routine with access to my Garmin account acts as a bridge. A few times a day it sends last night’s sleep numbers to the site, asks what should be on my watch, makes those changes and reports back. The site does all the thinking; the bridge just carries things back and forth. It starts in a dry-run mode that only logs what it would do, so I can check a week before letting it loose on my watch.

Zwift sessions stay off the watch. They’re in the calendar with the power targets, I ride them in Zwift, and Zwift uploads the ride to Garmin afterwards so it still counts.

The plan's four phases with dates and milestones: Reset (now), Aerobic base, Speed and Sub-20 block, ending with the goal of a sub-20 5k in autumn 2027.
The long game: four phases between now and a sub-20 attempt next autumn.

How to use it

There’s nothing to do, which was the point. Things appear in my calendar and on my watch, and my phone tells me what’s on at 7am. When life happens I can:

  • tap skip on a session, on the page or in Telegram
  • say my ankle’s sore, which swaps runs for the bike for a week and eases off the rehab
  • just delete a session from my calendar

What’s next

  • Run the dry-run week, check every decision in the log, then switch it on.
  • A trend chart for VO2 max and parkrun times on the page, so I can see whether the plan is working.
  • Custom Zwift workout files, so the power targets load straight into Zwift instead of me building them.
  • Longer long runs in the weeks before a half marathon. For now the plan stays 5k-focused and only tapers and recovers around one.

Changelog

  • 28/11/2026: The morning sleep check was missing about half the time. The bridge used to make its last try at 6:45, but my watch only syncs last night’s sleep once I’m up with my phone, and on lie-in days I’m not. It now tries at 6:45, 7:45 and 8:45, and the morning message waits for real sleep data, with 8:45 as the cut-off. There’s also a catch-up try at 11:45, so even after a proper lie-in the rest of the day is planned around how I actually slept.

Keep reading

This website

How I rebuilt itsjustben.co.uk with Astro and Cloudflare, with a public blog and a family-only private area.

parkrun + Spoons

A page that pairs parkruns with the nearest Wetherspoon for a post-run breakfast. A public finder for anyone, plus a private version that tracks the ones we've done.

Smart home

Tidying up the tech around the house, starting with stripping the ads, trackers and clutter out of my Google TV box and giving it a home screen that matches this website.