Skip to content
HarshkumarG007Public

About

Privacy-first digital sanctuary for two, built with React, Fastify, WebCrypto E2EE, WebAuthn passkeys, PostgreSQL RLS, deterministic Three.js, secure media pipelines, and AWS infrastructure.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

32 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Slow Light โ€” A Hardware-Bound Cinematic Sanctuary

Slow Light is a heavily fortified, Zero-Knowledge web sanctuary engineered exclusively for two individuals. Built on the principles of Progressive Device-Bound Session Credentials (DBSC), WebCrypto End-to-End Encryption (E2EE), and Deterministic WebGL Rendering, it represents a masterclass in secure systems design, applied cryptography, and resilient distributed architecture.

Designed under strict "MAANG-level" engineering tenets, this project employs aggressive fail-closed security mechanisms, PostgreSQL Row-Level Security (RLS), and a strictly decoupled front-end architecture that isolates DOM state from GPU render loops.


๐Ÿ—๏ธ System Architecture & Data Flow

Slow Light operates as a tightly integrated monorepo encompassing a static SPA, a Fastify-driven API, a background media processing pipeline, and infrastructure-as-code (IaC).

Overarching Cloud Architecture

                                 [ Client Device ]
                                 (Passkey / DBSC)
                                        |
                            +-----------+-----------+
                            |                       |
                    [ CloudFront CDN ]        [ AWS WAF / ALB ]
                            |                       |
                    +-------+-------+               |
                    |               |               |
               [ S3 SPA ]      [ S3 Media ]    [ Fastify API ] (ECS Fargate)
             (Static Vite)   (Signed URLs)          |
                                                    +--- [ RDS PostgreSQL ] (RLS Enforced)
                                                    |
                                                    +--- [ AWS KMS ] (Envelope Cryptography)
                                                    |
                                                    +--- [ Media Worker ] (ECS Fargate)
                                                         (ClamAV, sharp, FFmpeg)

Component Breakdown & Interconnectivity

  1. The Client (Vite + React 19 + Three.js): The frontend is a strictly sandboxed React application. State transitions are governed by mathematically verifiable XState finite state machines (preventing impossible UI states). The 3D Engine (Vanilla Three.js) is completely decoupled from Reactโ€”they communicate exclusively via a typed pub/sub event bus. This prevents React's reconciliation cycle from causing garbage-collection (GC) stutters in the 60fps WebGL render loop.
  2. The API Gateway (Fastify 5): A high-throughput API layer enforcing strict input validation via Zod. It is entirely stateless, utilizing encrypted secure cookies anchored to hardware-bound session identifiers (DBSC).
  3. The Storage Layer (PostgreSQL + RLS): The database utilizes FORCE ROW LEVEL SECURITY tied to Fastify's transaction-local variables (SET LOCAL app.user_id). Even if a SQL injection vulnerability were introduced, the database driver physically rejects queries outside the authenticated user's scope.
  4. The Cryptographic Engine (KMS + E2EE): Textual memories are secured using AES-256-GCM envelope encryption (via AWS KMS) for data-at-rest. For absolute privacy, Phase 12 introduced a True E2EE WebCrypto Vault, leveraging ECDH P-256 key agreement and HKDF-SHA256 for zero-knowledge client-side decryption.

๐ŸŒณ Detailed Repository Structure

The monorepo is managed via pnpm workspaces, establishing strict boundaries validated by dependency-cruiser in CI/CD.

slow-light/
โ”œโ”€โ”€ apps/
โ”‚   โ”œโ”€โ”€ api/                     # Backend Microservice (Fastify, Drizzle, KMS)
โ”‚   โ”‚   โ”œโ”€โ”€ src/auth/            # DBSC Engine, Passkey Registration, Session Mgmt
โ”‚   โ”‚   โ”œโ”€โ”€ src/crypto/          # AES-256-GCM Envelope Encryption & Keyring
โ”‚   โ”‚   โ”œโ”€โ”€ src/db/              # Drizzle Schema with RLS FORCE definitions
โ”‚   โ”‚   โ””โ”€โ”€ src/routes/          # Zod-validated API endpoints
โ”‚   โ”œโ”€โ”€ web/                     # Frontend SPA (React, XState, Three.js)
โ”‚   โ”‚   โ”œโ”€โ”€ src/app/             # XState Machine defining the 15-state UI flow
โ”‚   โ”‚   โ”œโ”€โ”€ src/lib/             # Client-side WebCrypto (E2EE Vault, DBSC vault)
โ”‚   โ”‚   โ”œโ”€โ”€ src/three/           # Deterministic WebGL Engine (Zero React coupling)
โ”‚   โ”‚   โ””โ”€โ”€ src/components/      # CSS Modules + React DOM layer
โ”‚   โ””โ”€โ”€ worker/                  # Asynchronous Media Pipeline
โ”‚       โ””โ”€โ”€ src/                 # FFmpeg HLS chunking, sharp image pyramids
โ”œโ”€โ”€ packages/
โ”‚   โ”œโ”€โ”€ shared/                  # Agnostic Logic Layer
โ”‚   โ”‚   โ”œโ”€โ”€ schemas/             # JSON/Zod Validation Schemas
โ”‚   โ”‚   โ””โ”€โ”€ src/                 # Equirectangular Map Projection, PRNGs, E2EE
โ”‚   โ””โ”€โ”€ tokens/                  # Design System
โ”‚       โ””โ”€โ”€ tokens.json          # Single Source of Truth for CSS/JS aesthetics
โ”œโ”€โ”€ infra/                       # Infrastructure as Code
โ”‚   โ”œโ”€โ”€ waf.tf                   # Admin-Door IP Allowlisting & Rate Limiting
โ”‚   โ””โ”€โ”€ s3.tf                    # Strictly Private Buckets (Block Public Access)
โ”œโ”€โ”€ db/                          # Database Migrations
โ””โ”€โ”€ docs/                        # Specifications and Architectural Decisions

๐Ÿ“– The Chronicle: The Story of Slow Light

