L1 · DESIGN projects

cat projects/waltersphere-firebase-to-self-hosted-migration/README.md

WalterSphere: Firebase to self-hosted migration

My portfolio moved from a managed platform to my own homelab: a new data layer, a security rebuild, CI with image scanning, and a staged cutover with no data lost.

Role
Engineer, end to end
Layers
L1 · DESIGN Infrastructure & DevOpsL2 · BUILD Software DevelopmentL3 · RUN IT Support & Systems AdministrationL4 · DECIDE Data & Business Analytics
FIG. 01cat problem.md

Problem

The site ran on Firebase with security rules that let anyone register as an admin, an open image-upload preset, public AI endpoints with no limits, and content stored as HTML. I didn’t control the platform, and the site described me as only a software engineer.

FIG. 02cat constraints.md

Constraints

  • Keep the old site live until the new one was verified.
  • One small server at home, no inbound ports, a DMZ that can't reach my private network.
  • Visitor comments and contact data had to move without loss and without leaking.
  • Every dependency at least two weeks old unless a security fix needed a newer one.
FIG. 03cat approach.md

Approach

I rebuilt the data layer on PostgreSQL with typed queries and versioned migrations, replaced the admin with layered authentication, moved content to sanitised Markdown, and built CI that tests and scans every image. Then I deployed it to a DMZ host behind an outbound tunnel and cut over through a protected staging site.

  • Data: exported Firestore read-only, transformed it into relational tables (slugs, tags, comments as rows), and validated every row with the same rules the admin uses. Content fixes live in a reviewed file in git.
  • Security: admin behind an access gateway, then GitHub sign-in limited to one numeric ID, then a server-side check on every action. Public forms are bot-checked, rate-limited and store only a keyed hash of the IP address.
  • Browser: a nonce-based Content Security Policy on every page, no third-party scripts, fonts or images.
  • Delivery: CI runs unit, database and browser tests, a dependency audit and an image scan; images are published by commit and deployed by digest, never "latest".
  • Cutover: staging behind access control, a seed verified table by table, a restore test, a rollback rehearsal, then a one-line route change.
FIG. 04cat decisions.md

Decisions

  1. Rebuild instead of patching Firebase. The security holes were in the design, not in a few rules.
  2. Manual, pull-only deploys. CI can never reach the server; deploying is one command I run.
  3. Production is the source of truth for content after launch. The import never runs against production; admin edits are exported back into git.
FIG. 05cat what-went-wrong.md

What went wrong

  • A page lost its preview after client-side navigation. A security exception scoped to one route didn't survive navigating in from another page. Fix: one policy for every page, and browser tests that navigate in, not just load pages directly.
  • Forms failed on staging only. The bot check accepted tokens from the live domain only, and nothing logged why. Fix: an explicit list of allowed domains and a logged reason for every refusal.
  • A security advisory landed days before launch. The framework release I'd pinned had a critical issue. Fix: a documented exception to my two-week rule, and an audit gate that fails closed with expiring, per-advisory exceptions.
FIG. 06cat outcome.md

Outcome

Live on my own hardware with no data lost, no audit exceptions open, a strict Content Security Policy on every page, nightly backups with a tested restore, and one-command rollback.

FIG. 07cat stack.md

Stack

Next.js · TypeScript · PostgreSQL · Drizzle · Docker · GitHub Actions · Trivy · Cloudflare Tunnel, Access & Turnstile · Resend