# coda0hq/open-artifacts architecture

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

- Interactive diagram: https://gitdiagram.com/coda0hq/open-artifacts
- Repository: https://github.com/coda0hq/open-artifacts

## Overview

Open Artifacts is a self-hosted Cloudflare service and companion agent CLI for publishing versioned, shareable HTML/Markdown artifacts. The main path is agent-authored Recipe and fragments → CLI composition and validation → Worker API → persistent versioned content → sandboxed viewer URL; later updates can keep the same URL. The service also supports password-encrypted artifacts, comments, live updates, recorded walkthrough handoffs, and link previews. Edges follow the README or shown source-index references; finer runtime wiring in unsampled code is intentionally omitted.

Main entry points: [`src/app.ts`](https://github.com/coda0hq/open-artifacts/blob/main/src/app.ts) (Cloudflare Worker), [`src/api.ts`](https://github.com/coda0hq/open-artifacts/blob/main/src/api.ts) (Artifact API), [`skills/using-open-artifacts/scripts/artifact.mjs`](https://github.com/coda0hq/open-artifacts/blob/main/skills/using-open-artifacts/scripts/artifact.mjs) (Artifact CLI), [`src/store.ts`](https://github.com/coda0hq/open-artifacts/blob/main/src/store.ts) (Artifact store)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_authoring["Agent authoring"]
  node_cli["Artifact CLI<br/>[artifact.mjs]"]
  node_recipe["Recipe and fragments<br/>[recipe.mjs]"]
  node_compose["Artifact composition<br/>[compose.mjs]"]
  node_quality["Build validation<br/>[validate.mjs]"]
end

subgraph group_service["Worker service"]
  node_worker["Cloudflare Worker<br/>[app.ts]"]
  node_api["Artifact API<br/>[api.ts]"]
  node_domain["Domain validation<br/>[domain.ts]"]
  node_auth["Authorization<br/>[authorizer.ts]"]
end

subgraph group_persistence["Persistence"]
  node_store["Artifact store<br/>[store.ts]"]
  node_d1[("D1 metadata")]
  node_r2[("R2 content")]
end

subgraph group_viewer["Artifact viewing"]
  node_viewer["Artifact viewer<br/>[wrap.ts]"]
  node_og["Link preview cards<br/>[og.ts]"]
end

subgraph group_collaboration["Collaboration"]
  node_live["Live updates<br/>[live-api.ts]"]
  node_liveobject["Live connection state<br/>[live-do.ts]"]
  node_comments["Comments and anchors<br/>[api.ts]"]
  node_handoff["Walkthrough handoff<br/>[index.ts]"]
  node_preview["Camera preview<br/>[preview.ts]"]
end

node_agent(("Coding agent"))
node_url(("Shareable URL"))
node_visitor(("Artifact visitor"))

node_agent -->|"runs"| node_cli
node_cli -->|"reads inputs"| node_recipe
node_cli -->|"composes output"| node_compose
node_compose -->|"reads fragments"| node_recipe
node_cli -->|"validates output"| node_quality
node_cli -->|"publishes request"| node_worker
node_worker -->|"routes API"| node_api
node_worker -->|"serves pages"| node_viewer
node_worker -->|"renders card"| node_og
node_api -->|"validates inputs"| node_domain
node_api -->|"authorizes actions"| node_auth
node_api -->|"reads and writes"| node_store
node_store -->|"stores metadata"| node_d1
node_store -->|"stores content"| node_r2
node_api -->|"broadcasts version"| node_live
node_live -->|"dispatches updates"| node_liveobject
node_visitor -->|"opens"| node_url
node_url -->|"requests page"| node_worker
node_worker -->|"loads artifact"| node_store
node_worker -->|"embeds dock"| node_handoff
node_handoff -->|"requests camera"| node_preview
node_visitor -->|"posts comments"| node_api
node_worker -->|"returns share link"| node_url

click node_cli "https://github.com/coda0hq/open-artifacts/blob/main/skills/using-open-artifacts/scripts/artifact.mjs"
click node_recipe "https://github.com/coda0hq/open-artifacts/blob/main/skills/using-open-artifacts/scripts/lib/recipe.mjs"
click node_compose "https://github.com/coda0hq/open-artifacts/blob/main/skills/using-open-artifacts/scripts/lib/compose.mjs"
click node_quality "https://github.com/coda0hq/open-artifacts/blob/main/skills/using-open-artifacts/scripts/lib/validate.mjs"
click node_worker "https://github.com/coda0hq/open-artifacts/blob/main/src/app.ts"
click node_api "https://github.com/coda0hq/open-artifacts/blob/main/src/api.ts"
click node_domain "https://github.com/coda0hq/open-artifacts/blob/main/src/domain.ts"
click node_auth "https://github.com/coda0hq/open-artifacts/blob/main/src/authorizer.ts"
click node_store "https://github.com/coda0hq/open-artifacts/blob/main/src/store.ts"
click node_viewer "https://github.com/coda0hq/open-artifacts/blob/main/src/wrap.ts"
click node_live "https://github.com/coda0hq/open-artifacts/blob/main/src/live-api.ts"
click node_liveobject "https://github.com/coda0hq/open-artifacts/blob/main/src/live-do.ts"
click node_comments "https://github.com/coda0hq/open-artifacts/blob/main/src/api.ts"
click node_handoff "https://github.com/coda0hq/open-artifacts/blob/main/src/handoff/index.ts"
click node_preview "https://github.com/coda0hq/open-artifacts/blob/main/src/handoff/preview.ts"
click node_og "https://github.com/coda0hq/open-artifacts/blob/main/src/og.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_cli,node_recipe,node_compose,node_quality toneBlue
class node_worker,node_api,node_domain,node_auth toneAmber
class node_store,node_d1,node_r2 toneMint
class node_viewer,node_og toneRose
class node_live,node_liveobject,node_comments,node_handoff,node_preview,node_agent,node_url,node_visitor toneIndigo
```

## Components

### Agent authoring

- [Artifact CLI](https://github.com/coda0hq/open-artifacts/blob/main/skills/using-open-artifacts/scripts/artifact.mjs): `skills/using-open-artifacts/scripts/artifact.mjs`
- [Recipe and fragments](https://github.com/coda0hq/open-artifacts/blob/main/skills/using-open-artifacts/scripts/lib/recipe.mjs): `skills/using-open-artifacts/scripts/lib/recipe.mjs`
- [Artifact composition](https://github.com/coda0hq/open-artifacts/blob/main/skills/using-open-artifacts/scripts/lib/compose.mjs): `skills/using-open-artifacts/scripts/lib/compose.mjs`
- [Build validation](https://github.com/coda0hq/open-artifacts/blob/main/skills/using-open-artifacts/scripts/lib/validate.mjs): `skills/using-open-artifacts/scripts/lib/validate.mjs`

### Worker service

- [Cloudflare Worker](https://github.com/coda0hq/open-artifacts/blob/main/src/app.ts): `src/app.ts`
- [Artifact API](https://github.com/coda0hq/open-artifacts/blob/main/src/api.ts): `src/api.ts`
- [Domain validation](https://github.com/coda0hq/open-artifacts/blob/main/src/domain.ts): `src/domain.ts`
- [Authorization](https://github.com/coda0hq/open-artifacts/blob/main/src/authorizer.ts): `src/authorizer.ts`

### Persistence

- [Artifact store](https://github.com/coda0hq/open-artifacts/blob/main/src/store.ts): `src/store.ts`
- **D1 metadata**
- **R2 content**

### Artifact viewing

- [Artifact viewer](https://github.com/coda0hq/open-artifacts/blob/main/src/wrap.ts): `src/wrap.ts`
- [Link preview cards](https://github.com/coda0hq/open-artifacts/blob/main/src/og.ts): `src/og.ts`

### Collaboration

- [Live updates](https://github.com/coda0hq/open-artifacts/blob/main/src/live-api.ts): `src/live-api.ts`
- [Live connection state](https://github.com/coda0hq/open-artifacts/blob/main/src/live-do.ts): `src/live-do.ts`
- [Comments and anchors](https://github.com/coda0hq/open-artifacts/blob/main/src/api.ts): `src/api.ts`
- [Walkthrough handoff](https://github.com/coda0hq/open-artifacts/blob/main/src/handoff/index.ts): `src/handoff/index.ts`
- [Camera preview](https://github.com/coda0hq/open-artifacts/blob/main/src/handoff/preview.ts): `src/handoff/preview.ts`

### Other components

- **Coding agent**
- **Shareable URL**
- **Artifact visitor**

## Connections

- Coding agent → Artifact CLI: runs
- Artifact CLI → Recipe and fragments: reads inputs (evidence: `skills/using-open-artifacts/scripts/artifact.mjs`)
- Artifact CLI → Artifact composition: composes output (evidence: `skills/using-open-artifacts/scripts/artifact.mjs`)
- Artifact composition → Recipe and fragments: reads fragments (evidence: `skills/using-open-artifacts/scripts/lib/compose.mjs`)
- Artifact CLI → Build validation: validates output (evidence: `skills/using-open-artifacts/scripts/artifact.mjs`)
- Artifact CLI → Cloudflare Worker: publishes request
- Cloudflare Worker → Artifact API: routes API (evidence: `src/app.ts`)
- Cloudflare Worker → Artifact viewer: serves pages (evidence: `src/app.ts`)
- Cloudflare Worker → Link preview cards: renders card (evidence: `src/app.ts`)
- Artifact API → Domain validation: validates inputs (evidence: `src/api.ts`)
- Artifact API → Authorization: authorizes actions (evidence: `src/api.ts`)
- Artifact API → Artifact store: reads and writes (evidence: `src/api.ts`)
- Artifact store → D1 metadata: stores metadata
- Artifact store → R2 content: stores content
- Artifact API → Live updates: broadcasts version (evidence: `src/api.ts`)
- Live updates → Live connection state: dispatches updates (evidence: `src/live-api.ts`)
- Artifact visitor → Shareable URL: opens
- Shareable URL → Cloudflare Worker: requests page
- Cloudflare Worker → Artifact store: loads artifact (evidence: `src/app.ts`)
- Cloudflare Worker → Walkthrough handoff: embeds dock
- Walkthrough handoff → Camera preview: requests camera (evidence: `src/handoff/index.ts`)
- Artifact visitor → Artifact API: posts comments
- Cloudflare Worker → Shareable URL: returns share link
