Skip to content
All projects
In progress

Portfolio

This site. Every piece of content on it is a row in Postgres behind row-level security — hard-coded JSX would have been less work and would have proven nothing.

On this page
Ended
Ongoing
Type
project

Built with

The problem

A portfolio that claims production thinking should survive someone actually reading its source. Hard-coded JSX for every project and article would have been less work, and would have demonstrated nothing beyond the ability to write JSX. Every real decision in this codebase — RLS policies, an admin that writes through Server Actions, a visit counter that lives in Postgres instead of a third-party service — exists because the content genuinely lives in a database, not as a show of effort.

Architecture

Browser
  │
  ├─ every request ── middleware ── service-role client ── +1 site_config.visit_count
  │
  ├─ public routes ── Server Components ── anon Supabase client ── Postgres
  │                   ISR, revalidate 300                             │
  │                                                                RLS: state = 'published'
  │
  └─ /admin ── middleware (session refresh + redirect)
               └─ Server Actions ── session-bound client ── Postgres
                                                              │
                                                           RLS: email ∈ admin_allowlist

Public pages use an anonymous Supabase client with no cookie, so responses stay cacheable. Admin pages carry the signed-in user's session, so Postgres evaluates every RLS policy as that specific user, not as an app-level role the client could spoof.

Decisions

Authorization has three layers, and only one is real. Middleware redirects anonymous requests away from /admin — convenience. requireAdmin() re-checks server-side in every admin page and Server Action — defence in depth. The actual control is a Postgres RLS policy joining an admin_allowlist table: delete the first two layers entirely and an anonymous client still cannot write a row. A security-check script asserts this in both directions — anon refused writes and drafts, the signed-in admin granted exactly what the UI needs — and exits non-zero on any failure, so the claim is checked, not asserted.

The visit counter lives in Postgres, not a third-party service, after starting somewhere else. The first version used Upstash Redis specifically because Edge middleware needs a fetch-based client, not a TCP one. It moved to a single site_config row once a usage-limit concern on the free Redis tier came up — reusing a table that already existed rather than adding a new one, at the cost of an explicit, documented non-atomic read-then-write (fine at personal-portfolio traffic; the upgrade path if that ever matters is a Postgres RPC, not a new service).

One generic admin form system, not N bespoke ones. A single saveRow/deleteRow/setState/reorder set of Server Actions, driven by a declarative Field[] per table, runs every content editor in /admin — projects, articles, experiments, technologies, sections, diagrams, milestones. The one deliberate exception is tagging a project's technologies, a pure many-to-many join table with a composite key the generic id-based actions can't address, which got its own small addProjectTech/removeProjectTech pair instead of being forced into the generic shape.

Challenges

A long next dev session eventually corrupts its own hot-reload state. After dozens of live edits in one sitting, the dev server threw two different cache-corruption symptoms in the same session — missing static chunks from a stale webpack cache, then a cookies() called outside a request scope error from a desynced module cache during a Server Action. Neither was a real code bug; a full production build plus next start (no hot-reload state to corrupt) made the whole class of failure go away, which was also the fastest way to tell a transient dev artifact apart from an actual regression.

Schema assumptions have to be verified against the live database, not inferred from a type file. The TypeScript types implied site_config and project_milestones had only nullable columns; a real probe insert against the actual Supabase project surfaced a NOT NULL constraint on label in both tables that the types didn't capture. Catching that before shipping the write path — rather than after a user's first save failed — meant testing against the real database early, not trusting the inferred shape.