00002 — Media Asset Delivery Architecture
Images live in a Cloudflare R2 bucket, not in the repository (ADR-002, SR-002). The page path is in 00001.
1. Topology

Two paths meet only in the reader’s browser: the page comes from the Pages project, and each image from assets.<domain>.
2. Components
| Component | Responsibility | Requirements |
|---|---|---|
images/ folder |
Holds every post and application image, as images/posts/<slug>/ and images/applications/<app>/. Git-ignored, so binaries never enter the repository. In development, public/images links to it, so astro dev serves the images locally. |
SR-002 SR-NF-01 |
| Markdown and front matter | Refer to images by root-relative paths, /images/.... The same text works locally and on the deployed site. |
— |
scripts/upload-media.sh |
Runs on the host, started by a person through op run, which supplies the bucket’s access keys. Uploads only files whose content differs from the stored object, never deletes, and refuses any bucket that is not a non-production one. |
SR-002 SR-F-03 |
scripts/promote-media.sh |
Runs in app.yml before the deploy. Lists the images the build links, checks each in the non-production bucket, and copies it inside R2 into the target environment’s bucket; prod’s copy is checked against the checksums the non-production release recorded. |
SR-005 SR-F-10, SR-NF-08 |
| Media bucket | One per environment. Public reads only through assets.<domain>; no listing and no writes through that address, and the r2.dev address is off. The non-production bucket deletes objects after a set number of days. |
SR-002 SR-F-03, SR-NF-02 |
| Image source resolver | src/lib/image-source.mjs and the rehype plugin src/lib/rehype-image-source.mjs. At build time they prefix every /images/... path, in front matter and in Markdown, with the environment’s media base URL. With no base URL set, the path stays local. |
SR-003 SR-F-04 |
| Content-Security-Policy | scripts/write-headers.mjs adds the media origin to img-src, so the browser loads images from it. |
SR-009 SR-F-02 |
3. Flows
Author
- Save the image under
images/. A diagram is exported there bynpm run export:diagrams. - Refer to it in Markdown as
/images/.... - Commit the Markdown only. The image stays out of Git.
- Upload new and changed images to the non-production bucket with
scripts/upload-media.shthroughop run. Never to production: images reach it only through a release.
Build
app.ymlbuilds the site for an environment when a person releases it there, with that environment’s media base URL as a build variable (00006).- The resolver writes
https://assets.<domain>/images/...into every image reference in the HTML. - Before the deploy,
scripts/promote-media.shcopies the images the build links from the non-production bucket into the environment’s own, inside R2. A non-production release copies them onto themselves, which restarts their expiry, and records their checksums; a production release copies the images of the tested non-production build and checks them against those checksums (ADR-006).
Read
- The browser loads the page from the Pages project.
- It loads each image from
assets.<domain>, through the same zone, TLS settings and firewall as the page.
Because media is not bundled into dist/, build and deploy time does not grow with the number of images (BRD-002).
4. How a release copies images: server-side in R2
The release copies images with the S3 CopyObject call, which R2 carries out inside the account, bucket to bucket. The GitHub runner sends one request per image and never holds the image itself, and production receives the object the non-production release served, checked against its recorded checksum.
The copy key pair reads objects in the non-production bucket and writes objects in its own environment’s bucket, nothing else (00005). Why a server-side copy was chosen, and the alternatives considered: ADR-006 — Release Media by Server-Side Copy from the Test Bucket.
Related Documents
- BRD-002 — Media Asset Delivery and Repository Hygiene
- SR-002 — Media Asset Delivery
- ADR-002 — Media Storage Decoupling with Cloudflare R2
- ADR-006 — Release Media by Server-Side Copy from the Test Bucket
- 00001 — Static Website Deployment Architecture
- 00003 — Delivery Pipeline Architecture
- 00005 — Access Boundaries Architecture