Project

Completed

Building the Movie Dashboard

Spec-Driven Development to create a movie watch log using Google Sheets, enriched with TMDB metadata

Visit project ↗

The music dashboard I created turned eighteen years, give or take, of listening history into charts, and I wanted something for films and TV. The catch is that nothing scrobbles my film or TV watching, so I’d be logging them by hand.

That part had to stay as low-effort as possible, so I opted to use a Google sheet with one row per film. All I track is the date, the title, give it a rating, locate the TMDB ID, mark if it’s a movie or tv show, and have two columns for notes.

If I want to add a review I can write a short piece of text in the public_note column. If it’s a tv show, denote the season/series and episode, again one episode per row. Everything else (posters, runtimes, genres, directors, streaks) should be worked out for me without me touching anything.

This dashboard and log was built with Claude Code, across three of my repos in a single evening. Once a basic system was built it was ready for a backfill of several years worth of data from various watch logs (Letterboxd and Trakt).

As I imported data into Google Sheets, I then spent some time reworking how the pages fit together and how the data flowed. Seeing it come together with real data makes all the difference.

Film Watch Log → Daily Stats Pipeline

Before any code, I wrote a simple spec. It covered the goal, an architecture sketch of what I thought it would look like, the spreadsheet schema and the use of the TMDB API.

The underlying infrastructure needs to be considered, there are a fair few moving pieces built to accommodate what looks like simple pages of data. There are cloud functions, buckets, data pulls, a website build, GitHub actions; the application itself which is a small collection of Python scripts to pull in data from Google Sheets, to match it with TMDB data via its API, and to store my enriched and transformed data in a GCS bucket. Then there’s the website itself which is built on Astro. All of this is published as dependency-free static pages, a page for every film. There’s no server or compute so everything needs to be built.

Goal

Log films in a personal Google Sheet. Every day, a scheduled GCP job reads the sheet, enriches each entry with TMDB metadata, computes dashboard stats, and publishes a stats.json that my personal website consumes.

Hand-edited data stays in Sheets. Everything else is derived and rebuildable.

Architecture

Architecture of the film stats pipeline: Google Sheet, Cloud Scheduler, Cloud Run, Secret Manager, a private cache bucket, a public stats bucket, TMDB, a GitHub Action, Cloud Build and the visitor's browser

Following a film from the sheet to the page:

  1. I add a row to the sheet: date, rating, TMDB ID.
  2. At 05:00 UK time, Cloud Scheduler calls the private Cloud Run service, proving who it is with a short-lived OIDC token. Nothing else is allowed to call it.
  3. The service reads the whole Google sheet through the Sheets API. It has read-only access because the sheet is shared with its service account, exactly like sharing it with a person. No key file is involved.
  4. For each film, it checks a private cache bucket first and only asks TMDB on a miss. The TMDB token comes from Secret Manager.
  5. It writes one file to a public bucket: films.json, every viewing plus the TMDB metadata for each title.
  6. At 06:30 UTC, a GitHub Action in the website repo downloads it. If anything changed, it commits it, which triggers the normal site build and deploy. The build works out every stat from that file.
  7. Visitors get plain static HTML. Only the poster images come from TMDB, directly into their browser.

If a run fails, Cloud Scheduler retries it three times, and a Cloud Monitoring alert emails me.

Three repos, one pipeline

The site is already split across three repos: one for small backend apps, one for Terraform, and one for the website itself. This project touched all three.

The apps, infra and website repos, what runs on a pull request and on merge to main in each, and which part of Google Cloud each one deploys to

Each repo has its own CI and deploys its own piece, and none of them hold a Google Cloud key. GitHub Actions swap their own OIDC token for short-lived credentials through Workload Identity Federation. The only link between repos at runtime is the one public file.

The service

The service is Python, laid out the way the spec suggested: one small module per job, and a thin main.py that runs them in order.

The five steps of one run, and what each does when something goes wrong

Reading the sheet. Dates were the first trap. Asked for dates as formatted text, the Sheets API formats them in the sheet’s locale, so 03/04/2026 could be March or April. The service asks for dates as serial numbers instead, which mean the same thing in any locale.

Validating. Bad rows follow the spec: they’re skipped, and recorded in the output with their row number and the reason, such as non-numeric tmdb_id. An out-of-range rating is treated more gently: the viewing still counts, it’s just unrated.

Enriching. TMDB responses are big, so the service keeps only the ten or so fields it needs and caches them in a private bucket. Cache entries are refreshed after 30 days so posters and scores don’t go permanently stale, and if TMDB is down, the old copy is used. (The cache started out as one small file per film; scaling for a backfill explains why it became a single index file.)

