00001 — Static Website Deployment Architecture

By Engineering Team•October 12, 2026•5 min read

The site is static Astro output hosted on Cloudflare Pages (ADR-001), with media in a Cloudflare R2 bucket (ADR-002). Every edge setting below is declared in the site’s OpenTofu module, deploy/modules/site/, and applied the same way to non-production and production. Requirement IDs refer to SR-009 unless stated.


1. Request path

Request path: the reader's browser reaches the Cloudflare zone, passes DNS, TLS and the firewall, and is sent to the Pages project for the domain or to the media bucket for the assets address; a blocked request never reaches an origin

Each environment has its own zone: <test-domain> for non-production and <domain> for production. Two addresses are served in each zone:

  • <domain> (and www) is the Pages project, which holds the built dist/ folder and nothing else.
  • assets.<domain> is the media bucket, attached to the zone as a custom domain.

Both addresses pass the same TLS settings and firewall rules, because both are in the same zone.


2. Components

Component Responsibility Declared in Requirements
DNS A record for the host pointing at the Pages project, and www pointing at the host. The media address’s record is created by Cloudflare when the bucket’s custom domain is attached. dns.tf —
Zone baseline TLS and HSTS, Cloudflare’s managed rules, two custom firewall rules, a per-client rate limit over the whole zone, and the threat settings, from the shared site module. Described once in Zone Baseline. tls.tf, waf.tf, security.tf SR-INFRA-008
Pages project Hosts one environment’s built site. Deployed by direct upload from the pipeline, so Cloudflare needs no access to the repository. It exposes no separate origin. pages.tf SR-001 SR-F-02, SR-F-03; SR-009 SR-F-05
Media bucket Holds the site’s public images. Served only at assets.<domain>; its r2.dev address is turned off, so media cannot be reached around the zone. storage.tf SR-009 SR-F-04
Security headers X-Frame-Options, X-Content-Type-Options, Referrer-Policy and a Content-Security-Policy on every page, and a one-year immutable cache on /_astro/*. public/_headers, rewritten by scripts/write-headers.mjs at build SR-009 SR-F-02, SR-F-03

3. Read flow

  1. The reader’s browser asks for https://<domain>/.... Plain HTTP is redirected to HTTPS.
  2. The zone applies the managed ruleset, the custom rules, the rate limit and the threat settings. A request that fails any of them is blocked at the edge and never reaches Pages or the bucket.
  3. A page request is answered by the Pages project, through Cloudflare’s cache.
  4. The page’s images point at https://assets.<domain>/images/..., so the browser fetches them from the media bucket through the same zone.
  5. Every page response carries the security headers. The policy allows images from the media address and each inline script by its hash.

4. Content-Security-Policy

The policy is computed per build, not written by hand. npm run build runs astro build, then scripts/write-headers.mjs rewrites the policy line in dist/_headers:

  • img-src adds the origin of the environment’s media address.
  • script-src lists the SHA-256 hash of every inline script in dist/, never 'unsafe-inline'.
  • style-src keeps 'unsafe-inline', because highlighted code blocks carry inline styles a hash cannot cover.
  • Fonts, icons and analytics are allowed from their named hosts only.

The build fails when the policy passes the length Pages allows for one header.


5. Non-production and production

Both environments call the same module with different inputs: hostname, zone, Pages project, media bucket, HSTS age and rate-limit threshold. The only difference in shape is an expiry rule on the non-production media bucket, which keeps test media inside the free storage limit. The infrastructure is applied by the layers described in Layered Environments.


6. Cost and failure behaviour

  • Cost: hosting, bandwidth, the managed ruleset, the custom rules and the rate limit run on the free plan, and R2 has no egress charge, so a traffic flood cannot produce a bill (BRD-001 BR-1.1, BR-1.2).
  • Traffic surge: pages and media are cached at the edge, so load does not reach a single origin (BRD-001 BR-3.2).