Platform foundations
Platform foundations provide the shared services that let the public site, AMA booking, media management, and owner administration run as one system. They keep business data durable, protect public and owner actions, move approved changes through isolated environments, and measure public booking activity without sending personal data to analytics.
Platform role
The platform joins four concerns that cross product boundaries: durable state, request protection, controlled delivery, and safe observation. Public pages can stay fast and mostly static while private operations use the same database, identity boundary, and runtime rules.
The main relationships are:
- Postgres stores product state and shared rate-limit windows.
- Clerk protects owner routes. Server-side metadata identifies the site owner.
- Bunny stores media objects while Postgres stores their catalog and publication state.
- GitHub Actions applies database changes before it deploys the matching application commit.
- Vercel Analytics records anonymous public funnel events. It does not receive guest names, email addresses, briefs, or hold IDs.
Persistence
Database boundary
The application uses a shared Postgres database for the state that must survive a request or a deployment. It covers legacy newsletter records plus the AMA, media, publication, purge, and rate-limit domains. The application connects with a CRUD-only runtime role; migration access is kept outside the running Vercel application. The database and migrations page describes the data model and its evolution.
The database is the source of truth for operational state. External services hold related material, such as media objects or provider events, but the application records the state needed to resume work, prevent duplicate actions, and present a stable result to an owner or guest.
References: db/index.ts• L1-19 db/schema.ts• L23-41 db/schema.ts• L67-87 db/schema.ts• L293-470 db/schema.ts• L843-1091
External object boundary
Media content crosses a separate storage boundary. Bunny holds Originals, Renditions, and transfer chunks in one media zone with distinct paths. Only Renditions are public; Originals and in-progress transfer data remain protected. This lets the database describe and govern an asset without making private source material part of the public web surface.
References: docs/…/0013-one-bunny-media-zone.md• L3-13 db/schema.ts• L293-470 db/schema.ts• L692-791
Security boundaries
Request protection
The runtime applies a common security baseline to public and private responses. It limits where content can load from, blocks framing and unsafe object types, requires transport security, and restricts browser capabilities. Admin pages use a related policy that permits the Clerk browser client, while the Google connection page adds only the OAuth form destination it needs. The runtime security and delivery page covers these controls in more detail.
Public mutations also require a same-origin browser request and a rate-limit check. Admin mutations use the authenticated owner identity as a pseudonymous rate-limit key. Security audit events keep request correlation and action outcomes while avoiding raw client addresses and other sensitive values.
The Next.js runtime also keeps private resume documents and admin API responses out of caches, search indexes, and external referrers. The application sets these route-specific boundaries in next.config.ts, while the shared policy remains in the security header service.
References: next.config.ts• L82-142 lib/…/headers.ts• L31-128 lib/…/service.ts• L90-181 lib/…/http.ts• L62-100
Owner authorization
Clerk is the authentication system for the owner application. Middleware protects the admin route family, then server-side checks require the authenticated Clerk user to carry the exact owner marker publicMetadata.siteOwner = "yes". This separates identity from product records: existing AMA and media owner namespaces do not grant access by themselves.
The protected layout checks ownership again while each page loader checks before it reads owner data. The admin shell can therefore render its shared frame without making the frame itself the authorization decision. Signed-out requests and signed-in non-owners receive deliberate denial responses rather than partial admin data.
References: proxy.ts• L26-43 proxy.ts• L61-82 app/…/layout.tsx• L7-23 app/…/layout.tsx• L17-35
Provider capability boundary
Provider-backed AMA capabilities follow complete credential pairs. Missing pairs leave the related capability unavailable and return a closed failure response; half-configured pairs fail environment validation instead of creating a partly working feature. This keeps payments, email finalization, Google Calendar, and Tencent meeting actions separate from the public database-backed parts of the booking flow.
References: lib/…/server-env-schema.ts• L47-79 lib/…/server-env-schema.ts• L209-285 docs/…/0011-credential-driven-ama-capabilities.md• L11-28
Deployment lifecycle
Environment separation
The project has distinct Local, Preview, Staging, and Production operating modes. Staging and Preview use a non-production Neon project. Production uses a separate Neon project and a protected GitHub environment. Data and credentials do not cross this boundary, and non-production data must remain disposable or irreversibly sanitized.
GitHub Actions is the deployment controller because the schema must be ready before the application starts. Vercel Git deployments stay disabled. A deployment creates or reuses the matching Neon branch, runs migrations with a migration role, obtains a CRUD-only runtime connection, and then deploys the same commit to Vercel.
This diagram shows the shared order for non-production delivery and the stricter production path.
flowchart LR
Commit[Git commit] --> Checks[Required checks]
Checks --> Branch[Neon environment branch]
Branch --> Migrate[Run migrations]
Migrate --> Runtime[Create CRUD-only runtime connection]
Runtime --> Deploy[Deploy matching commit to Vercel]
Deploy --> Verify[Hosted browser verification]
Checks -->|main only| Expand[Expand-only migration check]
Expand --> Migrate
References: .github/…/action.yml• L1-15 .github/…/action.yml• L77-150 .github/…/deploy-staging.yml• L16-49 .github/…/deploy-production.yml• L15-74
Scheduled operations
The runtime uses scheduled requests for work that must continue after a user leaves a page. One scheduled operation reconciles abandoned media transfer state. Another advances durable AMA work such as provider-backed booking actions. These jobs rely on persisted state and retry rules rather than on a browser session.
References: vercel.json• L1-15 db/schema.ts• L473-541 db/schema.ts• L1045-1091
Public route continuity
The public site preserves the legacy URL contract while it evolves. The checked-in manifest defines which old paths stay pages, redirect to new destinations, or rewrite to another internal route. Next.js turns those manifest entries into permanent redirects and rewrites at build time, so public links and search entry points continue to reach the intended content.
References: next.config.ts• L10-26 next.config.ts• L144-148 content/legacy-url-manifest.json• L1-24
Analytics
Public funnel measurement
Vercel Analytics is mounted only in the public site document. It measures a small set of anonymous AMA funnel events so the owner can see where a visitor leaves the flow. Events have no properties by design, and an analytics failure never interrupts booking.
The owner admin uses a separate document path that omits public analytics. This keeps operational screens out of the public measurement stream and prevents booking details from becoming analytics data.
References: lib/analytics.ts• L3-20 app/…/site-document.tsx• L46-73 app/…/site-document.tsx• L78-114
Cross-system contracts
The platform depends on a small set of contracts that connect otherwise separate systems:
| Contract | Shared rule | Downstream effect |
|---|---|---|
| Database access | Runtime uses CRUD access; migrations use a separate path | The deployed code cannot change schema on its own |
| Owner access | Clerk identity plus exact server-side owner metadata | AMA and media tools share one authorization boundary |
| Public media | Only Bunny Renditions are deliverable | Public pages cannot fetch Originals or transfer chunks |
| Capability setup | Provider features require complete credential pairs | Missing providers fail closed instead of exposing partial flows |
| Delivery order | Migrate before deploying the same commit | Code and schema stay compatible during release |
| Analytics | Public events carry no identifying properties | Measurement does not become a second store for guest data |
| Public URLs | Legacy manifest entries map old paths to pages, redirects, or rewrites | Existing links and search paths keep a defined destination |
Change checklist
When these files or sections are changed, remember to consider these:
- A schema change must remain compatible with the migration order and with the CRUD-only runtime role. See database and migrations.
- A new provider-backed action must define its complete credential pair, closed failure response, and environment isolation. Do not add a separate runtime switch without a new platform decision.
- A new owner page or mutation must pass through both the Clerk route boundary and the server-side owner check. Its browser requests must keep the same-origin and rate-limit rules.
- A new public analytics event must remain property-free and must not be mounted in the admin document.
- A change to a deployment branch, runtime role, or migration role must preserve the migrate-before-deploy order for Staging, Preview, and Production.
- A media delivery change must preserve the protected Original and transfer-chunk paths and the public Rendition-only boundary.
- A legacy URL change must keep the manifest entry kind aligned with the redirect or rewrite behavior generated by next.config.ts.
- A route-specific privacy change must be checked against the shared security policy so a narrower path override does not weaken cache, referrer, indexing, or content-source controls.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Migration credentials reach the Vercel runtime | Application code could alter schema outside the reviewed release path | Separate migration and runtime roles; Vercel receives only the CRUD connection |
| Production deploy skips migration compatibility checks | A new application commit can run against an incompatible schema | Production expand-only check runs before migrations |
| A provider credential pair is incomplete | The environment is rejected or the provider action stays unavailable | Environment validation checks pairs; absent capabilities fail closed with 503 |
| A non-owner reaches an admin URL | Owner data or operations could be exposed | Clerk middleware and server-side exact owner metadata checks |
| Public analytics receives booking properties | Guest data could enter an external measurement system | Funnel events accept names only and send no properties |
| Bunny path rules expose Originals or transfer chunks | Raw media or unfinished upload bytes become public | Pull Zone delivery is limited to Renditions and protected paths are denied |
| A private resume or admin API response is cached or indexed | Sensitive content can persist in a browser, proxy, search index, or referrer | Route-specific no-store, noindex, and referrer policies in next.config.ts |
| A legacy URL has the wrong manifest kind or destination | Existing public links can return the wrong page or lose their migration path | Checked-in manifest entries drive the generated redirect and rewrite rules |
Key files
| File | Why to read it |
|---|---|
| db/schema.ts | Shows the durable product state shared by AMA, media, publication, and rate limiting |
| db/index.ts | Shows the application database boundary and pooled runtime connection |
| lib/…/server-env-schema.ts | Defines environment validity, provider capability rules, and rate-limit backend selection |
| proxy.ts | Shows the request-level split between public routes and Clerk-protected admin routes |
| lib/…/headers.ts | Defines the response security baseline and the admin policy variants |
| next.config.ts | Connects route headers, private-response controls, public URL continuity, and packaged runtime assets |
| lib/…/service.ts | Connects same-origin checks, rate limits, audit events, and closed capability failures |
| .github/…/action.yml | Shows the migrate-before-deploy contract for Neon-backed environments |
| .github/…/deploy-production.yml | Shows the protected Production release path and expand-only check |
| vercel.json | Defines scheduled media reconciliation and AMA work |
| lib/analytics.ts | Defines the privacy-safe public funnel measurement contract |
| app/…/site-document.tsx | Shows the separation between public analytics and the owner admin document |
| content/legacy-url-manifest.json | Defines the preserved, redirected, and rewritten public URL contract |
| docs/database-and-migrations.md | Child page for schema, database testing, and migration evolution |
| docs/runtime-security-and-delivery.md | Child page for runtime controls, deployment details, and verification automation |