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)

DocumentPurposePhaseNotes
`docs/ARCHITECTURE.md`As-built system: topology, request flow, data model summary, environmentsFoundationFactual only; links to code and migrations
`docs/PRODUCTION_AUDIT.md`Phase 1 findings: gaps, risks, severity × effortPhase 1Living doc until audit sign-off
`docs/PRODUCTION_STANDARD.md`Phase 2: lightweight target standard + prioritized backlogPhase 2Depends on audit
`docs/ENGINEERING_RULES.md`Phase 3: human-readable engineering contractPhase 3Companion to .cursor/rules
**.cursor/rules/*.mdc**Phase 3: enforceable Cursor rules (PRs, migrations, RLS, tests)Phase 3Short, actionable
`docs/OPERATIONS_CHECKLIST.md`Phase 4 end state: configured / manual / outstandingPhase 4Simple checklist Adam requested

Existing docs — role after this work

Existing fileRelationship
docs/BACKEND_OPERATIONS.mdDeep ops/deploy; ARCHITECTURE.md summarizes and links here for runbooks
docs/DATA_MODEL.mdAspirational / PRD-era model; ARCHITECTURE.md describes implemented schema (server/migrations/*)
docs/SUPABASE_AUTH.mdAuth setup runbook; architecture doc references auth boundary only
docs/FRONTEND_FLOWS.mdUX contracts; architecture doc references pages/API touchpoints
docs/MVP_IMPLEMENTATION_CHECKLIST.mdHistorical checklist; audit may supersede open items
README.mdQuick 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

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)

4. Environments

SurfaceDatabaseAuthOrigin
Local devSQLite data/walls.sqliteSupabase optional; local-test auth in testshttp://127.0.0.1:4173
Vercel previewPostgres if integration wired; else ephemeralOptional on previewVERCEL_URL / request host
Vercel productionPostgres (required for accounts)Supabase required for signup/loginAPP_ORIGIN or production URL
Docker prodSQLite on volumeSupabase 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).

WorkstreamRepo starting pointLikely focus
Architecture & depsThis plan + codeNode 24, postgres, sharp; no framework; dual store
Git & Vercelvercel.json, no .github/ CI yetBranch strategy, preview vs prod env vars
Env separationserver/runtime-config.js, .env.examplePreview boots without Supabase; prod expectations
Supabasesupabase/templates/, app migrations onlyNo `supabase/migrations` or RLS in repo — gap vs checklist
Testingnpm test, npm run test:e2e, PlaywrightCoverage of auth, 409 revision, explore
ObservabilityConsole errors in handlerNo structured logging/monitoring
Secrets.env.example, docsIntegration vs manual vars
DRserver/backup.js (SQLite); Supabase for PostgresVercel-specific runbook
Performance/costImages in DB, Sharp pipelinePooler 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):

Phase 3 — Engineering rules

Phase 4 — Safeguards (incremental, after approval)

Examples (not started in plan mode):

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

---

Next step (after you choose)

OptionAction
AWrite docs/ARCHITECTURE.md (sections 1–4 only) on this branch
BStart Phase 1 audit (PRODUCTION_AUDIT.md) in parallel threads
CAdjust doc map / phases first (comment on open decisions)
DA + B together (architecture first, then audit references arch)

Recommended: D — architecture doc first (~half day of agent time), then audit with stable vocabulary.