The TMDB client itself retries rate limits and server errors with exponential backoff, and respects TMDB’s Retry-After header when it sends one.

Computing the stats. This is the part I most wanted tested, so it’s pure functions: films and metadata in, a dictionary out. They don’t touch the network or even read the clock; “today” is passed in. That makes them easy to test against fixtures, covering the edge cases the spec listed: rewatches, empty months, streaks that cross a month or year end, and bad rows. In the first version this ran in the service and published a ready-made stats.json. Since the redesign the service only builds the export, and the same kind of tested pure functions run in the website’s build instead.

One small design choice I like: the current streak survives until the end of the day after your last film. Otherwise the 05:00 run would reset it every morning, before I’d had a chance to watch anything that evening.

Publishing. The file is uploaded under a staging name, then copied over the live one, so a failed upload never touches the live file. It’s served with a one-hour cache header.

Data contract: the Sheet

Tab name: Watch Log. Row 1 is headers. One row per viewing (rewatches are separate rows with the same ID).

ColHeaderTypeNotes
Awatched_datedateReal date cell or ISO YYYY-MM-DD
BtitletextHuman label only, not trusted for lookup
Cscorenumberoptional
Dtmdb_idintegersource of truth for enrichment
Emedia_typetext movie or tvblank means movie
Fseasonintegerseason if tv, what season?
Gepisode.integerepisode if tv, what episode?
Hpublic_notetextOptional; this is my review for publishing
InotestextOptional; not published

Rules: skip blank rows, skip rows with a missing or non-numeric tmdb_id or an unparsable date, and record each skipped row (row number plus reason) in warnings in the output rather than failing the run.

Components

1. Cloud Run function (Python 3.12), src/

Runs as a dedicated service account (film-stats-runner). No service account keys. Use Application Default Credentials with scope https://www.googleapis.com/auth/spreadsheets.readonly; the runtime SA is shared on the sheet as Viewer.

Suggested layout:

src/
  main.py          # entrypoint: orchestrates the run
  sheet.py         # read + validate rows
  tmdb.py          # fetch with cache, retry/backoff, rate-limit politeness
  stats.py         # pure functions: rows + metadata -> stats dict (unit tested)
  publish.py       # write stats.json to GCS
tests/
  test_stats.py
  fixtures/

Flow in main.py:

  1. Read the sheet via sheets.spreadsheets().values().get(range="'Watch Log'!A2:F", valueRenderOption="UNFORMATTED_VALUE", dateTimeRenderOption="FORMATTED_STRING").
  2. Validate and normalise rows (sheet.py).
  3. For each unique (media_type, tmdb_id): load from GCS cache, otherwise call TMDB GET /{type}/{id}?append_to_response=credits and write the trimmed result to cache. Cache only the fields needed: title, release date, runtime, genres, director(s), poster path, original language, TMDB vote average. If TMDB errors and a cache entry exists, use it. If neither exists, add a warning and continue.
  4. Compute stats (stats.py).
  5. Write stats.json to the public bucket with Cache-Control: public, max-age=3600. Write atomically (upload under a temp name, then copy/rename) so the site never reads a half-written file.
  6. Log a one-line summary (rows read, rows skipped, TMDB calls made, cache hits).

The function should be idempotent: running it twice produces the same output.

2. Stats to compute (stats.json)

Include schema_version, generated_at (UTC ISO), and warnings.

  • totals: films watched (viewings), unique films, rewatches, total runtime hours
  • by_year and by_month: viewing counts (fill empty months with 0 for charting)
  • genres: counts, sorted descending
  • decades: counts by release decade
  • directors: top 10 by count
  • languages: counts
  • streaks: current and longest run of consecutive days with a viewing
  • busiest: busiest month, busiest weekday
  • ratings: distribution plus average (only if ratings exist)
  • recent: last 12 viewings with title, year, poster path, watch date, rating, TMDB ID
  • attribution: the TMDB attribution string required by their terms

Keep it a single JSON file for now. If it grows past a few hundred KB, split recent or all_viewings into a second file.

3. Terraform, infra/

