# sudodevstudio/fastly-for-astro architecture

> Architecture diagram of the GitHub repository sudodevstudio/fastly-for-astro, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sudodevstudio/fastly-for-astro
- Repository: https://github.com/sudodevstudio/fastly-for-astro
- Video tour (about a minute): https://gitdiagram.com/sudodevstudio/fastly-for-astro/video

## Overview

This is an Astro adapter that turns an Astro server build into a Fastly Compute application. The main request path receives a Fastly request, tries KV-backed static publishing except for server-island URLs, then invokes Astro SSR; the handler adds cache/security headers and optional observability. Build-time adapter configuration and generated runtime assets support that path, while encryption shims enable server-island support. The request and handler links are shown in excerpts; KV publishing and several advertised capabilities are documented but their implementation is not fully sampled.

Main entry points: [`templates/compute-entry.js`](https://github.com/sudodevstudio/fastly-for-astro/blob/main/templates/compute-entry.js) (Compute Entry Template), [`src/index.ts`](https://github.com/sudodevstudio/fastly-for-astro/blob/main/src/index.ts) (Adapter Integration), [`src/runtime/handler.ts`](https://github.com/sudodevstudio/fastly-for-astro/blob/main/src/runtime/handler.ts) (SSR Request Handler), [`src/build/generate-compute-app.ts`](https://github.com/sudodevstudio/fastly-for-astro/blob/main/src/build/generate-compute-app.ts) (Compute App Generation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_build["Adapter and Build"]
  node_adapter["Adapter Integration<br/>[index.ts]"]
  node_options["Option Resolution<br/>[options.ts]"]
  node_compute_generation["Compute App Generation"]
  node_runtime_config["Runtime Config<br/>[runtime-config.ts]"]
  node_static_publish_config["Static Publish Config"]
  node_static_publish_rc["Publisher Runtime Config"]
end

subgraph group_edge["Fastly Request Runtime"]
  node_entry_template["Compute Entry Template<br/>[compute-entry.js]"]
  node_publisher["Static Publisher<br/>[compute-entry.js]"]
  node_kv[("KV Static Assets")]
end

subgraph group_astro["Astro Rendering"]
  node_server_entry["Astro Server Entry<br/>[server-entry.ts]"]
  node_handler["SSR Request Handler<br/>[handler.ts]"]
  node_path["URL Reconstruction<br/>[path.ts]"]
end

subgraph group_policy["Response Policy"]
  node_headers["Cache and Security<br/>[headers.ts]"]
  node_observability["Request Observability<br/>[observability.ts]"]
end

subgraph group_islands["Islands and Crypto"]
  node_islands["Astro Server Islands"]
  node_encryption_shim["Astro Encryption Shim"]
  node_crypto_polyfill["AES-GCM Polyfill<br/>[crypto-polyfill.js]"]
end

node_astro_user(("Astro App"))
node_fastly(("Fastly Compute"))

node_astro_user -->|"configures"| node_adapter
node_adapter -->|"resolves options"| node_options
node_adapter -->|"writes config"| node_runtime_config
node_adapter -->|"generates app"| node_compute_generation
node_compute_generation -.->|"uses template"| node_entry_template
node_fastly -->|"dispatches request"| node_entry_template
node_entry_template -->|"tries static lookup"| node_publisher
node_publisher -.->|"serves published assets"| node_kv
node_entry_template -->|"imports handler"| node_server_entry
node_server_entry -->|"creates handler"| node_handler
node_handler -->|"reconstructs URL"| node_path
node_handler -->|"classifies and applies"| node_headers
node_handler -->|"records timings"| node_observability
node_handler -->|"renders app routes"| node_astro_user
node_entry_template -->|"routes island requests"| node_islands
node_adapter -->|"aliases Astro encryption"| node_encryption_shim
node_entry_template -->|"installs polyfill"| node_crypto_polyfill
node_islands -.->|"encrypts island props"| node_encryption_shim
node_static_publish_config -.->|"configures publishing"| node_kv
node_static_publish_rc -.->|"configures publisher"| node_publisher

click node_adapter "https://github.com/sudodevstudio/fastly-for-astro/blob/main/src/index.ts"
click node_options "https://github.com/sudodevstudio/fastly-for-astro/blob/main/src/options.ts"
click node_compute_generation "https://github.com/sudodevstudio/fastly-for-astro/blob/main/src/build/generate-compute-app.ts"
click node_runtime_config "https://github.com/sudodevstudio/fastly-for-astro/blob/main/src/build/runtime-config.ts"
click node_entry_template "https://github.com/sudodevstudio/fastly-for-astro/blob/main/templates/compute-entry.js"
click node_publisher "https://github.com/sudodevstudio/fastly-for-astro/blob/main/templates/compute-entry.js"
click node_server_entry "https://github.com/sudodevstudio/fastly-for-astro/blob/main/src/runtime/server-entry.ts"
click node_handler "https://github.com/sudodevstudio/fastly-for-astro/blob/main/src/runtime/handler.ts"
click node_path "https://github.com/sudodevstudio/fastly-for-astro/blob/main/src/runtime/path.ts"
click node_headers "https://github.com/sudodevstudio/fastly-for-astro/blob/main/src/runtime/headers.ts"
click node_observability "https://github.com/sudodevstudio/fastly-for-astro/blob/main/src/runtime/observability.ts"
click node_encryption_shim "https://github.com/sudodevstudio/fastly-for-astro/blob/main/src/runtime/shims/astro-encryption.ts"
click node_crypto_polyfill "https://github.com/sudodevstudio/fastly-for-astro/blob/main/templates/crypto-polyfill.js"
click node_static_publish_config "https://github.com/sudodevstudio/fastly-for-astro/blob/main/templates/publish-content.config.js"
click node_static_publish_rc "https://github.com/sudodevstudio/fastly-for-astro/blob/main/templates/static-publish.rc.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_adapter,node_options,node_compute_generation,node_runtime_config,node_static_publish_config,node_static_publish_rc toneBlue
class node_entry_template,node_publisher,node_kv toneAmber
class node_server_entry,node_handler,node_path toneMint
class node_headers,node_observability toneRose
class node_islands,node_encryption_shim,node_crypto_polyfill,node_astro_user,node_fastly toneIndigo
```

## Components

### Adapter and Build

- [Adapter Integration](https://github.com/sudodevstudio/fastly-for-astro/blob/main/src/index.ts): `src/index.ts`
- [Option Resolution](https://github.com/sudodevstudio/fastly-for-astro/blob/main/src/options.ts): `src/options.ts`
- [Compute App Generation](https://github.com/sudodevstudio/fastly-for-astro/blob/main/src/build/generate-compute-app.ts): `src/build/generate-compute-app.ts`
- [Runtime Config](https://github.com/sudodevstudio/fastly-for-astro/blob/main/src/build/runtime-config.ts): `src/build/runtime-config.ts`
- [Static Publish Config](https://github.com/sudodevstudio/fastly-for-astro/blob/main/templates/publish-content.config.js): `templates/publish-content.config.js`
- [Publisher Runtime Config](https://github.com/sudodevstudio/fastly-for-astro/blob/main/templates/static-publish.rc.js): `templates/static-publish.rc.js`

### Fastly Request Runtime

- [Compute Entry Template](https://github.com/sudodevstudio/fastly-for-astro/blob/main/templates/compute-entry.js): `templates/compute-entry.js`
- [Static Publisher](https://github.com/sudodevstudio/fastly-for-astro/blob/main/templates/compute-entry.js): `templates/compute-entry.js`
- **KV Static Assets**

### Astro Rendering

- [Astro Server Entry](https://github.com/sudodevstudio/fastly-for-astro/blob/main/src/runtime/server-entry.ts): `src/runtime/server-entry.ts`
- [SSR Request Handler](https://github.com/sudodevstudio/fastly-for-astro/blob/main/src/runtime/handler.ts): `src/runtime/handler.ts`
- [URL Reconstruction](https://github.com/sudodevstudio/fastly-for-astro/blob/main/src/runtime/path.ts): `src/runtime/path.ts`

### Response Policy

- [Cache and Security](https://github.com/sudodevstudio/fastly-for-astro/blob/main/src/runtime/headers.ts): `src/runtime/headers.ts`
- [Request Observability](https://github.com/sudodevstudio/fastly-for-astro/blob/main/src/runtime/observability.ts): `src/runtime/observability.ts`

### Islands and Crypto

- **Astro Server Islands**
- [Astro Encryption Shim](https://github.com/sudodevstudio/fastly-for-astro/blob/main/src/runtime/shims/astro-encryption.ts): `src/runtime/shims/astro-encryption.ts`
- [AES-GCM Polyfill](https://github.com/sudodevstudio/fastly-for-astro/blob/main/templates/crypto-polyfill.js): `templates/crypto-polyfill.js`

### Other components

- **Astro App**
- **Fastly Compute**

## Connections

- Astro App → Adapter Integration: configures (evidence: `README.md`)
- Adapter Integration → Option Resolution: resolves options (evidence: `src/index.ts`)
- Adapter Integration → Runtime Config: writes config (evidence: `src/index.ts`)
- Adapter Integration → Compute App Generation: generates app (evidence: `src/index.ts`)
- Compute App Generation → Compute Entry Template: uses template
- Fastly Compute → Compute Entry Template: dispatches request (evidence: `templates/compute-entry.js`)
- Compute Entry Template → Static Publisher: tries static lookup (evidence: `templates/compute-entry.js`)
- Static Publisher → KV Static Assets: serves published assets
- Compute Entry Template → Astro Server Entry: imports handler (evidence: `templates/compute-entry.js`)
- Astro Server Entry → SSR Request Handler: creates handler (evidence: `src/runtime/server-entry.ts`)
- SSR Request Handler → URL Reconstruction: reconstructs URL (evidence: `src/runtime/handler.ts`)
- SSR Request Handler → Cache and Security: classifies and applies (evidence: `src/runtime/handler.ts`)
- SSR Request Handler → Request Observability: records timings (evidence: `src/runtime/handler.ts`)
- SSR Request Handler → Astro App: renders app routes (evidence: `src/runtime/handler.ts`)
- Compute Entry Template → Astro Server Islands: routes island requests (evidence: `templates/compute-entry.js`)
- Adapter Integration → Astro Encryption Shim: aliases Astro encryption (evidence: `src/index.ts`)
- Compute Entry Template → AES-GCM Polyfill: installs polyfill (evidence: `templates/compute-entry.js`)
- Astro Server Islands → Astro Encryption Shim: encrypts island props
- Static Publish Config → KV Static Assets: configures publishing
- Publisher Runtime Config → Static Publisher: configures publisher
