Architecture documentation & production-readiness plan
Status: ARCHITECTURE.md drafted (sections 1–4 + open questions). Phase 1 audit not started. Audience: Adam (owner), primary coding agent, future contributors. Repo: Digital Walls (digital-sanctuary-mvp) — Vercel + Supabase + GitHub.
---
Goal
1. Capture current-state architecture in a single canonical doc (docs/ARCHITECTURE.md) without mixing audit findings, risks, or roadmap. 2. Execute Adam’s four-phase production-readiness program using separate, linked documents. 3. Reuse and reconcile existing docs under docs/ instead of duplicating them.
---
Document map (keep ARCHITECTURE.md clean)
| Document | Purpose | Phase | Notes |
|---|---|---|---|
| `docs/ARCHITECTURE.md` | As-built system: topology, request flow, data model summary, environments | Foundation | Factual only; links to code and migrations |
| `docs/PRODUCTION_AUDIT.md` | Phase 1 findings: gaps, risks, severity × effort | Phase 1 | Living doc until audit sign-off |
| `docs/PRODUCTION_STANDARD.md` | Phase 2: lightweight target standard + prioritized backlog | Phase 2 | Depends on audit |
| `docs/ENGINEERING_RULES.md` | Phase 3: human-readable engineering contract | Phase 3 | Companion to .cursor/rules |
**.cursor/rules/*.mdc** | Phase 3: enforceable Cursor rules (PRs, migrations, RLS, tests) | Phase 3 | Short, actionable |
| `docs/OPERATIONS_CHECKLIST.md` | Phase 4 end state: configured / manual / outstanding | Phase 4 | Simple checklist Adam requested |
Existing docs — role after this work
| Existing file | Relationship |
|---|---|
docs/BACKEND_OPERATIONS.md | Deep ops/deploy; ARCHITECTURE.md summarizes and links here for runbooks |
docs/DATA_MODEL.md | Aspirational / PRD-era model; ARCHITECTURE.md describes implemented schema (server/migrations/*) |
docs/SUPABASE_AUTH.md | Auth setup runbook; architecture doc references auth boundary only |
docs/FRONTEND_FLOWS.md | UX contracts; architecture doc references pages/API touchpoints |
docs/MVP_IMPLEMENTATION_CHECKLIST.md | Historical checklist; audit may supersede open items |
README.md | Quick start; link to ARCHITECTURE.md once published |
---
docs/ARCHITECTURE.md outline (first sections to write)
These sections match Digital Walls’ actual stack and pay off immediately for onboarding and deploy debugging.
1. Deploy topology
- Vercel:
@vercel/nodehandler from rootserver.js;vercel.jsonroutes/(.*)→server.js; build runsscripts/prepare-studio.mjs. - Static vs compute: Browser assets in
public/(CDN-friendly); API + HTML shell served by Node handler. - Alternative: Self-hosted Docker (
docker/Dockerfile) — long-lived Node + SQLite on/data(not Vercel path). - Supabase: Auth (REST via
server/supabase-auth.js); Postgres for durable data on Vercel; no Supabase Storage for wall images today (bytes in DB). - Postgres connectivity:
resolveDatabaseUrl()— transaction pooler:6543upgraded to session pooler:5432on Vercel; direct/non-pooling for local CLI migrations only. - Ephemeral Vercel disk:
/tmp/digital-walls.sqliteonly when Postgres unset; account routes 503 — guest mode still works.
2. Request flow
ASCII or mermaid diagram:
Browser (public/*.js, HTML)
→ Vercel → server.js → createApp (server/server.js)
→ Accounts (Supabase session cookies) | Walls | Discover | Uploads
→ openStore → PostgresStore | SqliteStore
Cover: CSRF-ish guards (Origin, Sec-Fetch-Site, X-Wall-Request), session cookie, share-token read paths, explore/votes (Discover).
3. Data model (implemented)
- Source of truth:
server/migrations/(SQLite) andserver/migrations/postgres/(Postgres). - Core entities:
users(+supabase_id),sessions,boards,board_items, image blobs, explore/votes tables from003_*/ postgres002_*. - Explicit note: authorization is application-layer, not Supabase RLS (Postgres is accessed with server credentials only).
4. Environments
| Surface | Database | Auth | Origin |
|---|---|---|---|
| Local dev | SQLite data/walls.sqlite | Supabase optional; local-test auth in tests | http://127.0.0.1:4173 |
| Vercel preview | Postgres if integration wired; else ephemeral | Optional on preview | VERCEL_URL / request host |
| Vercel production | Postgres (required for accounts) | Supabase required for signup/login | APP_ORIGIN or production URL |
| Docker prod | SQLite on volume | Supabase required (requireSupabase) | HTTPS APP_ORIGIN |
Env vars that matter: APP_ORIGIN, SUPABASE_URL, SUPABASE_PUBLISHABLE_KEY, POSTGRES_URL / DATABASE_URL, NODE_ENV, PORT, DATABASE_PATH (non-Vercel).
Safe to ignore (unless tooling): Prisma-style URLs if present in dashboard but unused; SUPABASE_ACCESS_TOKEN (scripts only); service role (test scripts only).
---
Phase alignment (Adam’s email)
Phase 1 — Audit (docs/PRODUCTION_AUDIT.md)
Structured passes; each finding: severity (S0–S3), effort (S/M/L), evidence (file/link).
| Workstream | Repo starting point | Likely focus |
|---|---|---|
| Architecture & deps | This plan + code | Node 24, postgres, sharp; no framework; dual store |
| Git & Vercel | vercel.json, no .github/ CI yet | Branch strategy, preview vs prod env vars |
| Env separation | server/runtime-config.js, .env.example | Preview boots without Supabase; prod expectations |
| Supabase | supabase/templates/, app migrations only | No `supabase/migrations` or RLS in repo — gap vs checklist |
| Testing | npm test, npm run test:e2e, Playwright | Coverage of auth, 409 revision, explore |
| Observability | Console errors in handler | No structured logging/monitoring |
| Secrets | .env.example, docs | Integration vs manual vars |
| DR | server/backup.js (SQLite); Supabase for Postgres | Vercel-specific runbook |
| Performance/cost | Images in DB, Sharp pipeline | Pooler choice, image size limits |
Deliverable: ranked findings table + “accepted risks” section for product sign-off.
Phase 2 — Production standard (docs/PRODUCTION_STANDARD.md)
Lightweight defaults (prefer existing tools):
- PR + feature branch for meaningful changes (
cursor/*-b53fpattern for agents). - CI:
npm run check,npm test, optional e2e on main/PR. - Migrations: versioned SQL in
server/migrations/postgres/applied on boot; add explicit “migration review” rule. - AuthZ: document app-layer rules; decide whether Supabase RLS is in scope or explicitly out of scope for v1.
- No silent production changes without approval (already in agent instructions).
Phase 3 — Engineering rules
.cursor/rules/production.mdc(or split by concern): PRs, migrations, RLS verification when added, tests, minimal diffs, error handling, task summary template.docs/ENGINEERING_RULES.md: same content in prose for non-Cursor readers.
Phase 4 — Safeguards (incremental, after approval)
Examples (not started in plan mode):
- GitHub Actions workflow for check + unit tests.
- Health/version endpoints already exist — document alerting hooks.
- Supabase auth URL script + template sync documented in CI optional job.
- Explicitly out of bounds without approval: prod data changes, destructive migrations, credential rotation, Vercel prod config changes.
Final: `docs/OPERATIONS_CHECKLIST.md` — configured / manual / outstanding.
---
Execution order (recommended)
flowchart LR
A[Plan sign-off] --> B[ARCHITECTURE.md draft]
B --> C[Phase 1 audit doc]
C --> D[Review findings with Adam]
D --> E[PRODUCTION_STANDARD.md]
E --> F[ENGINEERING_RULES + Cursor rules]
F --> G[Approved Phase 4 items]
G --> H[OPERATIONS_CHECKLIST.md]
1. Sign off this plan (scope, doc names, RLS in/out of scope). 2. Draft `ARCHITECTURE.md` from code + existing ops docs (~1 focused pass). 3. Parallel audit workstreams into PRODUCTION_AUDIT.md (can split by agent/thread). 4. Review → standard → rules → implement approved safeguards.
---
Open decisions (need product/engineering alignment)
1. Supabase RLS & Storage: MVP checklist still lists RLS/storage as open; app today uses server-side Postgres with app auth. Standard path: document as intentional for v1, or plan RLS migration? 2. Canonical production host: Vercel production URL vs custom domain — drives APP_ORIGIN and Supabase redirect URLs. 3. CI scope: Unit tests only on every PR vs full Playwright (slower, flakier). 4. Docker vs Vercel: Is Docker a supported production target alongside Vercel, or dev/self-host only?
---
Success criteria
- New engineer can read `ARCHITECTURE.md` and explain deploy topology, one API save path, and env vars in <30 minutes.
- `PRODUCTION_AUDIT.md` has a ranked list with no “unknown” for auth, data store, or deploy entrypoint.
- Phase 3 rules exist in repo and match how the agent already works on Cloud Agents.
- Phase 4 checklist is honest about manual Supabase/Vercel dashboard steps.
---
Next step (after you choose)
| Option | Action |
|---|---|
| A | Write docs/ARCHITECTURE.md (sections 1–4 only) on this branch |
| B | Start Phase 1 audit (PRODUCTION_AUDIT.md) in parallel threads |
| C | Adjust doc map / phases first (comment on open decisions) |
| D | A + B together (architecture first, then audit references arch) |
Recommended: D — architecture doc first (~half day of agent time), then audit with stable vocabulary.