Follow the repo’s existing conventions for backend, naming and variable layout. Resources:

  • APIs enabled: sheets.googleapis.com, run.googleapis.com, cloudscheduler.googleapis.com, secretmanager.googleapis.com, storage.googleapis.com, cloudbuild.googleapis.com, artifactregistry.googleapis.com
  • Service accounts:
    • film-stats-runner: runtime identity for the function
    • film-stats-scheduler: used only by Scheduler to invoke the function
  • Secret Manager: tmdb-api-token (resource only; I’ll add the secret version manually so the value never touches state or the repo). film-stats-runner gets secretAccessor on that secret only.
  • Buckets (uniform bucket-level access, public access prevention as appropriate):
    • <project>-film-tmdb-cache: private. Runner gets objectAdmin.
    • <project>-film-stats-public: runner gets objectAdmin. allUsers gets objectViewer on this bucket only. CORS restricted to my website origin (variable). Lifecycle: none needed.
  • Cloud Run function (2nd gen): Python 3.12, runs as film-stats-runner, env vars for sheet ID, bucket names, sheet tab and range; TMDB token mounted from Secret Manager. Not publicly invocable. Modest limits (256–512 MiB, 120s timeout, max 1 instance).
  • Cloud Scheduler job: daily at 05:00 Europe/London, HTTP target is the function, OIDC token from film-stats-scheduler, which has run.invoker on the function only. Retry config: 3 attempts with backoff.
  • Variables: project_id, region, sheet_id, site_origin, schedule. Outputs: function URL, public stats URL, runner SA email (I need this to share the sheet).

As on the contact form, Terraform creates the secret but never its value, so the TMDB token never touches Terraform state or git. That brings back the same chicken-and-egg problem: Cloud Run won’t create a service whose secret has no value. So the first apply builds everything except the service. Then I add the token by hand, and a one-line change switches the service on.

4. Manual steps (Claude Code should list these for me at the end, not try to do them)

  1. Create the Sheet with the headers above and a few test rows.
  2. Share it (Viewer) with the film-stats-runner SA email from Terraform output.
  3. Create a TMDB account and get an API Read Access Token; add it as a version of tmdb-api-token.
  4. Trigger the scheduler job once manually and check the output.

5. CI/CD

Use whatever the repo already uses (GitHub → Cloud Build, Release Please, etc.). At minimum: lint and run unit tests on PR, terraform fmt/validate/plan on PR, deploy on merge to main.

Website side (separate task, after the pipeline works)

Fetch stats.json from the public bucket URL (at build time for a static site, or at runtime if it’s a client-side dashboard). Render the stats as charts and a recent-films poster grid. Poster images come from https://image.tmdb.org/t/p/w342{poster_path}. Show the TMDB attribution and logo as their terms require.

Phases

  1. Skeleton: Terraform for APIs, SAs, buckets, secret; hello-world function; scheduler hitting it.
  2. Read: Sheets read with validation and warnings; log output.
  3. Enrich: TMDB client plus GCS cache; retry/backoff.
  4. Stats: pure functions with unit tests against fixtures (include edge cases: rewatches, empty months, year boundaries, streak across month end, bad rows).
  5. Publish: write stats.json, set CORS and cache headers, verify from the browser.
  6. Harden: alert if the job fails (log-based alert or Scheduler failure notification), README with the manual steps.

Acceptance criteria

  • Adding a row to the sheet changes stats.json after the next run, with no code changes.
  • A bad row never breaks the run; it shows up in warnings.
  • A TMDB outage doesn’t break the run for already-cached films.
  • No secrets or key files in the repo or Terraform state.
  • terraform apply from a clean project, plus the manual steps above, yields a working pipeline.
  • Unit tests cover stats.py.

That’s essentially it, but one can’t just hand it off without understanding what is being built and how.

A film’s TMDB ID is the key to everything. Titles are ambiguous (there are a lot of films called Troy), but an ID points at exactly one film, and TMDB’s API turns it into a poster, a runtime, genres and a director.

The acceptance criteria were written so they could be checked, not just agreed with:

  • Adding a row to the sheet changes the stats after the next run, with no code changes.
  • A bad row never breaks the run; it shows up in warnings.
  • A TMDB outage doesn’t break the run for films already seen.
  • No secrets or key files in any repo or in Terraform state.
  • Unit tests cover the stats.

Decisions before any code

Claude Code read the spec, then read all three of my repos (Terraform infra, website applications, and the content website itself) before asking anything.

A public data file. It’s a watch log I’m putting on a public web page. A public bucket means the site can fetch it with no credentials at all.

Notes are never published. The notes column is for me. The code doesn’t just leave it out of the output: it never reads the column in the first place.

TV counts too. Each TV row counts as one episode. TMDB labels TV genres differently (“Sci-Fi & Fantasy” rather than “Science Fiction”), so those get split into the film genre names and counted together.

The page