๐ŸŒŸ Part I: The "Why" โ€” Explaining Slow Light to a Layman (The Newman's Guide)

To truly appreciate the architecture of Slow Light, one must first understand what it is and why it exists.

1. The Human Story: A Digital Sanctuary for Two

In modern life, our most precious memoriesโ€”the photographs from a rainy Tuesday in autumn, the quiet voice notes recorded late at night, the handwritten letters, and the promises madeโ€”are scattered across commercial platforms. They live inside corporate chat applications, cloud photo streams, and social media feeds. In those commercial spaces:

  • Algorithms constantly analyze your private life to serve advertisements.
  • Tracking pixels follow you across the internet.
  • A single data breach or leaked password can expose your most intimate thoughts to strangers.
  • The interface is filled with distraction: red notification badges, likes, read receipts, and commercial clutter.

Slow Light was born from a completely different premise:

"Everything we were is still arriving."

It is a custom, private digital sanctuary created exclusively for exactly two people: the Author (who curates the memories) and the Recipient (the loved one who visits). When the Recipient logs in, she does not see a feed or a grid of thumbnails. She steps into a three-dimensional, interactive night sky.

Every star in that celestial canopy is a memory. As she navigates forward in time along a luminous cosmic rail, she can touch a star to "unfold" it. A memory panel opens, presenting high-definition photographs, restored home videos, audio recordings, and deeply personal letters. Some letters are open; others are locked with digital clockwork, designed to unlock only on an anniversary or a specific future date.

2. Translating "MAANG-Level Security" into Everyday Metaphors

Why build a private romantic application with the same security engineering used by intelligence agencies, top-tier financial networks, and defense systems? Because intimacy without security is an illusion. If an application holds the most vulnerable, honest expressions of human love, it must be completely impervious to surveillance, data mining, theft, and accidental exposure.

Here is how the deep technical concepts work in everyday terms:

  • Passkeys instead of Passwords (The Unforgeable Biometric Lock):

    • The Problem: Passwords can be guessed, written down, intercepted by spyware, or leaked in server breaches.
    • The Solution: Slow Light has no passwords. None. Instead, entering the sanctuary requires a WebAuthn Passkey. Just like opening your iPhone with FaceID or TouchID, your physical device creates an unforgeable cryptographic signature. The server never holds your biometric data; it only verifies that the mathematical key locked inside your personal phone approved the entry.
  • Sealed Envelopes & KMS (The Blind Post Office):

    • The Problem: In standard cloud applications, backend developers, database administrators, and cloud hosting staff can open the database and read all the private letters stored inside.
    • The Solution: Before any letter or memory text touches the database, it is sealed inside an AES-256-GCM cryptographic envelope. Even if someone steals the database hard drive or runs a SQL query, all they see is random, scrambled noise. The key to unseal that envelope is protected by a dedicated Hardware Security Module (AWS KMS) that only unlocks for authorized requests bound to the specific row identity.
  • DBSC โ€” Device-Bound Session Credentials (The Physical Keycard):

    • The Problem: When you log into a typical website, your browser saves a "session cookie" (like an entry wristband). If malware infiltrates your computer or someone steals that cookie, they can impersonate you from anywhere in the world.
    • The Solution: Slow Light uses cutting-edge DBSC. When you log in, your browser creates a private cryptographic key stored deep in your device's secure hardware enclave. Every single API request requires your phone to sign a live, single-use 32-byte cryptographic puzzle. Even if an attacker steals the session cookie, it is completely useless to them because they don't possess your physical phone's hardware chip.
  • True Client-Side E2EE (The Secret Code Between Two Hearts):

    • The Problem: What if the cloud provider itself is subpoenaed or compromised?
    • The Solution: Phase 12 introduced True End-to-End Encryption (E2EE). Using the WebCrypto API directly in the browser, the Author and Recipient negotiate an ephemeral secret key using ECDH P-256 and HKDF. The message is encrypted on the Author's device before it leaves, and decrypted on the Recipient's device after it arrives. The server in the middle is completely blind.
  • Row-Level Security / RLS (The Welded Safety Deposit Box):

    • The Problem: A programming mistake in backend code can accidentally return another user's data.
    • The Solution: PostgreSQL's FORCE ROW LEVEL SECURITY acts as a physical steel wall inside the database engine itself. The database refuses to return any data unless the query originates from an authenticated transaction tagged with that exact user's identity.
  • Vanilla Three.js & The Governor (The Butter-Smooth Planetarium):

    • The Problem: 3D websites often stutter, overheat mobile phones, or drain the battery because of memory leaks and heavy frameworks.
    • The Solution: The 3D engine is built in pure, handcrafted Three.js, completely isolated from React. A built-in "Governor" monitors the device's battery and frame rate in real time. If she opens the app on a high-end desktop, it displays blooming cosmic nebulae; if she opens it on an older phone on a train, the Governor smoothly steps down the graphical load to maintain a rock-solid, battery-efficient 60 frames per second.
  • The Admin Door (The Invisible Speakeasy):

    • The Problem: Admin portals are prime targets for brute-force hacker attacks.
    • The Solution: The Admin console does not even exist on the public internet. It is protected by AWS WAF IP filtering and a dedicated secret entry gate. To anyone scanning the web, the admin panel returns a blank 404 wall.

๐Ÿ›๏ธ Part II: The Phase-by-Phase Genesis & Verification Evidence

Every line of Slow Light was built systematically across 13 distinct phases (Phase 0 through Phase 12). Each phase tackled a critical technical domain, enforced strict non-negotiable architectural invariants, and produced verifiable cryptographic and automated test evidence.

 PHASE 0           PHASE 1          PHASE 2          PHASE 3          PHASE 4          PHASE 5
 [Blueprints] ---> [Foundation] ---> [Passkeys] ----> [Media Vault] -> [3D Engine] ---> [Memory Flow]
      |                 |                |                |                |                |
      v                 v                v                v                v                v
  ADRs 001-012      Postgres RLS     WebAuthn FIDO2    KMS Envelopes    Deterministic   XState FSM
  CI Guardrails     Drizzle Schema   Zero Passwords    CloudFront RSA   Three.js 60fps  SL-Text Parser

 PHASE 6           PHASE 7          PHASE 8          PHASE 9          PHASE 10         PHASE 11
 [Sensory] ------> [Admin Door] ---> [Hardening] ---> [Performance] -> [Red Team] ----> [Production]
      |                 |                |                |                |                |
      v                 v                v                v                v                v
  Web Audio API     WAF IP Gate      Trusted Types    Code Splitting   Playwright CDP  Terraform IaC
  Signed Refresh    Isolated MPA     HMAC Chain       <120KB Budget    A11y WCAG AA    Soft Launch

                                    PHASE 12 (CROWNING EXTENSIONS)
  +-------------------+--------------------+--------------------+-------------------+--------------------+
  | T12.1: Replies    | T12.2: DBSC        | T12.3: True E2EE   | T12.4: HLS Video  | T12.5: Map View    |
  | Sealed Whispers   | Hardware Binding   | WebCrypto Vault    | 4-Tier Ladder     | Offline SVG Globe  |
  +-------------------+--------------------+--------------------+-------------------+--------------------+

Phase 0: Architecture, Invariants & Security Guardrails

  • The Goal: Establish immutable engineering guardrails, locked architectural decision records, and automated boundary verification before writing a single application line.
  • The Engineering Solution:
    • Formulated ADR-001 through ADR-012, defining the non-negotiables: no Next.js/RSC (eliminating server-side template injection and SSR CVEs), zero third-party client trackers (no Google Fonts, no CDN scripts, no analytics), and DOM-isolated media elements (photos are never WebGL textures, eliminating GPU memory leaks).
    • Configured pnpm workspace boundaries enforced by dependency-cruiser in continuous integration.
  • The Newman Takeaway: Setting up the laws of physics and safety codes before breaking ground on the sanctuary.
  • Concrete Evidence:
    • Architectural Specifications: docs/spec/00-front.md through docs/spec/36-*.md.
    • Engineering Rules: rules.md and AGENTS.md.
    • Strict dependency graphs preventing apps/web from ever importing backend database or server logic.

Phase 1: Foundation, Design Tokens & The Database Bedrock

  • The Goal: Build a rock-solid, typed monorepo skeleton, design token pipeline, Fastify backend shell, and PostgreSQL database with tamper-proof security.
  • The Engineering Solution:
    • Designed a design token system (packages/tokens/tokens.json) compiling into CSS custom properties under CSS @layer reset, tokens, base, components, utilities.
    • Deployed a schema-first Fastify 5 server with Zod schema validation and Pino structured logging with strict redaction.
    • Formulated the PostgreSQL schema using Drizzle ORM, with 27 distinct relational tables and FORCE ROW LEVEL SECURITY applied across every table.
    • Implemented withActor database transaction contexts binding PostgreSQL session variables (SET LOCAL app.user_id = ?) to enforce isolation at the SQL engine level.
  • The Newman Takeaway: Pouring the steel-reinforced concrete foundation and laying the private plumbing where every pipe has an unpickable physical lock.
  • Concrete Evidence:
    • Database Schema: apps/api/src/db/schema.ts and db/migrations/0001_init.sql.
    • Design Tokens: packages/tokens/tokens.json.
    • Verified Docker Compose local stack with PostgreSQL 16 Alpine, MinIO S3 emulation, and mock KMS.

Phase 2: Passwordless Authentication โš‘ (The Biometric Gatekeeper)

  • The Goal: Eliminate passwords entirely and engineer a phishing-resistant authentication system for the two participants.
  • The Engineering Solution:
    • Built an end-to-end FIDO2 / WebAuthn Passkey engine using @simplewebauthn/server and @simplewebauthn/browser.
    • Implemented cryptographic challenge lifecycles with single-use consumption and short TTLs to defeat replay attacks.
    • Engineered a secure enrollment ceremony: the Author generates a cryptographically random, single-use invite URL and an out-of-band oral confirmation phrase.
    • Implemented double-defense CSRF protection using __Host- prefixed secure cookies, strict SameSite=Strict flags, and custom request header verification.
  • The Newman Takeaway: Replacing flimsy keys and easily guessed passwords with an unforgeable fingerprint lock and an ancient wax-seal invitation ceremony.
  • Concrete Evidence:
    • Implementation: apps/api/src/auth/passkeys.ts, apps/api/src/auth/sessions.ts, apps/web/src/components/Login.tsx.
    • Automated Tests: apps/api/src/auth/passkeys.test.ts achieving 100% branch coverage on authentication routines.

Phase 3: Private Storage & The Media Pipeline โš‘ (The Darkroom & Vault)

  • The Goal: Protect personal photographs, home movies, and intimate letters so they can never be exposed in database dumps or leaked cloud storage.
  • The Engineering Solution:
    • Created the seal() and unseal() envelope encryption engine in apps/api/src/crypto/sealed.ts using AES-256-GCM with 96-bit nonces and row-bound Associated Authenticated Data (AAD).
    • Direct media uploads leverage presigned S3 POST policies enforcing strict file size caps and MIME-type restrictions.
    • Developed an asynchronous media worker (apps/worker/src/) that pulls uploads from a quarantined S3 bucket, inspects magic bytes, scans for viruses via ClamAV, strips EXIF metadata using sharp, and generates responsive image pyramids and thumbnail previews.
    • Created CloudFront RSA-SHA1 Signed URL delivery (/_m/*) with strict 900-second time-to-live (TTL) and zero public S3 bucket access.
  • The Newman Takeaway: A museum-grade photographic darkroom that inspects every negative for poison, removes hidden GPS tracking tags, and only lets you view photos through a one-way security glass that dims after 15 minutes.
  • Concrete Evidence:
    • Cryptographic Engine: apps/api/src/crypto/sealed.ts.
    • Cryptographic Tests: apps/api/src/crypto/sealed.test.ts (13 tests passing verifying ciphertext integrity, tampering rejection, and AAD mismatches).
    • Media Access Route: apps/api/src/media/access.ts and apps/api/src/media/access.test.ts (4 tests passing).

Phase 4: Core 3D & The Deterministic Cosmos (The Planetarium)

  • The Goal: Create a breathtaking 3D celestial sky where memories exist as stars, running flawlessly at 60 frames per second across devices from iPhones to 4K monitors.
  • The Engineering Solution:
    • Developed a vanilla Three.js WebGL engine (apps/web/src/three/Engine.ts) with zero React coupling. The engine and React communicate strictly through a typed event/command bus (apps/web/src/three/bus.ts).
    • Implemented the mulberry32 pseudo-random number generator (PRNG) and FNV-1a hashing in packages/shared/src/layout.ts to ensure the position and twinkle of every star is 100% deterministic across all platforms.
    • Engineered a multi-tier Performance Governor (apps/web/src/three/Governor.ts) monitoring real-time frame delta times, dynamically stepping down visual fidelity tiers (High, Medium, Low, Mobile, Minimal, Flat) to guarantee zero UI stuttering.
    • Created a custom ResourceTracker deallocating every GPU buffer, material, and geometry on route changes, preventing WebGL context crashes.
  • The Newman Takeaway: A custom-engineered planetarium where every star has an exact mathematical coordinate that never shifts, accompanied by an invisible conductor that keeps the performance smooth even if your phone's battery is low.
  • Concrete Evidence:
    • Mathematical Layout: packages/shared/src/layout.ts and packages/shared/src/layout.test.ts (5 tests passing).
    • Engine Core: apps/web/src/three/Engine.ts and apps/web/src/three/Governor.ts.
    • Memory Leak Suite: apps/web/src/three/memory-leak.test.ts (1 test passing asserting complete GPU buffer deallocation down to 0).

Phase 5: The Memory System & The Lamp Room (The Chronicle of Moments)

  • The Goal: Orchestrate the unfolding of memories, chronological time navigation, and private letter reading through a mathematically verifiable state machine.
  • The Engineering Solution:
    • Built the application lifecycle around an XState v5 state machine (apps/web/src/app/machine.ts) with 15 discrete states, 9 guards, and 9 actors, mathematically eliminating impossible UI states (e.g. viewing a memory while logged out).
    • Created the SL-Text custom lightweight parser (apps/web/src/lib/sl-text.ts), allowing the Author to format memories with italics, poetic line breaks, and emphasis without introducing risky HTML or script injection surfaces.
    • Developed the Lamp Room (apps/web/src/components/LetterViewer.tsx), supporting open letters, timed letters (locked until a future timestamp), and held letters requiring a deliberate "seal-breaking" gesture.
    • Engineered the Logbook (apps/web/src/components/Logbook.tsx), providing an accessible, high-contrast DOM alternative to the 3D sky for keyboard navigation and screen readers.
  • The Newman Takeaway: An interactive digital scrapbook and a secret room of letters, where each memory gently unfolds like parchment and impossible interface glitches are mathematically prevented.
  • Concrete Evidence:
    • State Machine: apps/web/src/app/machine.ts and apps/web/src/app/machine.test.ts (2 tests passing).
    • Markup Parser: apps/web/src/lib/sl-text.ts and apps/web/src/lib/sl-text.test.ts (5 tests passing).
    • Content Schemas: packages/shared/schemas/content.schemas.json.

Phase 6: The Media Experience & Sonic Landscape (The Sensory Symphony)

  • The Goal: Deliver an intimate, cinema-grade multimedia viewer with responsive imagery, fluid touch gestures, and an opt-in procedural audio soundscape.
  • The Engineering Solution:
    • Built MediaViewer.tsx featuring pinch-to-zoom, touch swiping, keyboard shortcuts, and Low-Quality Image Placeholder (LQIP) blurred crossfades.
    • Engineered a transparent signed URL auto-refresh mechanism: if a CloudFront signed URL expires while the Recipient is reading or listening, the component catches the 403, requests a fresh token, and preserves video/audio playback position seamlessly.
    • Created the procedural AudioSystem.ts leveraging the Web Audio API. Soundscapes are strictly off by default, require an intentional user gesture to unlock, and feature gentle crossfading between atmospheric ambient beds.
  • The Newman Takeaway: A private cinema with acoustic soundproofing and an automated projectionist who swaps film reels so seamlessly that you never notice the clock running out.
  • Concrete Evidence:
    • Components: apps/web/src/components/MediaViewer.tsx, apps/web/src/components/MediaAsset.tsx.
    • Audio Engine: apps/web/src/lib/audio.ts.

Phase 7: The Admin Console & The Admin Door โš‘ (The Curator's Workshop)

  • The Goal: Provide the Author with a powerful, desktop-optimized content management portal that is completely hidden and inaccessible to the outside world.
  • The Engineering Solution:
    • Architected the Admin Console as a standalone Multi-Page Application (MPA) at admin.html, completely physically separated from the Recipient's SPA bundle.
    • Implemented the Admin Door: enforced via AWS WAF IP allowlisting. Requests attempting to reach /admin from unauthorized IP addresses receive a silent 404 response.
    • Built rich editors for memories, constellation chapters, time-locked letters, and invite phrases, alongside a real-time cryptographic audit log viewer.
    • Strictly prevented any logging or exposure of the Recipient's reading activity or browsing behavior, upholding invariant A-08.
  • The Newman Takeaway: A hidden study behind a secret revolving bookcase that only opens when you enter from your personal home network, giving you a quiet desk to write letters without disturbing the sanctuary.
  • Concrete Evidence:
    • Admin Portal: apps/web/admin.html and apps/web/src/admin/.
    • Backend API: apps/api/src/routes/admin.routes.ts.
    • WAF Gate: infra/waf.tf.

Phase 8: Security Hardening & The Impenetrable Perimeter โš‘ (The Iron Armor)

  • The Goal: Harden the application against all known web attack vectors, achieving an airtight security posture verified against a 55-row adversarial threat matrix.
  • The Engineering Solution:
    • Enforced W3C Trusted Types (apps/api/src/plugins/securityHeaders.ts), turning Cross-Site Scripting (XSS) from a runtime vulnerability into a compile-time and DOM-level impossibility.
    • Deployed a hyper-strict Content Security Policy (CSP): default-src 'none'; script-src 'self'; connect-src 'self'. Zero foreign domains, zero third-party CDNs, zero remote fonts.
    • Configured Clear-Site-Data: "cache", "cookies", "storage" on logout and session revocation to purge cached memory assets immediately from device storage.
    • Created a cryptographically chained audit log where each event hash is bound to the previous event hash using HMAC-SHA256, making historical tampering mathematically detectable.
  • The Newman Takeaway: Inspecting every rivet in the castle walls with an electron microscope, sealing every microscopic crack, and burning the bridge behind every exit.
  • Concrete Evidence:
    • Security Headers: apps/api/src/plugins/securityHeaders.ts and infra/security-headers.json.
    • Threat Matrix: docs/spec/27-security-test-matrix.md.
    • Cryptographic Audit Logs: apps/api/src/audit/.

Phase 9: Performance Engineering & Resource Optimization (The Lightweight Feather)

  • The Goal: Ensure instant page loads and zero garbage-collection stuttering, even on constrained cellular networks and older mobile chipsets.
  • The Engineering Solution:
    • Implemented dynamic code-splitting via React.lazy() for heavy 3D canvases, keeping the critical entry bundle (The Veil) well below the strict 120 KB gzip budget.
    • Applied Latin-subset font packaging for Inter and Playfair Display, eliminating layout shifts (CLS < 0.05).
    • Optimized database query plans using Drizzle composite indexes and PostgreSQL EXPLAIN ANALYZE benchmarks, ensuring world manifests generate in under 50 milliseconds.
  • The Newman Takeaway: Tuning an elite race car by stripping away every surplus gram of weight, so it starts instantaneously even on a weak mobile phone connection in the rain.
  • Concrete Evidence:
    • Performance Budgets: packages/config/performance-budgets.json.
    • Lazy Loading Integration: apps/web/src/App.tsx.
    • Automated Performance Suite: .github/workflows/performance.yml.

Phase 10: Testing, Resilience & Red-Teaming (The Proving Grounds)

  • The Goal: Subject the entire system to comprehensive automated end-to-end testing, virtual authenticator flows, accessibility scans, and simulated disaster drills.
  • The Engineering Solution:
    • Built Playwright E2E suites utilizing the Chrome DevTools Protocol (CDP) to inject virtual FIDO2 / WebAuthn authenticators, testing passkey registration, login, and step-up elevation without human intervention.
    • Integrated @axe-core/playwright to automatically verify WCAG 2.2 AA accessibility compliance across all modals, dialogs, and color contrasts.
    • Executed database disaster recovery drills, verifying that Point-In-Time Recovery (PITR) restores the encrypted database state in under 5 minutes with zero plaintext leakage.
  • The Newman Takeaway: Simulating earthquakes, fires, and professional safe-cracker attacks in a controlled laboratory to prove the vault cannot fail.
  • Concrete Evidence:
    • E2E Workflow: .github/workflows/e2e.yml.
    • Disaster Recovery Drill Scripts: packages/cli/.
    • Automated accessibility verification across all primary views.

Phase 11: Production Infrastructure & Operational Readiness (The Launchpad)

  • The Goal: Codify every piece of cloud infrastructure in declarative code and build operational CLI tools for safe, verified production deployment.
  • The Engineering Solution:
    • Authored complete Terraform Infrastructure-as-Code (infra/): AWS ECS Fargate clusters, RDS PostgreSQL Multi-AZ databases, private S3 buckets with Object Lock and SSE-KMS, CloudFront distributions, and WAF rate-limiting rules.
    • Engineered the unified CLI suite (pnpm cli <cmd>):
      • bootstrap: Initializes database roles and KMS keyrings.
      • invite:create: Generates single-use, out-of-band Recipient enrollment passes.
      • admin-door: Dynamically opens and closes the WAF IP allowlist.
      • export-escrow: Generates an offline, encrypted paper/cold-storage backup escrow.
      • soft-launch: Verifies production database health, KMS encryption, and S3 connectivity prior to user onboarding.
  • The Newman Takeaway: Building the space launchpad and fueling the rocket with double-redundant emergency parachutes before anyone steps inside.
  • Concrete Evidence:
    • Terraform Infrastructure: infra/main.tf, infra/waf.tf, infra/s3.tf, infra/variables.tf.
    • CLI Tooling: apps/api/src/cli/ (bootstrap.ts, invite.ts, soft-launch.ts, export-escrow.ts).
    • Configuration Specifications: docs/spec/20-configuration.md.

Phase 12: The Five Crown Jewel Extensions (The Pinnacle of Modern Engineering)

Phase 12 took Slow Light from a battle-tested web application to the cutting edge of applied cryptography and systems design, implementing five ambitious extensions:

+--------------------------------------------------------------------------------------------------+
|                                    PHASE 12 EXTENSIONS SUMMARY                                   |
+--------+---------------------------------------+-------------------------+-----------------------+
| Task   | Title                                 | Architectural Decision  | Verification Evidence |
+--------+---------------------------------------+-------------------------+-----------------------+
| T12.1  | Recipient Sealed Replies              | ADR-013 (Option 1)      | 4 / 4 Tests Passing   |
| T12.2  | Device-Bound Session Credentials      | ADR-014 (Option 2)      | 22 / 22 Tests Passing |
| T12.3  | Sealed Vault v2 (True Client E2EE)    | ADR-015 (Option 2)      | 16 / 16 Tests Passing |
| T12.4  | Adaptive Bitrate HLS Video Streaming  | ADR-016 (Option 1)      | 9 / 9 Tests Passing   |
| T12.5  | Interactive Offline Starlight Map     | ADR-017 (Option 3)      | 17 / 17 Tests Passing |
+--------+---------------------------------------+-------------------------+-----------------------+
1. T12.1: Recipient Sealed Replies (The Intimate Whisper)
  • The Problem: In v1, the Recipient could only view memories and favorite letters. She had no way to whisper back or leave a quiet response.
  • The Solution (ADR-013): Built the sealed reply pipeline. The Recipient can type a personal reply directly inside any MemoryPanel or LetterViewer. The message is encrypted with row-bound AES-256-GCM (body_sealed), stored in the replies database table, and presented exclusively to the Author inside a dedicated admin viewer.
  • Evidence:
    • Database Schema: replies table in apps/api/src/db/schema.ts.
    • Endpoints: POST /api/v1/replies and GET /api/v1/replies in apps/api/src/routes/replies.routes.ts.
    • UI Components: ReplyComposer.tsx (client) and RepliesViewer.tsx (admin).
    • Automated Tests: apps/api/src/routes/replies.test.ts (4 tests passing).
2. T12.2: Device-Bound Session Credentials (The Physical Silicon Anchor)
  • The Problem: Traditional browser cookies can be stolen by infostealer malware or network interception.
  • The Solution (ADR-014): Pioneered DBSC via progressive enhancement. Upon login, the client uses the WebCrypto API to generate a non-extractable ECDSA P-256 keypair stored in IndexedDB (sl_dbsc_vault). Every sensitive API call requires signing a server-generated 32-byte challenge with a raw IEEE P1363 signature. Replay attempts are rejected by single-use challenge consumption within a 120-second window.
  • Evidence:
    • Core Engine: apps/api/src/auth/dbsc.ts (dual WebCrypto raw IEEE P1363 and ASN.1 DER signature verification).
    • Client Vault: apps/web/src/lib/dbsc.ts and SecurityPanel.tsx.
    • Protocol Headers: Emits Sec-Session-Registration: (path="/api/auth/dbsc/register") on authentication.
    • Automated Tests: apps/api/src/auth/dbsc.test.ts (17 tests) and apps/api/src/routes/dbsc.routes.test.ts (5 tests) = 22 tests passing.
3. T12.3: Sealed Vault v2 โ€” True Client-Side E2EE (The Zero-Knowledge Vault)
  • The Problem: Even with database encryption, anyone with root access to the backend server could theoretically intercept decrypted text in server memory.
  • The Solution (ADR-015): Implemented true client-to-client zero-knowledge encryption using pure WebCrypto:
    1. Author and Recipient generate client-side ECDH P-256 keypairs stored in non-extractable device vaults (sl_e2ee_vault).
    2. Public keys are exchanged via POST /api/auth/e2ee/keys.
    3. The sender performs ECDH key agreement, derives an encryption key via HKDF-SHA256, wraps a per-memory row key via AES-KW (RFC 3394), and seals the plaintext with AES-256-GCM using row-bound AAD.
    4. The backend server stores the resulting v2.e2ee... ciphertext without ever possessing the decryption key.
    5. The client seamlessly decrypts the text in the browser, proudly displaying a gold "โœฆ Hardware E2EE Sealed" badge.
  • Evidence:
    • Cryptographic Core: packages/shared/src/e2ee.ts (zero dependencies, pure WebCrypto).
    • Client Key Manager: apps/web/src/lib/e2ee.ts.
    • Badges & Verification: MemoryPanel.tsx, LetterViewer.tsx, and interactive benchmark in SecurityPanel.tsx.
    • Automated Tests: packages/shared/src/e2ee.test.ts (11 tests) and apps/api/src/routes/e2ee.test.ts (5 tests) = 16 tests passing.
4. T12.4: Adaptive Bitrate HLS Streaming (The Uninterrupted Cinema)
  • The Problem: Streaming uncompressed 4K video directly to mobile devices causes buffering on spotty cellular connections and generates enormous bandwidth egress.
  • The Solution (ADR-016): Built a multi-bitrate HTTP Live Streaming (HLS) pipeline conforming to RFC 8216:
    • The media worker (apps/worker/src/hls.ts) segments source videos into 6-second MPEG-TS chunks and generates master playlists across 4 distinct resolution ladders: 1080p (4.5 Mbps), 720p (2.2 Mbps), 480p (1.0 Mbps), and 360p (500 kbps).
    • Videos are streamed through CloudFront signed URLs (/_m/*) with 900s TTL.
    • Developed HLSPlayer.tsx in React: uses native Apple HLS on iOS Safari, supports manual and auto quality switching, falls back to progressive MP4 if HLS is unavailable, and transparently preserves playback timestamps across signed URL renewals.
  • Evidence:
    • Playlist Generator: apps/worker/src/hls.ts.
    • Access Control: apps/api/src/media/access.ts (supporting variant: 'hls').
    • Video Player: apps/web/src/components/HLSPlayer.tsx.
    • Automated Tests: apps/worker/src/hls.test.ts (5 tests) and apps/api/src/media/access.test.ts (4 tests) = 9 tests passing.
5. T12.5: Interactive Starlight Map View (The Constellation of Journeys)
  • The Problem: A romantic journey spans places and cities across the globe. Using third-party map providers (like Google Maps or Mapbox) would violate invariant PRIV-01 by leaking the Recipient's IP address and coordinates to third parties.
  • The Solution (ADR-017): Engineered a 100% self-contained, offline SVG Equirectangular World Map:
    • The math engine (packages/shared/src/map.ts) translates GPS (latitude, longitude) into 2D SVG canvas space (x, y) without external libraries.
    • Implemented strict server-side coordinate coarsening: exact GPS coordinates are snapped to a coarse grid (ยฑ0.1ยฐ / ~11 km resolution) to prevent pinpoint location tracking.
    • Memories with hidden location flags are stripped before transmission.
    • Renders memories as luminous golden starlight pins with chronological glowing trails, interactive pan/zoom, preview cards, and direct deep-linking into the 3D celestial sky.
  • Evidence:
    • Mathematical Projection: packages/shared/src/map.ts.
    • API Endpoint: apps/api/src/routes/map.routes.ts (GET /api/v1/map).
    • UI Explorer: apps/web/src/components/MapView.tsx.
    • Automated Tests: packages/shared/src/map.test.ts (13 tests) and apps/api/src/routes/map.test.ts (4 tests) = 17 tests passing.

๐Ÿ›ก๏ธ Part III: Verification Metrics & Operational Health

The entire Slow Light monorepo stands at 100% completion with impeccable quality gates verified across all workspaces:

========================================================================================
                          MONOREPO VERIFICATION AUDIT MATRIX
========================================================================================
  Check / Test Suite       Target              Actual Result            Health Status
----------------------------------------------------------------------------------------
  ESLint Code Quality      0 warnings, 0 err   0 warnings, 0 errors     โœ… PERFECT
  TypeScript Strictness    0 compilation err   0 errors (strict mode)   โœ… PERFECT
  Vitest Monorepo Tests    100% pass           94 / 94 tests passing    โœ… PERFECT
    - packages/shared      All unit tests      29 / 29 passed           โœ… PASS
    - apps/api             All routes/crypto   52 / 52 passed           โœ… PASS
    - apps/web             FSM / UI / leaks    8 / 8 passed             โœ… PASS
    - apps/worker          HLS / processing    5 / 5 passed             โœ… PASS
  Dependency Cruiser       Zero cycles         0 boundary violations    โœ… PERFECT
  Production Builds        All packages clean  4 of 4 workspaces clean  โœ… PERFECT
  Git Working Tree         Clean & committed   Up to date with origin   โœ… SYNCHRONIZED
========================================================================================

๐Ÿงฉ Part IV: The Evolutionary Mosaic โ€” How Every Fragment Sums Up & Connects

When looking at a complex, high-assurance system from the outside, individual components can appear fragmented: Why does a romantic memory app need Device-Bound Session Credentials (DBSC)? Why both AWS KMS and WebCrypto E2EE? Why an offline SVG world map instead of Google Maps? Why an XState finite state machine?

When you examine the implementation plans, architectural walkthroughs, and commit history, the fragments suddenly lock together into an airtight, harmonious whole. Every single technical decision was forged to solve a fundamental human and operational challenge: absolute privacy, zero client trust, cinematic performance, and multi-decade longevity.

                                  THE GRAND ARCHITECTURAL MOSAIC
 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
 โ”‚                                   1. IDENTITY & ENTRANCE                                    โ”‚
 โ”‚  Biometric WebAuthn Passkeys (Phase 2) + Silicon Hardware Binding via DBSC (Phase 12.2)     โ”‚
 โ”‚  โ€ข Result: Passwords eliminated; stolen session cookies are rendered cryptographically dead.โ”‚
 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                                โ”‚
                                                โ–ผ
 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
 โ”‚                                   2. CONFIDENTIALITY AT REST                                โ”‚
 โ”‚  KMS Envelope Encryption (Phase 3) + True Client-Side WebCrypto E2EE Vault (Phase 12.3)     โ”‚
 โ”‚  โ€ข Result: Database dumps reveal only noise; cloud hosts cannot read intimate letters.      โ”‚
 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                                โ”‚
                                                โ–ผ
 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
 โ”‚                                   3. DATA INTEGRITY & ISOLATION                             โ”‚
 โ”‚  PostgreSQL FORCE Row-Level Security (Phase 1) + W3C Trusted Types & CSP (Phase 8)          โ”‚
 โ”‚  โ€ข Result: Physical isolation at SQL engine; DOM injection and XSS rendered impossible.      โ”‚
 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                                โ”‚
                                                โ–ผ
 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
 โ”‚                                   4. MEDIA PIPELINE & PERFORMANCE                           โ”‚
 โ”‚  ClamAV Quarantine Worker (Phase 3) + 4-Tier HLS Adaptive Ladder (Phase 12.4)               โ”‚
 โ”‚  โ€ข Result: Virus-free, metadata-stripped 4K video delivered via signed CloudFront URLs.     โ”‚
 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                                โ”‚
                                                โ–ผ
 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
 โ”‚                                   5. THE USER EXPERIENCE & INTERACTION                      โ”‚
 โ”‚  Deterministic 3D Sky (Phase 4) + XState FSM (Phase 5) + Offline SVG Map (Phase 12.5)       โ”‚
 โ”‚  โ€ข Result: Silk-smooth 60fps WebGL; impossible UI states prevented; zero third-party leaks. โ”‚
 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

1. The Commit & Version Milestone Matrix

The system evolved across 28 focused commits, each executing an explicit implementation plan and validated by a comprehensive walkthrough:

Commit SHA Phase / Scope Milestone & Implementation Plan Focus Walkthrough & Verification Evidence
48141d3 Phase 0 Repo initialization, ADRs 001โ€“012, CI guardrails, CODEOWNERS. Verified toolchain (Node 22 LTS, pnpm 12.5), dependency boundary rules locked.
49ee30a Phase 1 Monorepo layout, Fastify 5 shell, Drizzle schema with FORCE RLS. Docker Compose local stack running; RLS unit tests passing against Postgres 16.
3e553cb Phase 2 Passwordless WebAuthn Passkeys, session manager, CSRF double-defense. 100% branch coverage on auth/; virtual authenticator challenge/response verified.
1bd7c25 Phase 3 AES-256-GCM envelope encryption (sealed.ts), presigned S3 uploads. 13/13 crypto unit tests pass; tamper rejection and row-bound AAD validated.
4fc2d10 Phase 4 Vanilla Three.js engine, mulberry32 PRNG sky, camera rail, Governor. Look-dev spike approved; 60fps render loop decoupled from React state.
65a1d16 Phases 5โ€“7 XState FSM, SL-Text parser, Lamp Room letters, MediaViewer, Admin MPA. 15-state UI machine verified; signed URL 403 auto-refresh; WAF Admin Door gated.
c4d9453 Phase 8 W3C Trusted Types, CSP default-src 'none', HMAC audit log chain. Zero external requests; daily hash chaining prevents audit log modification.
ebb949d Phase 9 Code splitting (React.lazy), font subsetting, memory leak assertions. Bundle budget (<120 KB gzip Veil) met; memory-leak.test.ts asserts 0 GPU leaks.
50f610e Phase 10 Playwright E2E with CDP virtual authenticators, axe-core WCAG audits. Automated browser passes on Chromium/WebKit/Firefox; 0 accessibility violations.
bbc5932 Phase 11 Terraform IaC (ECS, RDS, S3, CloudFront, WAF), soft-launch CLI script. Infrastructure declarative; disaster recovery drill meets RPO โ‰ค 5 min.
4586546 T12.1 Recipient Sealed Replies (ADR-013): sealed storage, API, and composer. 4/4 route tests pass; whispers sealed with row-bound AES-256-GCM.
eedf352 T12.2 Device-Bound Session Credentials / DBSC (ADR-014): WebCrypto ECDSA. 22/22 tests pass; raw IEEE P1363 verification, 120s anti-replay challenges.
d4672d1 T12.3 Sealed Vault v2 True E2EE (ADR-015): ECDH P-256 key agreement, AES-KW. 16/16 tests pass; zero-knowledge client decryption with IndexedDB key vault.
82bd9b6 T12.4 HLS Adaptive Bitrate Video (ADR-016): 4-tier ladder (1080p to 360p). 9/9 tests pass; RFC 8216 master/media playlists; timestamp-preserving signed URLs.
4a8a1d3 T12.5 Offline Starlight Map (ADR-017): Equirectangular SVG projection engine. 17/17 tests pass; server coordinate coarsening (~11km); zero third-party map requests.
c152953 CLI Suite Unified management CLI: bootstrap, invite:create, export-escrow. Out-of-band enrollment passes and cold-storage escrow export verified.
5cf61a1 Media Sign CloudFront RSA-SHA1 signing implementation; eliminated all residual TODOs. Zero TODO comments across entire repository; clean signed URL resolution.
b7c7521 Polish Monorepo-wide zero-warning polish; eliminated loose any types. 0 ESLint warnings, 0 TypeScript errors under strict mode.
e2f4490 System Ref MAANG-level system architecture layout; Fastify 5 logger bugfix. Production dev server boot validated; FST_ERR_LOG_INVALID_LOGGER_CONFIG fixed.
c0d049d Chronicle Integrated Master Project Chronicle & Layman Guide into README. Narrative history with layman metaphors and phase-by-phase evidence completed.

2. The Lifecycle of a Memory (The End-to-End Data Odyssey)

To understand how every module functions with the others as a cohesive whole, follow the journey of a single photograph and love letter from creation to presentation:

 [1. Author Writes Memory] โ”€โ”€โ”€> [2. Client-Side E2EE] โ”€โ”€โ”€> [3. Fastify Validation]
 (Admin Portal, admin.html)     (WebCrypto ECDH P-256)      (Zod .strict() Schema)
                                                                     โ”‚
                                                                     โ–ผ
 [5. S3 Quarantine Upload] <โ”€โ”€โ”€ [4. KMS Envelope Seal] <โ”€โ”€โ”€ [PostgreSQL Storage]
 (Presigned POST Policy)        (AES-256-GCM + AAD)         (FORCE Row-Level Security)
            โ”‚
            โ–ผ
 [6. Media Worker Processing] โ”€โ”€> [7. HLS Transcoding] โ”€โ”€โ”€> [8. S3 Private Media]
 (ClamAV Scan + sharp EXIF strip)  (1080p/720p/480p/360p)   (SSE-KMS Encryption)
                                                                     โ”‚
                                                                     โ–ผ
 [10. Recipient Arrives] <โ”€โ”€โ”€โ”€ [DBSC Challenge/Proof] <โ”€โ”€โ”€ [9. CloudFront Signer]
 (WebAuthn Passkey Touch)      (Raw IEEE P1363 Signature)   (RSA-SHA1 Signed URL)
            โ”‚
            โ–ผ
 [11. 3D Planetarium] โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€> [12. Memory Unfolds] โ”€โ”€โ”€โ”€โ”€> [13. Recipient Whispers]
 (Deterministic Three.js Sky)   (E2EE Decrypted in Browser) (Sealed Reply Sent Back)
  1. Creation: The Author opens the hidden Admin Portal (admin.html). They compose a letter, attach a 4K anniversary video, and tag a secret location in Paris.
  2. Client-Side Sealing (E2EE): Before the text leaves the Author's browser, the packages/shared/src/e2ee.ts engine negotiates a forward-secret key with the Recipient's public JWK using ECDH P-256, wraps a per-memory row key via AES-KW, and encrypts the letter into a v2.e2ee... ciphertext.
  3. API Validation & Envelope Cryptography: Fastify 5 validates the payload against strict Zod schemas (packages/shared/schemas/). The backend envelopes metadata with AWS KMS (apps/api/src/crypto/sealed.ts) using row-bound Associated Authenticated Data (AAD) containing memory_id and author_id.
  4. Database Ingestion: The database transaction sets SET LOCAL app.user_id = ?. PostgreSQL's FORCE ROW LEVEL SECURITY verifies permissions. Even if rogue SQL were executed, the database kernel physically rejects row inserts outside the authorized actor.
  5. Media Quarantine & Inspection: The 4K video is uploaded directly to a quarantined S3 bucket via presigned POST with size and MIME conditions. The asynchronous media worker (apps/worker/src/) spins up on ECS Fargate, verifies magic bytes, scans with ClamAV, strips EXIF GPS tags using sharp, and chunks the video into an adaptive RFC 8216 HLS ladder (1080p down to 360p).
  6. Privacy Coarsening: The Paris GPS coordinates are snapped on the server to ยฑ0.1ยฐ (~11 km resolution) via packages/shared/src/map.ts. Exact coordinates are permanently discarded to protect real-time privacy.
  7. Biometric Entry (The Recipient Visits): The Recipient visits the sanctuary URL. She touches FaceID/TouchID. WebAuthn authenticates her without transmitting biometric data or passwords.
  8. Hardware Binding (DBSC): Her browser generates a hardware-bound ECDSA P-256 key stored in IndexedDB (sl_dbsc_vault). Fastify issues a 32-byte nonced challenge. Her browser signs the challenge with a raw IEEE P1363 signature. Stolen cookies cannot impersonate her.
  9. Cosmic Rendering: The deterministic Three.js engine (apps/web/src/three/) executes mulberry32 PRNG over the seeded memories. The anniversary memory appears as a luminous golden star in a constellation.
  10. The Unfolding: The Recipient touches the star. The XState finite state machine smoothly transitions the camera along the rail. The browser's local WebCrypto engine decrypts the letter right in the DOM, streaming the video via CloudFront signed URLs (/_m/*) with automatic 900s renewal, and displaying the city on an offline SVG world map.
  11. The Whisper Reply: The Recipient writes a quiet reply. It is sealed with row-bound AES-256-GCM and stored in the database, waiting exclusively for the Author.

3. Why the "Fragments" Form an Indivisible Whole

Every architectural choice that might seem unusual in isolation is, in reality, a deliberate answer to a critical requirement:

  • Why Passkeys AND DBSC?
    • Passkeys protect the front door during login.
    • DBSC protects the active session. If a device is infected with cookie-stealing malware, the stolen cookie is completely useless to an attacker because they cannot produce the hardware signature demanded on every API request.
  • Why KMS Envelope Encryption AND True WebCrypto E2EE?
    • KMS Envelope Encryption protects the database storage and backups while allowing the server clock to enforce time-locked letters (e.g. unlocking a letter on December 31st).
    • WebCrypto E2EE provides mathematical zero-knowledge privacy for letters and replies where the Author and Recipient demand that even the database administrator cannot read them.
  • Why Three.js Canvas AND React DOM?
    • Three.js renders the starfield at 60fps on the GPU.
    • React DOM handles the text and photos. Loading photos as WebGL textures consumes hundreds of megabytes of VRAM, leading to mobile browser crashes, and makes images invisible to screen readers. Keeping photos in the DOM guarantees accessibility (WCAG 2.2 AA) and eliminates GPU memory pressure.
  • Why an Offline SVG Map instead of Google Maps?
    • Embedding Google Maps or Mapbox makes requests to third-party servers, leaking the Recipient's IP address, device specs, and coordinates to commercial tracking networks (violating invariant PRIV-01). The self-contained offline SVG projection engine delivers an intimate map with zero external network traffic.
  • Why XState Finite State Machines?
    • Standard React apps rely on scattered useState and useEffect flags (isLoading, isModalOpen, hasError), leading to "impossible states" (e.g., viewing a memory while the session is expired). XState mathematically models the 15 valid UI states, ensuring transitions are deterministic, bug-free, and resilient.

๐Ÿ›ก๏ธ Engineering Challenges & Architectural Decisions (ADRs)

Building a highly secure, cinematic application required navigating severe trade-offs between performance, security, and bundle size.

1. DBSC (Device-Bound Session Credentials) vs Bearer Tokens

Challenge: Standard session cookies are vulnerable to exfiltration (malware stealing the __Host-sl_sid cookie). Decision (ADR-014): Implemented a progressive DBSC engine. Upon login, the client generates a non-extractable WebCrypto ECDSA P-256 keypair, storing the private key in IndexedDB. Every subsequent API request requires an IEEE P1363 (Raw) signature over a server-generated 32-byte challenge. Stolen cookies are useless without the hardware-bound private key.

2. Vanilla Three.js vs React Three Fiber (R3F)

Challenge: R3F provides excellent developer ergonomics but tightly couples the React render cycle to the GPU loop, leading to uncontrollable garbage collection spikes on mobile devices. Decision (ADR-002): Chose Vanilla Three.js. Wrote a custom ResourceTracker to explicitly allocate and dispose of GPU geometries/textures. The engine layout is fully deterministic (using mulberry32 PRNG), ensuring 60fps performance even on lower-tier mobile hardware.

3. Server-Side Rendering (Next.js) vs Static SPA (Vite)

Challenge: Next.js offers superior SEO and initial load times, but introduces a massive server-side attack surface (e.g., RSC vulnerabilities). Decision (ADR-001): As a private application, SEO is irrelevant. Opted for a Vite SPA hosted on a static S3 bucket. This eliminates an entire class of server-side vulnerabilities and drastically reduces compute costs.

4. Zero-Knowledge E2EE vs Envelope Encryption

Challenge: The Author wanted absolute privacy, meaning even a database administrator cannot read the Recipient's letters. Decision (ADR-015): Phased approach. Base architecture uses KMS envelope encryption (AES-256-GCM). Phase 12 introduced a WebCrypto E2EE Vault. Participants exchange public JWKs (ECDH-P256), negotiate a shared secret via HKDF, and wrap row-bound AES keys via AES-KW. The backend serves purely as a blind storage array.

5. Media Pipeline & HLS Adaptive Streaming

Challenge: Serving massive 4K videos directly to mobile devices causes buffering and massive AWS egress costs. Decision (ADR-016 & ADR-007): Uploaded media goes to a Quarantine bucket. A worker sanitizes (ClamAV) and generates a multi-bitrate HLS ladder (1080p to 360p). Media is delivered via CloudFront using RSA-SHA1 Signed URLs with a strict 900-second TTL.


๐Ÿ“ Part V: System Architecture & Sequence Flows (Phase-by-Phase Deep Dives)

Slow Light's architecture is a testament to uncompromising security and performance. To provide a true "glass-box" view of the system, the following sequence diagrams detail the exact cryptographic, data, and execution flows for every single phase of the application's development lifecycle (Phases 0 through 12).


Phase 0: Architecture & Infrastructure Provisioning

(Zero Long-Lived Credentials, OIDC IAM Federation & Immutable CMKs)

Before writing application code, Phase 0 establishes the cryptographic bedrock. Infrastructure is provisioned via Terraform using ephemeral GitHub Actions OIDC federation, eliminating hardcoded AWS secrets. Customer Master Keys (CMKs) are generated with deletion protection and strict key policies.

sequenceDiagram
    autonumber
    participant Dev as Author and Git
    participant CI as GitHub Actions CI
    participant IAM as AWS IAM (OIDC Provider)
    participant TF as Terraform Engine
    participant KMS as AWS KMS and S3
    
    Dev->>CI: Push infrastructure commits to main branch
    CI->>IAM: Request short-lived STS credentials via OIDC token
    Note over IAM: Validates repository, branch, and signature
    IAM-->>CI: Issue scoped temporary IAM role credentials (1h TTL)
    CI->>TF: Execute terraform plan and apply
    TF->>KMS: Acquire S3 remote state lock via DynamoDB
    TF->>KMS: Provision CMKs (alias/slowlight-sealed, media, vault)
    Note over KMS: Enforces key rotation and deletion locks
    TF->>KMS: Provision S3 buckets with S3 Block Public Access
    TF-->>CI: Infrastructure state locked and verified
    CI-->>Dev: Automated pipeline green, zero secrets stored in CI
Loading

Architectural Rationale: By refusing to generate long-lived AWS Access Keys, the blast radius of any compromised developer machine or CI secret leakage is reduced to zero.


Phase 1: Foundation & PostgreSQL Row-Level Security (RLS)

(Strict Tenant Isolation & Query-Level Boundary Enforcement)

The Fastify backend never trusts client input. Every inbound API request passes through the withActor middleware, which validates session credentials and injects PostgreSQL configuration variables (SET LOCAL) to enforce database-level Row-Level Security.

sequenceDiagram
    autonumber
    participant Browser as Client Browser (Veil)
    participant API as Fastify API Server
    participant Middleware as withActor Middleware
    participant Drizzle as Drizzle ORM
    participant DB as PostgreSQL (RLS Engine)
    
    Browser->>API: HTTP Request with Host-sl_sid Cookie
    API->>Middleware: Intercept and inspect session cookie
    Middleware->>DB: Validate SHA-256 token hash and expiration
    DB-->>Middleware: Return user record (role is recipient)
    Middleware->>DB: SET LOCAL role to slowlight_app
    Middleware->>DB: SET LOCAL request.jwt.claim.sub to user ID
    API->>Drizzle: Execute query: SELECT FROM memories
    Drizzle->>DB: Forward SQL statement
    Note over DB: Postgres RLS kernel evaluates USING policy<br/>author_id = current_user OR published_at in past
    DB-->>Drizzle: Return only permitted rows (unauthorized rows stripped)
    Drizzle-->>API: Typed memory entity array
    API-->>Browser: 200 OK (Clean payload, unauthorized objects return 404)
Loading

Architectural Rationale: Even if an application developer writes a buggy query like SELECT * FROM memories without a WHERE clause, the Postgres RLS kernel prevents data leakage at the database engine level. Unauthorized rows return 404 (never 403), preventing attacker resource enumeration.


Phase 2: Authentication & WebAuthn Passkeys

(Zero-Password Biometric Auth & Replay-Protected Attestation)

Slow Light has no passwords, no reset emails, and no usernames to enumerate. Authentication is strictly biometric using the FIDO2/WebAuthn standard backed by physical Secure Enclaves or YubiKeys.

sequenceDiagram
    autonumber
    participant Browser as Recipient Browser (WebAuthn)
    participant Edge as CloudFront / WAF
    participant API as Fastify Auth API
    participant DB as PostgreSQL DB
    
    Browser->>Edge: POST /api/v1/auth/passkey/options
    Edge->>API: Forward request (rate-limited by IP prefix)
    API->>API: Generate 32-byte cryptographically secure challenge
    API->>DB: INSERT INTO auth_challenges (TTL 120s)
    API-->>Browser: PublicKeyCredentialRequestOptions
    Note over Browser: Prompt FaceID or TouchID or Windows Hello<br/>navigator.credentials.get()
    Browser->>Browser: Sign challenge using hardware private key
    Browser->>API: POST /api/v1/auth/passkey/verify (Assertion)
    API->>DB: SELECT challenge WHERE consumed is false
    API->>API: Verify ECDSA signature against stored public key
    API->>API: Verify RP ID, origin, and increment counter
    API->>DB: UPDATE auth_challenges SET consumed is true
    API->>DB: INSERT INTO sessions (token_hash, expires_at)
    API-->>Browser: Set-Cookie Host-sl_sid (HttpOnly, Secure, SameSite Strict)
Loading

Architectural Rationale: Passkeys are cryptographically bound to the exact origin (slowlight.love). Phishing sites cannot relay credentials because the browser signs the authentic domain name directly in hardware.


Phase 3: Private Storage & KMS Envelope Encryption

(Air-Gapped Media Quarantine & Server-Side Envelope Sealing)

All personal media and text are encrypted using two-tier envelope encryption. File uploads bypass the application server entirely, landing directly in an isolated quarantine bucket before automated virus scanning and metadata stripping.

sequenceDiagram
    autonumber
    participant Admin as Author Admin
    participant API as Fastify API
    participant S3Q as S3 Quarantine Bucket
    participant Worker as Media Worker (ECS Fargate)
    participant KMS as AWS KMS (CMK)
    participant S3V as S3 Media Vault Bucket
    
    Admin->>API: POST /admin/media/uploads (mime, bytes, checksum)
    API-->>Admin: Presigned S3 POST URL (strict policy conditions)
    Admin->>S3Q: Direct binary upload to quarantine bucket
    Admin->>API: POST /admin/media/uploads/id/complete
    API->>Worker: Enqueue processing task (ECS RunTask)
    Worker->>S3Q: Download raw binary into sandboxed memory
    Worker->>Worker: ClamAV anti-malware scan and ExifTool GPS stripping
    Worker->>KMS: GenerateDataKey for slowlight-media
    KMS-->>Worker: Plaintext DEK plus Ciphertext DEK
    Worker->>Worker: Encrypt asset with AES-256-GCM using Plaintext DEK
    Worker->>Worker: Securely zero Plaintext DEK from RAM
    Worker->>S3V: Upload encrypted asset and Ciphertext DEK envelope
    Worker->>API: Mark asset status as ready in DB
Loading

Architectural Rationale: The API never handles multi-gigabyte media streams directly, preserving compute resources. Media files are sanitised in an ephemeral worker sandbox, stripping sensitive EXIF GPS locations before persistent storage.


Phase 4: Core 3D Engine & Deterministic Celestial Canvas

(60fps WebGL Pipeline, mulberry32 PRNG & Memory-Safe Resource Tracking)

The celestial sky is not an artistic rendering of pre-rendered videos; it is a live, deterministic Three.js WebGL simulation executing directly on the client's GPU.

sequenceDiagram
    autonumber
    participant Client as React DOM (WorldCanvas)
    participant XState as XState Machine
    participant Engine as Three.js Engine (Engine.ts)
    participant PRNG as mulberry32 PRNG
    participant Tracker as ResourceTracker
    participant GPU as WebGL2 / GPU Pipeline
    
    Client->>Engine: Initialize WorldCanvas context
    Engine->>PRNG: Seed generator with deterministic timestamp seed
    PRNG-->>Engine: Compute stable (x, y, z) star coordinates
    Engine->>Tracker: Allocate InstancedBufferGeometry and Shaders
    Tracker->>GPU: Upload starfield vertex buffers
    loop 60 FPS Render Loop
        Engine->>Engine: Evaluate Frame Governor (monitor delta-time)
        alt Frame budget exceeded
            Engine->>Engine: Throttle shader passes and step down visual tier
        else Frame budget healthy
            Engine->>GPU: Issue instanced draw call
        end
    end
    Client->>XState: User taps star in viewport
    XState->>Engine: Command: TRAVEL_TO_COORDINATE(x, y, z)
    Engine->>GPU: Interpolate camera along cubic Bezier curve rail
    Client->>Tracker: Unmount canvas or navigate away
    Tracker->>GPU: Dispose geometry and materials, release VRAM
Loading

Architectural Rationale: By decoupling Three.js from React's component render tree and managing allocations via ResourceTracker, Slow Light eliminates garbage collection spikes and WebGL memory leaks on constrained mobile devices.


Phase 5: The Memory System & XState Finite State Machine

(Deterministic State Transitions & AST SL-Text Parsing)

To prevent "impossible states" (such as a memory modal opening during a 3D camera travel animation), all user navigation is governed by a formal mathematical XState machine.

sequenceDiagram
    autonumber
    participant User as Recipient Action
    participant XState as XState Interpreter (machine.ts)
    participant React as React UI (MemoryPanel)
    participant Parser as SL-Text Parser
    participant API as Fastify API
    
    User->>XState: Send event: SELECT_MEMORY(id)
    Note over XState: State: exploring to unfolding<br/>Locks camera, disables picking, fires audio whoosh
    XState-->>React: Transition state change
    React->>API: GET /api/v1/memories/:id
    API-->>React: Return sealed memory payload
    React->>Parser: parseSLText(memory.rawContent)
    Note over Parser: Tokenizes custom syntax, builds AST,<br/>enforces strict no-raw-HTML sanitization
    Parser-->>React: Sanitized React Component Tree
    XState->>XState: Camera finishes rail travel
    XState->>XState: Transition: unfolding to viewing
    XState-->>React: Open MemoryPanel overlay with focus trap
    User->>XState: Press Esc or Close Button
    XState->>XState: Transition: viewing to returning to exploring
Loading

Architectural Rationale: Complex UI states are modeled as a directed graph. There is zero reliance on scattered boolean state flags (isLoading, isOpen), guaranteeing bug-free navigation and seamless accessibility focus management.


Phase 6: Media Experience, Signed URLs & Object URL Lifecycle

(Protected Media Streaming with Automated Client Memory Reclamation)

Decrypted media never hits disk. It is requested on-demand via time-limited CloudFront signed URLs, buffered in memory, and managed via an LRU cache to prevent memory exhaustion.

sequenceDiagram
    autonumber
    participant UI as MediaViewer Component
    participant LRU as Object-URL LRU Cache
    participant API as Fastify API (/media/access)
    participant Edge as CloudFront CDN (/_m/*)
    participant S3 as S3 Private Media Bucket
    
    UI->>API: POST /api/v1/media/access (assetId, variant display)
    Note over API: Checks caller session and RLS relationship
    API-->>UI: Return RSA-SHA1 Signed URL (TTL 900 seconds)
    UI->>Edge: GET /_m/assetId/display with signature
    Edge->>Edge: Validate signature against CloudFront Key Group
    Edge->>S3: Fetch private asset with OAC authentication
    S3-->>Edge: Binary stream
    Edge-->>UI: 200 OK (Cache-Control: private, no-store)
    UI->>LRU: Register binary blob and createObjectURL()
    alt Total active blob memory exceeds 50 MB
        LRU->>LRU: Revoke oldest URL via revokeObjectURL()
    end
    UI->>UI: Render media in DOM element (img or video)
    UI->>LRU: On component unmount: revokeObjectURL() immediately
Loading

Architectural Rationale: Media URLs are ephemeral (900s TTL). Photos and videos are loaded as DOM elements rather than WebGL textures, preserving GPU memory and allowing screen readers to access descriptive alternative text.


Phase 7: The Admin Door & Privilege Elevation

(Cloaked Administration, Step-Up Biometrics & SHA-256 Audit Trail)

The administration portal is completely invisible to the public. Accessing administrative capabilities requires passing a secret path challenge, followed by Step-Up Biometric elevation for any destructive operation.

sequenceDiagram
    autonumber
    participant Author as Author Admin Browser
    participant WAF as AWS WAF (IP & Path Filter)
    participant API as Fastify Admin API
    participant Audit as Audit Hash Chain Engine
    participant DB as PostgreSQL DB
    
    Author->>WAF: POST /admin/door-knock with cryptographic proof
    WAF->>WAF: Check IP allow-list and proof validation
    WAF-->>Author: 200 OK (Open transient 15-minute door window)
    Author->>API: POST /api/admin/auth/passkey (Admin login)
    API-->>Author: Admin session cookie created
    Author->>API: POST /api/admin/memories/:id/delete (Destructive Action)
    Note over API: Step-Up Check: Action requires fresh elevation
    API-->>Author: 403 Elevation Required (Challenge issued)
    Author->>Author: Biometric User Verification via Passkey
    Author->>API: POST /api/admin/elevation/verify (Assertion)
    API->>API: Verify assertion and grant 5-minute elevated token
    Author->>API: POST /api/admin/memories/:id/delete (with Elevation Token)
    API->>DB: Soft delete memory record in transaction
    API->>Audit: Append event: memory.delete
    Note over Audit: Computes immutable SHA-256 chain<br/>hash_n = SHA256(prev_hash, action, actor, timestamp)
    Audit->>DB: INSERT INTO audit_logs (hash, prev_hash)
    API-->>Author: 200 OK (Audit anchored)
Loading

Architectural Rationale: Even if an unauthorized party obtains physical access to an active admin computer, any sensitive or destructive modification is gated behind immediate re-biometric authentication.


Phase 8: Security Hardening & Edge Fortress

(Trusted Types DOM Enforcement, Isolated Processes & Strict CSP)

Phase 8 fortifies the client against browser-level threats. The application runs inside an isolated operating process using Cross-Origin-Embedder-Policy (require-corp) and strictly enforces W3C Trusted Types to eradicate Cross-Site Scripting (XSS).

sequenceDiagram
    autonumber
    participant Attacker as Adversary / Probe
    participant Edge as CloudFront Edge / WAF
    participant Browser as Client Browser (Veil DOM)
    participant API as Fastify CSP Report API
    
    Edge-->>Browser: HTTP 200 with Strict Security Headers (CSP, COOP, COEP)
    Note over Browser: Browser creates isolated process space (Spectre mitigation)
    Attacker->>Browser: Attempt DOM injection: element.innerHTML = payload
    Note over Browser: Trusted Types Engine blocks operation:<br/>Requires TrustedHTML policy
    Browser->>API: POST /api/v1/csp-report (Automated violation beacon)
    API->>API: Log security anomaly and alert Author via webhook
    Attacker->>Edge: Attempt directory traversal: GET /api/v1/../../etc/passwd
    Edge->>Edge: WAF Core Rule Set intercepts malicious pattern
    Edge-->>Attacker: 403 Forbidden (Blocked at edge, API never invoked)
Loading

Architectural Rationale: Modern web security must defend in depth. Trusted Types eliminate DOM XSS at the compiler and runtime level, while COOP/COEP headers isolate renderer processes from shared memory leaks.


Phase 9: Performance Optimization & Subsetting Pipeline

(Sub-Second Cold Starts, Brotli Compression & Zero Heap Drift)

To ensure Slow Light loads instantly over constrained mobile networks, bundle sizes are rigorously audited and font files are stripped of unused glyphs down to minimal payloads.

sequenceDiagram
    autonumber
    participant Build as Build System (Vite + Fonttools)
    participant S3 as S3 Static Hosting
    participant CDN as CloudFront CDN
    participant Mobile as Low-Tier Mobile Device
    
    Build->>Build: Execute font subsetting (strip unused glyphs: 2.4MB to 35KB)
    Build->>Build: Vite code-splitting: Core Veil (under 120KB gz) vs World Canvas
    Build->>Build: Pre-compress assets with Brotli level 11 (.br)
    Build->>S3: Deploy immutable versioned chunks (/assets/*)
    Mobile->>CDN: GET /index.html (Initial page request)
    CDN-->>Mobile: Deliver Brotli HTML and Critical CSS (LCP under 1.8s)
    Note over Mobile: Render login Veil without loading Three.js engine
    Mobile->>Mobile: User completes Passkey authentication
    Mobile->>CDN: Dynamic import: import(WorldCanvas)
    CDN-->>Mobile: Deliver 3D World chunk on demand
    Note over Mobile: Baseline memory capped under 150MB, steady 60fps
Loading

Architectural Rationale: The heavy Three.js engine and 3D assets are never downloaded before authentication. This guarantees maximum page speed for initial authentication and prevents unauthenticated memory waste.


Phase 10: Testing Rigor & Virtual Authenticator Automation

(Continuous Integration with Headless WebAuthn & Axe-Core Accessibility)

Because Slow Light requires biometric passkeys, traditional automated integration tests would fail without human interaction. Phase 10 implements a complete headless test pipeline using Chromium CDP Virtual Authenticators.

sequenceDiagram
    autonumber
    participant CI as GitHub Actions CI
    participant Playwright as Playwright Test Runner
    participant CDP as Chromium CDP Session
    participant WebAuthn as Virtual Authenticator (CTAP2)
    participant Axe as Axe-Core Accessibility Engine
    participant API as Fastify Test Server
    
    CI->>Playwright: pnpm e2e:run
    Playwright->>CDP: Attach to Chromium DevTools Protocol
    CDP->>WebAuthn: WebAuthn.enable()
    CDP->>WebAuthn: WebAuthn.addVirtualAuthenticator(CTAP2 internal)
    Playwright->>API: Execute user enrollment flow
    API-->>Playwright: Return registration challenge
    Playwright->>WebAuthn: Synthetic biometric sign (User Verification true)
    WebAuthn-->>Playwright: Valid attestation signature
    Playwright->>API: Complete registration and verify session
    Playwright->>Axe: Run automated WCAG 2.2 AA accessibility scan
    Axe-->>Playwright: Assert 0 serious/critical violations
    Playwright-->>CI: 100% test pass (94 unit/integration and E2E suites green)
Loading

Architectural Rationale: Testing security-critical code requires continuous automation. CDP virtual authenticators allow full regression testing of Passkey registration, authentication, counter rollover, and timeout handling in CI without manual hardware taps.


Phase 11: Production Go-Live, Zero-Downtime ECS & Escrow

(Blue/Green Deployments, Automated Migrations & Air-Gapped Disaster Recovery)

Deploying to production requires zero downtime and an unbreakable disaster recovery guarantee. Scheduled jobs create encrypted offline escrow backups, replicated across accounts to prevent complete cloud provider lockouts.

sequenceDiagram
    autonumber
    participant CI as Deployment Pipeline
    participant ECS as AWS ECS Fargate
    participant RDS as Amazon RDS PostgreSQL
    participant Cron as Escrow Worker (Scheduled)
    participant BackupS3 as Secondary Account S3 (WORM Lock)
    
    CI->>ECS: Run one-off task: drizzle-kit migrate (apply schema changes)
    ECS->>RDS: Execute idempotent schema migrations in transaction
    RDS-->>ECS: Schema verified
    CI->>ECS: Update ECS Service with new task definition (Blue/Green)
    ECS->>ECS: Spin up new container tasks and run ALB health checks
    ECS->>ECS: Drain traffic from old tasks once health checks pass
    Cron->>RDS: Daily snapshot: pg_dump encrypted stream
    Cron->>Cron: Encrypt database dump using air-gapped PGP Public Key
    Cron->>BackupS3: Replicate sealed archive to secondary AWS Account
    Note over BackupS3: S3 Object Lock enforces WORM compliance<br/>Write Once Read Many, immune to ransomware or deletion
Loading

Architectural Rationale: Backups are useless unless protected from compromise. Encrypting backups with an offline PGP key and storing them in an independent AWS account with WORM compliance guarantees recovery even if the primary cloud account is compromised.


Phase 12: Advanced Architectural Extensions (Deep Dives)

Phase 12 builds upon the core foundation to deliver state-of-the-art privacy and streaming extensions. The following diagrams detail each of the five Phase 12 architectural milestones.

Phase 12.1: Recipient Sealed Replies Flow

(Row-Bound Envelope Encryption for Intimate Correspondence)

When the Recipient writes a quiet reply to a memory, it is sealed with AES-256-GCM using row-bound Additional Authenticated Data (AAD), ensuring replies cannot be tampered with or swapped between memories.

sequenceDiagram
    autonumber
    participant Recipient as Recipient Browser (Web Client)
    participant API as Fastify API (/api/v1/replies)
    participant Crypto as Server Crypto Service
    participant DB as PostgreSQL (replies table)
    participant Author as Author Admin (RepliesViewer)
    
    Recipient->>API: POST /api/v1/replies (memoryId, body)
    Note over API: Validates session, CSRF, and memory accessibility
    API->>Crypto: sealEnvelope(body, AAD with replyId and memoryId)
    Crypto->>Crypto: Generate random 256-bit AES-GCM Key
    Crypto->>Crypto: Encrypt plaintext body with row-bound AAD
    Crypto-->>API: Sealed ciphertext payload
    API->>DB: INSERT INTO replies (id, memory_id, author_id, body_ciphertext)
    DB-->>API: 201 Created
    API-->>Recipient: Acknowledged (Stored in sealed vault)
    Author->>API: GET /api/v1/replies?memoryId=id
    API->>DB: Fetch sealed replies
    API->>Crypto: unsealEnvelope(ciphertext, AAD)
    Crypto-->>API: Decrypted plaintext
    API-->>Author: Render reply in Admin Portal
Loading

Phase 12.2: Device-Bound Session Credentials (DBSC)

(Cryptographic Session Anchoring via Hardware TPM Keys)

To eliminate session hijacking and cookie theft by malware, DBSC cryptographically binds the session cookie to an non-extractable private key residing in the client device's hardware enclave.

sequenceDiagram
    autonumber
    participant Browser as Browser (WebCrypto / IndexedDB)
    participant Edge as CloudFront / WAF
    participant API as Fastify API Server
    participant DB as PostgreSQL (device_sessions)
    
    Browser->>API: POST /api/v1/auth/passkey/verify (Successful Login)
    API-->>Browser: Set-Cookie: Host-sl_sid and Sec-Session-Registration
    Browser->>Browser: Generate non-extractable ECDSA P-256 keypair in IndexedDB
    Browser->>API: POST /api/auth/dbsc/challenge
    API-->>Browser: Issue 32-byte cryptographic challenge (120s TTL)
    Browser->>Browser: Sign challenge using private key via WebCrypto (IEEE P1363 / DER)
    Browser->>API: POST /api/auth/dbsc/register (publicKey, signature)
    API->>API: Verify ECDSA signature against public key
    API->>DB: INSERT INTO device_sessions (session_id, public_key_jwk)
    API-->>Browser: Session bound to hardware device
    loop Every Protected API Request
        Browser->>API: GET /api/v1/memories with Sec-Session-Signature
        API->>DB: Load bound public key
        API->>API: Validate signature over current request attributes
        API-->>Browser: 200 OK (Data returned)
    end
Loading

Phase 12.3: Sealed Vault v2 True E2EE

(Mathematical Zero-Knowledge Client-Side Encryption)

For ultimate privacy, Phase 12.3 implements a mathematical zero-knowledge pipeline. The server operates as an encrypted blind store; only the Author and Recipient hold the private keys necessary to decrypt letters.

sequenceDiagram
    autonumber
    participant A as Author Browser (WebCrypto)
    participant API as API & Postgres DB
    participant R as Recipient Browser (WebCrypto)

    Note over R: Generates ECDH P-256 Keypair<br/>Stores Private Key in IndexedDB
    R->>API: POST /api/auth/e2ee/keys (Registers Public JWK)
    A->>API: GET /api/auth/e2ee/keys (Fetches Recipient Public JWK)
    Note over A: 1. Generates 256-bit AES-GCM CEK<br/>2. Encrypts plaintext with row-bound AAD<br/>3. Generates Ephemeral ECDH keypair<br/>4. Derives KEK via ECDH and HKDF<br/>5. Wraps CEK via AES-KW<br/>6. Formats v2.e2ee envelope
    A->>API: Stores v2.e2ee opaque ciphertext in DB
    R->>API: Fetches memory / letter (gets v2.e2ee string)
    Note over R: 1. Unpacks Author Ephemeral Public Key<br/>2. Derives KEK using Recipient Private Key<br/>3. Unwraps CEK via AES-KW<br/>4. Decrypts AES-GCM ciphertext and checks AAD
    Note over R: Renders cleartext in DOM with E2EE badge
Loading

Phase 12.4: Adaptive HLS Video Streaming

(Multi-Bitrate Video Transcoding & Fragmented Signed Streaming)

4K cinematic memories are transcoded by an air-gapped FFmpeg worker into an RFC 8216 multi-bitrate HLS ladder, delivered via signed CloudFront segments.

sequenceDiagram
    autonumber
    participant W as Web Client (MediaAsset / HLSPlayer)
    participant S as API Server (/api/v1/media/access)
    participant M as Media Worker (ffmpeg pipeline)
    participant C as Media S3 Bucket & CloudFront (/_m/*)

    Note over M: Video Processing Triggered
    M->>M: Generates 1080p, 720p, 480p, 360p variants
    M->>M: Generates master.m3u8 and variant playlists
    M->>C: Uploads segments and manifests (SSE-KMS)
    M->>S: Updates media_assets (variant hls)
    W->>S: POST /api/v1/media/access (assetId, variant hls)
    Note over S: Verifies session and RLS visibility
    S-->>W: Returns signed CloudFront URL for master.m3u8 (TTL 900s)
    W->>C: GET /_m/.../master.m3u8 with signature
    C-->>W: Master playlist with bitrate tiers
    Note over W: Adaptive playback (Safari native / quality switcher)
Loading

Phase 12.5: Privacy-Preserving Offline Map View

(Equirectangular Projection & Ephemeral Coordinate Coarsening)

To display the journey of shared memories across the world without leaking physical locations to commercial tracking networks (Google Maps/Mapbox), Phase 12.5 executes an offline, coordinate-coarsened SVG map projection.

sequenceDiagram
    autonumber
    participant Client as React Client (MapView.tsx)
    participant API as Fastify API (/api/v1/map)
    participant DB as PostgreSQL (memories)
    participant Shared as Shared Geometry Engine (map.ts)
    
    Client->>API: GET /api/v1/map
    API->>DB: Query visible memories with location data
    DB-->>API: Raw memory records with exact GPS coordinates
    loop For each memory pin
        API->>API: Coarsen coordinates to plus-minus 0.1 deg (approx 11 km blur)
        API->>API: Strip precise timestamps and device metadata
    end
    API-->>Client: 200 OK (Sanitized coordinate pins array)
    Client->>Shared: projectCoordinatesToSVG(lat, lon, width, height)
    Shared-->>Client: Compute SVG (x, y) canvas coordinates
    Client->>Client: Render offline inline SVG world map with starlight pins
    Note over Client: Zero network requests to Google Maps or Mapbox<br/>Complete immunity against third-party location tracking
Loading

๐Ÿ“š Documentation Index

Slow Light is meticulously documented. The docs/ folder is the ultimate source of truth, dictating behavior, styling, and security guardrails.

Document / Specification Description
PRD.md Product Requirements Document: The overarching vision, MVP scope, and non-negotiable constraints.
architecture.md System Architecture: Detailed breakdown of the SPA, API, Worker, and DB interaction models.
rules.md Engineering Guardrails: Mandatory coding standards (No TODOs, No 3rd parties, strict CSP).
docs/spec/00-front.md Master Specification Index: Entry point to the 36 meticulously detailed spec documents.
docs/spec/20-configuration.md Environment Configuration: Schemas for .env and site.config.json defining deployment boundaries.
docs/spec/21-json-schemas.md Data Contracts: Strict JSON Schema 2020-12 definitions for all payloads traversing the system.
docs/spec/25-implementation-roadmap.md Phased Execution: The 13-phase roadmap dictating the build order and acceptance criteria.
docs/spec/27-security-test-matrix.md Threat Model: A 55-row matrix of adversarial scenarios and required mitigations.
docs/PROJECT-STATE.md State & Health: Real-time tracker of phase completions, test coverage, and active ADR implementations.
memory.md Project Ledger: A chronological log of decisions, audit results, and session histories.

Slow Light stands fully realized: a zero-knowledge, hardware-bound sanctuary of light, memory, and code.

About

Privacy-first digital sanctuary for two, built with React, Fastify, WebCrypto E2EE, WebAuthn passkeys, PostgreSQL RLS, deterministic Three.js, secure media pipelines, and AWS infrastructure.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages