# drupflare/worker architecture

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

- Interactive diagram: https://gitdiagram.com/drupflare/worker
- Repository: https://github.com/drupflare/worker

## Overview

Drupflare runs Drupal 11 on Cloudflare Workers, executing PHP/Wasm inside a Durable Object backed by its SQLite storage. The main request path serves static assets and cached pages before PHP renders a miss; renders then populate caches. The graph also preserves documented replica lanes, alarm-driven maintenance and repair, and owner administration. Some subsystem links are documented only at a high level; unsampled implementation details are not inferred.

Main entry points: [`src/site-do.ts`](https://github.com/drupflare/worker/blob/master/src/site-do.ts) (Site Durable Object), [`src/site.ts`](https://github.com/drupflare/worker/blob/master/src/site.ts) (Worker entry), [`src/site/edge-cache.ts`](https://github.com/drupflare/worker/blob/master/src/site/edge-cache.ts) (Edge cache), [`src/site/routes.ts`](https://github.com/drupflare/worker/blob/master/src/site/routes.ts) (Site routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_front["Request serving"]
  node_assets["Static assets"]
  node_worker["Worker entry<br/>[site.ts]"]
  node_routes["Site routes<br/>[routes.ts]"]
  node_edgecache["Edge cache<br/>[edge-cache.ts]"]
end

subgraph group_runtime["Drupal runtime"]
  node_do["Site Durable Object<br/>[site-do.ts]"]
  node_fill["Page filling<br/>[fill.ts]"]
  node_php["Drupal PHP<br/>[site-php.ts]"]
  node_wasm["PHP Wasm runtime<br/>[php-binary.ts]"]
  node_capabilities["PHP capabilities<br/>[capabilities.ts]"]
end

subgraph group_operations["Operations"]
  node_alarms["Alarm maintenance<br/>[alarm-body.ts]"]
  node_repair["Self-repair<br/>[repair.ts]"]
  node_replicas["Replica routing<br/>[replica-routing.ts]"]
  node_admin["Admin surfaces<br/>[admin.ts]"]
  node_auth["Owner and OIDC<br/>[auth.ts]"]
end

subgraph group_data["State and storage"]
  node_pagecache[("Page cache<br/>[site-do.ts]")]
  node_sql[("Durable SQLite<br/>[backend.ts]")]
  node_filestore[("File storage<br/>[file-store.ts]")]
end

node_visitor(("Visitor"))

node_visitor -->|"requests assets"| node_assets
node_visitor -->|"requests pages"| node_worker
node_assets -->|"serves static files"| node_visitor
node_worker -.->|"routes requests"| node_routes
node_worker -->|"checks cache"| node_edgecache
node_edgecache -->|"returns cached page"| node_visitor
node_edgecache -->|"miss reaches"| node_do
node_do -->|"reads cached pages"| node_pagecache
node_do -->|"fills cache misses"| node_fill
node_fill -.->|"renders pages"| node_php
node_php -.->|"executes PHP"| node_wasm
node_do -->|"uses object SQLite"| node_sql
node_pagecache -->|"stored in"| node_sql
node_do -->|"stores Drupal files"| node_filestore
node_do -->|"runs alarm work"| node_alarms
node_alarms -->|"checks and repairs"| node_repair
node_do -->|"selects replica lane"| node_replicas
node_visitor -->|"uses administration"| node_admin
node_admin -->|"drives site routes"| node_routes
node_routes -->|"routes authentication"| node_auth
node_do -->|"installs PHP hooks"| node_capabilities
node_capabilities -->|"accesses files"| node_filestore

click node_worker "https://github.com/drupflare/worker/blob/master/src/site.ts"
click node_routes "https://github.com/drupflare/worker/blob/master/src/site/routes.ts"
click node_edgecache "https://github.com/drupflare/worker/blob/master/src/site/edge-cache.ts"
click node_do "https://github.com/drupflare/worker/blob/master/src/site-do.ts"
click node_fill "https://github.com/drupflare/worker/blob/master/src/do/fill.ts"
click node_php "https://github.com/drupflare/worker/blob/master/src/drupal/site-php.ts"
click node_wasm "https://github.com/drupflare/worker/blob/master/src/runtime/php-binary.ts"
click node_pagecache "https://github.com/drupflare/worker/blob/master/src/site-do.ts"
click node_sql "https://github.com/drupflare/worker/blob/master/src/db/backend.ts"
click node_filestore "https://github.com/drupflare/worker/blob/master/src/db/file-store.ts"
click node_alarms "https://github.com/drupflare/worker/blob/master/src/do/alarm-body.ts"
click node_repair "https://github.com/drupflare/worker/blob/master/src/ops/repair.ts"
click node_replicas "https://github.com/drupflare/worker/blob/master/src/ops/replica-routing.ts"
click node_admin "https://github.com/drupflare/worker/blob/master/src/ui/admin.ts"
click node_auth "https://github.com/drupflare/worker/blob/master/src/do/routes/auth.ts"
click node_capabilities "https://github.com/drupflare/worker/blob/master/src/do/capabilities.ts"

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_assets,node_worker,node_routes,node_edgecache toneBlue
class node_do,node_fill,node_php,node_wasm,node_capabilities toneAmber
class node_alarms,node_repair,node_replicas,node_admin,node_auth toneMint
class node_pagecache,node_sql,node_filestore toneRose
class node_visitor toneIndigo
```

## Components

### Request serving

- **Static assets**
- [Worker entry](https://github.com/drupflare/worker/blob/master/src/site.ts): `src/site.ts`
- [Site routes](https://github.com/drupflare/worker/blob/master/src/site/routes.ts): `src/site/routes.ts`
- [Edge cache](https://github.com/drupflare/worker/blob/master/src/site/edge-cache.ts): `src/site/edge-cache.ts`

### Drupal runtime

- [Site Durable Object](https://github.com/drupflare/worker/blob/master/src/site-do.ts): `src/site-do.ts`
- [Page filling](https://github.com/drupflare/worker/blob/master/src/do/fill.ts): `src/do/fill.ts`
- [Drupal PHP](https://github.com/drupflare/worker/blob/master/src/drupal/site-php.ts): `src/drupal/site-php.ts`
- [PHP Wasm runtime](https://github.com/drupflare/worker/blob/master/src/runtime/php-binary.ts): `src/runtime/php-binary.ts`
- [PHP capabilities](https://github.com/drupflare/worker/blob/master/src/do/capabilities.ts): `src/do/capabilities.ts`

### Operations

- [Alarm maintenance](https://github.com/drupflare/worker/blob/master/src/do/alarm-body.ts): `src/do/alarm-body.ts`
- [Self-repair](https://github.com/drupflare/worker/blob/master/src/ops/repair.ts): `src/ops/repair.ts`
- [Replica routing](https://github.com/drupflare/worker/blob/master/src/ops/replica-routing.ts): `src/ops/replica-routing.ts`
- [Admin surfaces](https://github.com/drupflare/worker/blob/master/src/ui/admin.ts): `src/ui/admin.ts`
- [Owner and OIDC](https://github.com/drupflare/worker/blob/master/src/do/routes/auth.ts): `src/do/routes/auth.ts`

### State and storage

- [Page cache](https://github.com/drupflare/worker/blob/master/src/site-do.ts): `src/site-do.ts`
- [Durable SQLite](https://github.com/drupflare/worker/blob/master/src/db/backend.ts): `src/db/backend.ts`
- [File storage](https://github.com/drupflare/worker/blob/master/src/db/file-store.ts): `src/db/file-store.ts`

### Other components

- **Visitor**

## Connections

- Visitor → Static assets: requests assets
- Visitor → Worker entry: requests pages
- Static assets → Visitor: serves static files
- Worker entry → Site routes: routes requests
- Worker entry → Edge cache: checks cache
- Edge cache → Visitor: returns cached page
- Edge cache → Site Durable Object: miss reaches
- Site Durable Object → Page cache: reads cached pages (evidence: `src/site-do.ts`)
- Site Durable Object → Page filling: fills cache misses (evidence: `src/site-do.ts`)
- Page filling → Drupal PHP: renders pages
- Drupal PHP → PHP Wasm runtime: executes PHP
- Site Durable Object → Durable SQLite: uses object SQLite (evidence: `src/site-do.ts`)
- Page cache → Durable SQLite: stored in (evidence: `src/site-do.ts`)
- Site Durable Object → File storage: stores Drupal files (evidence: `src/site-do.ts`)
- Site Durable Object → Alarm maintenance: runs alarm work (evidence: `src/site-do.ts`)
- Alarm maintenance → Self-repair: checks and repairs
- Site Durable Object → Replica routing: selects replica lane (evidence: `src/site-do.ts`)
- Visitor → Admin surfaces: uses administration
- Admin surfaces → Site routes: drives site routes (evidence: `src/site/routes.ts`)
- Site routes → Owner and OIDC: routes authentication (evidence: `src/site/routes.ts`)
- Site Durable Object → PHP capabilities: installs PHP hooks (evidence: `src/site-do.ts`)
- PHP capabilities → File storage: accesses files (evidence: `src/do/capabilities.ts`)