The movies page follows the music page’s rule: no charting library and no client-side fetching. The first version was a single dashboard laid out from the job’s stats.json:

  • headline numbers for films, rewatches, hours, average rating and streaks
  • a grid of posters for the last twelve films
  • films by month, genres, directors, release decades, ratings, day of the week and original language

The charts are plain HTML and CSS. Every value is also available as text, through hover tooltips and tables for screen readers. Posters come from TMDB’s image service, and the TMDB logo and attribution sit at the bottom of every page, as their terms require.

The download script is deliberately suspicious of what it fetches. It checks the file’s schema version, checks that every viewing has a film to go with it, and refuses to replace a file full of films with one that has none. That last rule came from a real incident, described below.

It also leaves the file alone if the only thing that changed is its timestamp. Otherwise the site would rebuild and redeploy every morning for nothing.

The watch log

The dashboard originally showed totals, charts and the last twelve posters, but the films behind them weren’t visible anywhere so I made a few changes after testing it. I’m currently backfilling several years worth of history, which will mean thousands of rows, all exported from other platforms and cleaned up before automatically being added. This meant the full list got its own page rather than a section on the dashboard.

The first version was a simple archive: newest first, grouped by year and then month, with a row of year links at the top that stays pinned as you scroll. Each film showed the date, a small poster, the title and release year, my rating and a link to TMDB. There was no search box; the browser’s own find did that job. Like the dashboard, it was static HTML with no script, and it came from a second file, viewings.json, so the dashboard’s file stayed small however long the log got. The redesign replaced both files, and gave the log search and filters.

I tested it with 3,000 made-up films across eight years before any real backfill. The page comes to about 2.5 MB of HTML, but only about 115 KB once compressed in transit, and it’s ready in about 0.3 seconds on a desktop and about a second on a phone-speed processor. Posters are tiny (92 pixels wide) and only load as you scroll to them.

Scaling for a backfill

The service had been built for dozens of films. A first run over a backfill of thousands would have broken it in two ways:

  • The cache was one file per film, so checking it meant one storage read per title, one after another. For a few thousand titles, that alone takes most of a minute.
  • Every new title needs a TMDB lookup, also one at a time, at about three a second. That’s over ten minutes, and the service gives up after two. Every run would have timed out and emailed me an alert, every day.

Three changes fixed it:

  • The cache became a single index file, read once at the start of a run and written once at the end.
  • Lookups run four at a time, which still stays well under TMDB’s rate limit.
  • Each run does at most 600 lookups. Titles with no cache entry come first, then the stalest refreshes. Anything over the cap still counts in the totals straight away; it just has no poster or genre yet, and gets a single “N titles are waiting for a TMDB lookup” warning instead of thousands of individual ones.
todo = (missing + stale)[:max_fetches]  # new titles first, then the stalest

with ThreadPoolExecutor(max_workers=workers) as pool:
    results = list(pool.map(lookup, todo))

for key, (data, exc) in zip(todo, results, strict=True):
    if data is not None:
        metadata[key] = data
        entries[key] = (data, now)
    elif key not in metadata:  # no stale copy to fall back on
        warnings.append({"tmdb_id": key[1], "reason": str(exc)})

A simulated backfill of 2,000 new titles, with a realistic delay on every TMDB response, catches up in four runs, each comfortably inside the time limit:

Four runs over a 2,000-title backfill: each looks up at most 600 titles, so the titles with metadata go from 600 to 1,200 to 1,800 to 2,000, and each run takes 38 seconds or less of its 120-second limit

The daily schedule would get there in four days. Running the job by hand a few times gets there in a few minutes.

The redesign

The first version answered “what have I watched?”, but every film was a dead end: a poster and a link to TMDB. Once it was live I wanted to click through to a film, see every time I’d watched it, and find my way to other films by the same director or from the same decade. So I wrote a second spec, this time with mockups of the overview, the log and a film page, and gave it to Claude Code with an instruction to build it in stages and stop for review after each one.

The biggest change was underneath. The service had been working out the stats and publishing them ready-made, which meant every new chart needed a change to the service, a deploy, and a day’s wait to see real numbers. Now the service publishes one file, films.json: every viewing, plus one entry per title with the metadata from TMDB. That includes things the first version threw away, such as the cast, the collection a film belongs to and the UK age rating. The website works out every stat at build time, in TypeScript, with its own tests. A new chart is now just a change to the site.

