§ 07 — Architecture

A pnpm monorepo with one source of truth for the math.

Next.js on Vercel, Fastify on Railway, Postgres and Redis behind it, Solana underneath. Types, schemas, PDAs and every protocol number live in @sealed/shared so web, API and program cannot drift.

§ 7.1System map

Browser · Vercel

apps/web

Next.js 15 App Router, Tailwind, framer-motion

Wallet Adapter

SIWS sign-in; deposit transfer with memo

Bid vault

AES-GCM salts in IndexedDB

API · Railway

Fastify REST + /ws

/api/*, /llms.txt, event hub

Ledger engine

auctions, pool, drips, fee splits, rewards (double-entry)

Postgres · Redis

ledger of record; memory fallback in demo

Solana

Company wallet

holds deposits; pays withdrawals

Helius

RPC, deposit detection, Privacy Rings

sealed_launchpad

Anchor program · onchain mode (roadmap)

Default offchain custodial mode. In the roadmap onchain mode the browser signs program transactions directly and the API only indexes, relays reveals and cranks.

§ 7.2Monorepo

layout
packages/shared            @sealed/shared — types, Zod schemas, PDAs, clearing / fee / commitment math,
                           custody contract (custody.ts), demo world, REST + WS contract
packages/defi              @sealed/defi — Anchor client, Jupiter v6, Raydium adapter (optional),
                           internal-CPMM quotes, encrypted bid vault, Privacy Ring clients
programs/sealed-launchpad  Anchor program sealed_launchpad (onchain mode, roadmap) + tests + devnet init
apps/api                   @sealed/api — Fastify REST + /ws, Prisma/Postgres, Redis, workers, /llms.txt
  src/offchain/            custodial ledger engine, SIWS, deposits, withdrawals (in development)
apps/web                   @sealed/web — Next.js 15 App Router, Tailwind, framer-motion, these docs
tests                      @sealed/e2e — invariant/property tests, black-box API e2e, web smoke
scripts                    deploy-devnet.sh · deploy-api.sh · deploy-web.sh · verify.sh
dependency graph
@sealed/web ──▶ @sealed/defi ──▶ @sealed/shared
     │                                ▲
     └────────────────────────────────┤
@sealed/api ──────────────────────────┘   (the API deliberately does not depend on @sealed/defi)
sealed_launchpad (Rust) mirrors constants.ts and clearing/fees/commitment integer-for-integer

§ 7.3Data flow

Offchain custodial (default)

  1. The browser signs a SIWS message; the API issues a bearer token.
  2. The user transfers SOL/SPL to the company wallet with memo sealed:<depositRef>; the deposit watcher sees it through Helius RPC and credits the ledger after finality.
  3. Commits, reveals, swaps, claims and stakes are API calls that post double-entry ledger transactions.
  4. Schedulers clear auctions, graduate, run drips and split fees on the ledger; events stream over /ws.
  5. Withdrawals are paid from the company wallet by the payout worker, or queued for manual approval.

Onchain (roadmap)

  1. The browser builds and signs program transactions with Wallet Adapter (@sealed/defi client).
  2. The indexer polls getProgramAccounts every 20 s (and on onLogs, debounced 1.5 s), decodes accounts with the IDL and upserts launches.
  3. Diffs become WS events; the API serves the store over REST.

§ 7.4Workers

WorkerFileCadenceRuns whenStatus
Indexerworkers/indexer.ts20 s poll + onLogsnot demo, RPC + IDL presentOnchain mode
Auto-reveal relayerworkers/revealRelayer.ts2 salways; demo marks bids revealedLive in demo
Buyback keeperworkers/buybackKeeper.ts10 snot demo, KEEPER_SECRET_KEY setAccount wiring gap
Demo world ticker@sealed/shared demo.tsDEMO_TICK_MS (1 s)DEMO_MODELive in demo
Ledger engine, deposit watcher, payoutssrc/offchain/**—EXECUTION_MODE=offchainIn development

Workers run in-process with the HTTP server (WORKERS_ENABLED=true) and are stopped on shutdown. The relayer retries a reveal up to 8 times and treats AlreadyRevealed as success.

§ 7.5Storage and cache

Postgres (Prisma)
Models: Launch, Bid, RevealPayload, Trade, BuybackEvent, CreditLedger, HolderReward, ProtocolStats (apps/api/prisma/schema.prisma). The custodial ledger tables are added by the offchain workstream. prisma db push runs on container boot when DATABASE_URL is set.
Memory store
Used when DATABASE_URL is unset (demo). Not durable; a custodial deployment must use Postgres.
Redis
Response cache (1–2 s TTLs on lists, stats, revenue) and the keeper job queue. Falls back to an in-process map when REDIS_URL is unset.
Browser
Encrypted bid salts in IndexedDB; a client-side demo world takes over if the API is unreachable.