Build Logs/Building this site · Part 1 of 9
·23 min read
How this site works: the architecture
Part 1 of the build log for this site. Content lives in files, a build turns them into static pages, and only small islands of the page run JavaScript. How a page gets to a reader, where everything lives, what runs on the server and in the browser, how one stylesheet serves two themes, and the checks that stop a bad change from shipping.
This site started as a portfolio with a blog in October 2026. Since then it has grown audio players, moving diagrams, live charts, a SQL practice bank, a real PostgreSQL in the browser and a signed data feed. One long build-log post used to describe all of it. It is now this series, one part per feature, and this first part is the map: how the pieces fit, before the other parts open each one up.
#TL;DR
- The repository is the CMS. Posts, notes, project cards, audio lists, flash cards and recorded database runs are all files in git. There is no database and no admin page.
- Almost every page is built before anyone visits.
next buildreads the files and prerenders the pages to static HTML. One page, the Memex, keeps refreshing after the build: it fetches and verifies signed data at most every 15 minutes. - Most code never reaches the browser. Pages are React Server Components that send HTML. 35 of the 56 components are client components, small islands such as the audio player, the table of contents and the database labs.
- One stylesheet serves two themes. Colours are CSS variables, and the dark theme redefines the variables, not the components.
- The build is the test. A broken post fails
next build, and CI also runs lint, type checks, 13 Node tests, 138 Python tests and a public-safety scan on every push.
#What is the site made of?
| Layer | Choice | Where it is set |
|---|---|---|
| Framework | Next.js 16.4 with the App Router, React 19, TypeScript | package.json, next.config.ts |
| Styling | Tailwind CSS 4, with the typography plugin for post text | src/app/globals.css, tailwind.config.mts |
| Content | MDX and Markdown files, read with gray-matter, rendered by next-mdx-remote | content/, src/lib/blog.ts |
| Markdown plugins | remark-gfm for tables, rehype-slug for heading ids, rehype-highlight for code | src/components/MdxContent.tsx |
| Fonts | Bricolage Grotesque for headings, Atkinson Hyperlegible Next and Mono for text and code | src/app/layout.tsx |
| Storage outside git | Vercel Blob for the Memex files | scripts/upload-second-brain.mjs |
| Hosting and CI | Vercel, and GitHub Actions | .github/workflows/ci.yml |
#How does a page get to a reader?
Request or acknowledgmentData
There are two paths, and the first one carries almost all the traffic.
Build time. A push to main starts a build on Vercel. next build reads every content file, renders every page with the data it needs, and writes the result as static HTML and JavaScript that a CDN serves. A reader asking for a post gets a file that was finished minutes or days earlier. Nothing runs on a server for them.
Request time. The Memex page shows a feed the owner publishes from a separate pipeline, so its data changes without a push. Its data function is marked 'use cache' with a 15-minute revalidation (cacheLife), so the page fetches and verifies the files at most four times an hour and serves the cached result in between.
✅ The production build on 2026-11-18 (re-run after the Memex rename) generated 80 pages (fewer than the 90 of 2026-11-13, because the podcast pages were removed). Its route table marks each route as static (○), partially prerendered (◐, a static shell with a part that is filled in later) or dynamic (ƒ, rendered on each request):
Route (app) Revalidate Expire
┌ ○ / 15m 1y
├ ○ /blog 15m 1y
├ /blog/[slug] 15m 1y
│ ├ ○ /blog/agent-guardrails 15m 1y
│ ├ ○ /blog/inventory-agent 15m 1y
│ └ ◐ [+52 more paths]
├ /blog/series/[series] 15m 1y
│ ├ ○ /blog/series/agentic-ai 15m 1y
│ ├ ○ /blog/series/building-this-site 15m 1y
│ └ ◐ [+4 more paths]
├ ○ /memex 15m 1d
├ ƒ /memex/feed.xml
└ ○ /notes/feed.xml
○ (Static) prerendered as static content
◐ (Partial Prerender) prerendered as static HTML with dynamic server-streamed content
Four things in that table are worth reading closely:
- The dynamic routes (
[slug],[series],[section]) are still prerendered, because each one lists its pages withgenerateStaticParams. A post that isn't returned by it would be rendered on first request instead. - Revalidate 15m comes from the
defaultcache profile, which the cacheLife docs give as stale after 5 minutes, revalidated after 15, and never expiring; the build prints that last one as1y. For pages built from files that only change with a push, it changes nothing in practice: the next push replaces the whole build. /notes/feed.xmlis a route handler, and it is static too: it returns the same XML until the next build./memexis prerendered at build time like everything else, but its owncacheLife(revalidate 15 minutes, expire 1 day) shows in its row, so it is refreshed in the background after the build. Its RSS route,/memex/feed.xml, is dynamic: it runs on each request, reading from the same cached, verified data.
#Where does everything live?
There is no database and no API. The repository is the content management system, and each kind of content is a folder or a file:
content/
blog/ one .mdx file per post (the file name is the URL)
notes/ one .md file per nugget (a date and plain text)
projects/ one .md file per project card
flashcards/ one .json file per home page deck
sql-traces/ generated step-throughs for the SQL posts
db-lab/ recorded database runs for the Database Engineering posts
reads.json hand-picked reads shown on the Memex page
public/images/ diagrams and screenshots, by section / series / post
scripts/ generators, recorders, upload scripts, checks and tests
second-brain/ the Python pipeline behind the Memex page
src/
app/ routes: /, /blog/..., /notes, /projects, /about, /memex
components/ the page parts, and folders for charts, flow, db, sql, home
lib/ readers and parsers: blog, notes, sections, speech, dbLab, flashcards, secondBrain
Two rules keep this manageable. Generated content is never edited by hand: the SQL posts come from scripts/sql-bank/, and the database recordings from scripts/db-lab/ (part 6). Files that change outside a deploy stay out of git: the Memex files live in Vercel Blob, and the site holds only their address and the public key that verifies them (part 8).
#From a file to a page
DataMetadataRequest or acknowledgment
A post goes through three steps, all at build time:
- Read.
getAllPosts()listscontent/blog/*.mdx, reads each withfs, andgray-mattersplits the frontmatter from the body.parsePostturns that into aBlogPost, with fallbacks so a bad value never breaks the build (part 2 explains it). - Ask. Each page calls a small query:
getAllPosts,getPostsBySection,getPostsBySeriesorgetPostBySlug. - Render. The post page hands the body to
MdxContent, which compiles the MDX on the server withnext-mdx-remote/rsc. No MDX compiler is shipped to the browser.
MdxContent is also where Markdown turns into the site's design. It replaces plain elements with components:
| Element | What replaces it |
|---|---|
h2, h3, h4 | The heading plus a hover # link, using the id rehype-slug made |
pre | A code block with a language label and a Copy button |
table | The table inside a scrolling wrapper, so wide tables don't break the page |
img | A local SVG is read from disk and inlined, so the theme can recolour it; a .flow.json beside it adds a message animation (part 5) |
| Named tags | <Callout>, five live charts, <DataTrace>, and 19 database components such as <PgPlayground> and <TxnTheater> |
The table of contents has one subtle job: its links must point at the ids the page really has. getHeadings() parses the post with remark-parse and makes ids with the same slugger rehype-slug uses, walking every heading in order, so two headings with the same text get the same -1 suffix in both places. The client component on top adds scrollspy, a reading-progress bar and a phone menu.
#Which code runs in the browser?
In the App Router every component is a Server Component unless its file starts with 'use client'. A server component can read files and runs once, at build time, so it is where all the content reading happens. A client component is also rendered to HTML on the server, then hydrated in the browser, which attaches its event handlers and state.
✅ 35 of the site's 56 component files are client components. That sounds like a lot, but most are small, and they all sit at the edges: the audio players, the table of contents, the theme toggle, the copy button, diagram motion, the five live charts, the flash cards and the database labs. The pages, MdxContent and every reader in src/lib stay on the server.
Hydration has one strict rule: the HTML the server produced and the first render in the browser must match. Two patterns keep this site inside it:
- Browser facts come from
useSyncExternalStore. Whether the browser can speak, which voices it has, or whether reduced motion is on are facts about the outside world.useSyncExternalStoretakes a server value (nothing, or "off") and a browser value, so the first render matches and the real value arrives right after. - Computed numbers are rounded. 📜 The 2026-11-05 review found hydration errors on four database posts:
Math.cos,Math.sinandMath.log10gave a different last digit in Node and in the browser, such as97.9547177313654against97.95471773136542. Chart and ring coordinates are now rounded to two decimals (part 5).
#How does one class work in two themes?
The colours are CSS variables in globals.css: --paper, --card, --ink, --accent and so on, with light values on :root. The dark values apply in two cases: when the system prefers dark and no theme is chosen (:root:not([data-theme="light"])), and when the reader picks dark (:root[data-theme="dark"]). Tailwind's colour names (ink, card, accent) point at those variables, so a component writes text-ink once and it is right in both themes. No component has a dark: variant.
The saved choice is applied before the first paint by a one-line inline script in the <head>, so a reader who chose dark never sees a flash of light:
const themeScript = `try{var t=localStorage.getItem("theme");if(t==="light"||t==="dark")document.documentElement.setAttribute("data-theme",t)}catch(e){}`;
The try matters: reading storage can throw when cookies are blocked, and the page must still render. Diagrams follow the same idea with their own set of variables, which part 5 covers.
#What stops a bad change from shipping?
Request or acknowledgment
The first guard is the build itself: next build type-checks the code and renders every page, so a post with broken MDX, a missing recording or a malformed flash card fails it. Several readers fail on purpose rather than show something wrong: labItem throws when a post points at a recording that doesn't exist, and the flash card reader rejects a deck that doesn't have exactly 50 cards, a card without four different options, an answer index outside 0 to 3, or a card that points at a post that doesn't exist.
On top of that, GitHub Actions runs three independent jobs on every push and pull request. I re-ran each locally:
node scripts/check-public-safety.mjs
npm run test:second-brain
cd second-brain && python -m pytest -q
Public-safety check passed (702 files).
ℹ tests 13
ℹ pass 13
ℹ fail 0
138 passed in 11.23s
The public-safety job exists because the repository is public and now holds a pipeline that touches private data. It fails if git tracks a forbidden path (a .env file, a database, a key, the pipeline's data/ folder) or a line that looks like a secret or a personal home path. It prints the file and line, never the secret. Part 8 explains why the pipeline lives in this repository at all.
#Things that can trip you up
- Reading memory instead of the bundled docs. Next.js 16 changed caching and params. Check
node_modules/next/dist/docs/first. - Editing a generated file. The SQL posts and the database recordings are rewritten by their generators. Change the spec and rebuild.
- A server and browser that disagree. Anything random, time-based, locale-based or computed with floating point can break hydration. Round it, or render it only in the browser.
- A colour outside the palette. It has no dark-mode rule and stays the same colour in both themes.
- Trusting the dev server. It caches modules between edits. A result that matters should be checked on a production build (
next buildthennext start), which is what the tests in this series used.
#Reproduce this yourself
Each step is marked with how it was checked.
- ✅ Install and run.
npm install, thennpm run dev. Thepredevscript copies PGlite intopublic/pglite/first (part 7). - ✅ Build like production.
npm run build, thennpx next start, and openhttp://localhost:3000. The route table above is the end of the build output. - ✅ Run the checks. The three commands in the CI section. The Python tests need the pipeline's environment:
python -m venv .venv, activate it,pip install -e ".[dev]"insidesecond-brain/(Python venv docs). - 📘 Find a page's code. Routes are folders under
src/app/, so/blog/series/building-this-siteissrc/app/blog/series/[series]/page.tsx. Readers are insrc/lib/, and components insrc/components/. - 📘 Read the writing guide.
docs/mdx-formatting-guide.mdcovers frontmatter, callouts, images, the database components and the MDX traps.
#Summary
The site is files in and static pages out. Content lives in the repository, next build reads it with fs and prerenders every page, and a CDN serves the result. Server components do all the reading and send HTML; 35 small client components add behaviour where it is needed, under the rule that their first render must match the server's. One set of CSS variables serves both themes, and the build, three CI jobs and a public-safety scan stop most bad changes before a reader can see them. The parts that follow open up each feature.
#Key takeaways
- A static build with a few client islands is fast, cheap and hard to break.
- One page that needs fresh data can be cached per page with
'use cache', without making the rest dynamic. - Keep generated content generated, and keep big files out of git.
- Make readers fail the build on bad data, rather than render it.
#Concepts at a glance
| Term | In one line |
|---|---|
| Prerendering | Rendering a page to HTML at build time, so a request only fetches a file |
| Partial prerendering | A static shell served at once, with a dynamic part filled in later (◐ in the build output) |
generateStaticParams | Lists the values of a dynamic route to prerender |
| Server Component | Runs on the server, can read files, sends only HTML |
| Client Component | Marked 'use client'; rendered on the server, then hydrated in the browser |
| Hydration | Attaching event handlers and state to server HTML; the first render must match |
'use cache' | Caches a function's result, with a lifetime set by cacheLife |
| Theme tokens | CSS variables that the dark theme redefines, so classes never change |
| Public-safety check | A CI script that fails if a private file or secret is tracked |
#Test yourself
A post is added but not returned by generateStaticParams. What happens?
It is not prerendered. The route still exists, so the page is rendered on its first request instead. Returning every slug keeps every post a static file.
Why does the Memex page fetch at request time when nothing else does?
Its data is published from a separate pipeline and changes without a push, so a build-time snapshot would go stale. A 15-minute 'use cache' keeps it fresh without fetching on every visit.
Why can't a client component use Math.random() in its first render?
The server and the browser would produce different values, the HTML wouldn't match the first browser render, and React would report a hydration mismatch. Compute it on one side only, or after hydration.
How does text-ink become a different colour in dark mode without a dark: variant?
Tailwind maps ink to a CSS variable, and the dark theme redefines that variable. The class stays the same; its value changes.
What does the public-safety check protect against that the build doesn't?
A build passes with a database file, a token or a private key committed. The safety check fails on those paths and on secret-shaped lines, because the repository is public.
#Update log
Every change to the site is logged here under the day it was made, oldest first. New updates go in a new dated heading at the bottom.
#2026-10-29
| Type | Change |
|---|---|
| Feature | Sections, series and tags, with /blog/topic and /blog/series pages, "Part N of M" and previous and next links |
| Change | LLM Architectures posts renamed to readable slugs, with permanent redirects. Images moved to public/images/<section>/<series>/<post>/ |
| Feature | Listen to this post audio player: browser text-to-speech, reads prose, skips code and tables with a spoken note, highlights the paragraph, speed and voice controls |
| Fix | Audio did not play on mobile Safari and Chrome. Four causes fixed, a watchdog added, and the bar lifted above the iPhone home indicator |
| Feature | Diagram reading. The player reads each image's alt text, with a setting to turn it off |
#2026-10-30
| Type | Change |
|---|---|
| Feature | AI podcast versions. A post can carry an m4a made with NotebookLM, listed in content/audio.json, with its own player bar |
| Feature | Notes. Short, dated, plain-text entries on /notes, in a scrolling box on the home page, and as an RSS feed |
| Change | Audio moved out of git to Vercel Blob, re-encoded to mono AAC at 64 kbps |
#2026-11-03
| Type | Change |
|---|---|
| Feature | Diagram motion. Diagrams fade their parts in as they scroll into view, off with reduced motion |
| Feature | Live charts. Five charts in three posts became interactive, with sliders and a sentence that restates the numbers |
| Content | Data Engineering SQL series. A six-post, 92-question practice bank generated from real DuckDB runs |
| Feature | Data traces. A step-through of each SQL answer, built from the same runs |
#2026-11-05
| Type | Change |
|---|---|
| Content | Database Engineering series. Fourteen posts on database internals |
| Feature | Recorded demos from real PostgreSQL, MySQL, MongoDB, Redis and Memcached in Docker |
| Feature | Live PostgreSQL in the browser with PGlite, loaded only when a reader presses Run |
| Feature | Database simulators and flash card groups on the home page |
#2026-11-13
| Type | Change |
|---|---|
| Feature | Second brain page (beta). A curated reading feed published as signed files and verified by the site before it renders anything |
| Content | This series. The single build-log post became nine parts, one per feature, with the checks re-run. The old address redirects to the series page |
| Change | Podcasts moved to their own pages. /podcasts lists the episodes and each has a page with one shared player. Every post keeps the browser voice and links to its episode, so the two players never share a screen (part 3) |
| Fix | Audio kept playing after you left its page, because Next hides a page instead of removing it. The podcast player now pauses when its page is hidden, and the browser voice resets its state (part 3) |
#2026-11-17
| Type | Change |
|---|---|
| Content | A bug-fixing agent, part 9 of Agentic AI, with a project card linking its GitHub repo |
| Feature | Titled code blocks and output panels. A fence can name its file and lines with title="…", and output marks printed output and joins it to the command above. The titles already written in this series' posts now show |
#2026-11-18
| Type | Change |
|---|---|
| Content | Agentic AI replanned: 9 posts to 14. New posts on retrieval, long-term memory, observability, guardrails and an inventory agent; every lab re-run on Groq and on Claude |
| Feature | An updated callout for something that changed after the course a post follows, and a script that writes the Agentic AI series list from seriesOrder |
| Removal | AI podcasts removed. The /podcasts pages, the shared player, the episode link on each post, content/audio.json, the upload scripts and the 14 recordings in Vercel Blob are gone; part 3 keeps a short history. Every post keeps the browser voice |
| Content | Inventory Agent project card, linking its GitHub repo |
| Change | Nuggets moved into the hero. The header lost its Nuggets link; the nuggets now scroll in a card under the intro on the home page, filling the space beside the flash cards and the chart, and the card links to /notes. The phone header no longer overflows (part 4) |
| Change | Second brain renamed to Memex. The page moved to /memex, with a line at the top on where the name comes from; /second-brain and its feed answer 308 to the new addresses. Code names (second-brain/, SECOND_BRAIN_*, the Blob folder) are unchanged (part 8) |
#What's next
- Tags are still free-form and a little inconsistent. A small fixed list would make them a better filter.
- No sitemap, search or RSS feed for blog posts yet. The nuggets and the Memex already have feeds.
- The dev-only
instantvalidation error on post pages is unresolved (see above). - The browser voice can be sent a sentence longer than its 180-character target (part 3 shows the measurement).
#Sources
- Next.js: Server and Client Components, generateStaticParams, Route Handlers, cacheComponents, cacheLife, instant
- React: useSyncExternalStore and hydration mismatches
- next-mdx-remote
- Tailwind CSS: the
@configdirective, which loadstailwind.config.mts - GitHub Actions documentation
- Python: venv
- The repository and its writing guide,
docs/mdx-formatting-guide.md