It went in four stages, each a pull request I looked over before the next began:

  1. The data layer. The new file from the service, and the stats code and tests on the site. Dates are handled as plain YYYY-MM-DD strings, and “today” is worked out in UK time, so a build that runs in UTC just after midnight in summer doesn’t think it’s still yesterday.
  2. The log and film pages. The log gained list, grid and table views, search, filters and sorting, with the filters kept in the URL. Without JavaScript it’s still the full list. Every film and show has its own page, with every viewing, my rating against TMDB’s average, the cast, and links to films by the same director, from the same decade and watched around the same time.
  3. The overview. A calendar of every day of the year, month by month cards, favourites and low points, where I disagree most with TMDB’s crowd, and release year against rating.
  4. Browse, years and feeds. A page for every genre, director, decade, rating, country and collection, a review of each year, a public JSON copy of the log and an RSS feed. The old stats.json and viewings.json were retired.

Two rules from the spec shaped every page. Each part of the page declares a minimum amount of data it needs, and hides completely, heading and all, until there’s enough. With a few dozen films, “rated vs the crowd” or “directors seen more than once” would just be empty boxes. And everything had to hold up for the backfill, so each stage was checked against made-up logs of 1,000 and 5,000 viewings as well as the real one. At 5,000 viewings the site builds about 4,700 movie pages in around ten seconds, and once there are more than 150 viewings the log splits into a page per year, so no single page gets too heavy.

Things that went sideways

The alert needed a logging permission. The failure alert watches for a log entry, and Cloud Logging stores that kind of alert as a “notification rule”, which needs a permission that no Monitoring role includes. The first apply failed with a 403 until Terraform’s own account was given the extra role.

The columns were in a different order. The real problem was quieter. When I set up the sheet, I put the date in column A and the title in column B, not the order my own spec’s table laid out, and the code had followed the spec. Every single row failed validation, so the run “succeeded” and published a perfectly valid file with zero films and twelve warnings. The skip-and-warn design did its job, but it also hid how wrong things were.

The fix had three parts:

  • The service now finds columns by their header names, so the order doesn’t matter.
  • If a required header is missing, the run fails loudly instead of publishing an empty file.
  • The website’s download script refuses to overwrite real data with an empty file.

Logs that never arrived. While chasing that, the service’s own log lines were nowhere to be seen. Python buffers its output when it isn’t writing to a terminal, so a short daily job’s logs might never get flushed. One environment variable, PYTHONUNBUFFERED=1, fixed it, and fixed the same latent problem in my music pipeline too.

The file was right; the URL was stale. After a successful run, the public URL kept serving the old, empty file, and could have for up to an hour. That’s the one-hour cache header doing exactly what I asked it to: Google’s edge serves its cached copy until it expires. The download script now adds a throwaway query string to the URL, which gets a fresh copy.

The page didn’t update the next morning. The job ran at 05:00 and published the new numbers, but the site still showed the old ones. GitHub treats a workflow’s schedule as “not before”, not “at”, and this repo’s scheduled runs have started about seven hours late. Nothing was broken; the site just hadn’t pulled yet. Running the workflow by hand caught it up, and the schedule now gets to run when GitHub gets round to it.

The year links slid under the header. On the new log page, the pinned row of year links was set to stick to the top of the screen. But the site’s own header already sticks there, and sits on top, so the year links slid underneath it as soon as you scrolled. They now stick just below the header.

A speed-up that broke the year links. I’d also told the browser it could skip drawing months that were off screen, with a guess at how tall each one was. With smooth scrolling, months were drawn at their real height partway through a jump, so the year links overshot their headings by hundreds of pixels. Even with much better height guesses, it didn’t land reliably. Measured without the trick, the page was still quick, so it went.

Stars that weighed too much. Each row of the redesigned log showed my rating as five small star drawings. Multiplied across a year of rows, those drawings were almost a third of the page. Drawing the stars with a single shape repeated by CSS took the page from 670 KB to 523 KB.

Titles in curly quotes. TMDB’s title for Wuthering Heights comes wrapped in stylised quotation marks, so sorting by title put it ahead of everything starting with A. The title is still shown exactly as TMDB has it, but it now sorts by its first letter or number.

Result

There’s now a movies page, and a watch log behind it, a page for every film, and ways in by genre, director, decade and more or by year. Logging a film is still just a row in a spreadsheet.

Writing the spec first is what made one evening enough for the first version, and the second spec is what made the redesign a series of small, reviewable steps rather than one big rewrite. It gave Claude Code a precise target, a set of checks to test against, and a short list of things to ask me about rather than guess.

There you have it. An interesting and fun little project, and something that I can spend literally hours clicking and browsing through. I had a lot of fun building this.