# 0xnyn/airship architecture

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

- Interactive diagram: https://gitdiagram.com/0xnyn/airship
- Repository: https://github.com/0xnyn/airship

## Overview

#### Purpose and launch path
Airship is a local, Node 22+ visual editor placed in front of an existing HTTP dev server. It opens a browser editor, lets users select rendered elements or modify styles, then delegates source edits to Claude Code, Codex, or OpenCode. The published CLI is the primary entry point: `apps/cli/src/index.ts`, with launch orchestration in `apps/cli/src/commands/serve.ts`; `airship` and `airship.cmd` are repository-level launch shims.

#### CLI configuration and environment validation
The CLI parses flags, resolves settings from flags/environment/project configuration/defaults, detects a target dev-server port, optionally starts the dev command, and checks prerequisites. The configuration boundary is `apps/cli/src/lib/config.ts` and `apps/cli/src/lib/settings.ts`; target discovery is `apps/cli/src/lib/detect.ts`. `doctor` is a separate diagnostic entry path in `apps/cli/src/commands/doctor.ts`. CLI-facing behavior should remain independent of any particular target framework.

#### Local proxy and session server
The server binds loopback by default, validates host access, proxies the target application, and adapts responses so the editor can frame or overlay the target page. It owns HTTP-facing safety boundaries such as allowed hosts, CSP handling, and frame-header removal. Core server modules are `packages/server/src/index.ts`, `packages/server/src/proxy.ts`, and `packages/server/src/access.ts`. It also manages edit jobs/history and editor-launch integration through `packages/server/src/jobs.ts`, `packages/server/src/history.ts`, and `packages/server/src/open-editor.ts`.

#### Browser editor overlay
`packages/overlay` is the substantial browser-side editor package injected/served around the proxied app. Its application lifecycle and integration boundary are `packages/overlay/src/app.ts`, `packages/overlay/src/hook.ts`, and `packages/overlay/src/ws.ts`. It supports two presentations: an inline overlay over one page and a canvas/shell containing multiple live device frames. Canvas frame management is centered in `packages/overlay/src/canvas/frames.ts`, `packages/overlay/src/canvas/space.ts`, and `packages/overlay/src/shell-app.ts`.

#### Selection, visual editing, and UI state
The overlay turns DOM selection and computed/authored styling into editor operations. The inspector covers layout/CSS/DOM-oriented controls, with its central model and panel in `packages/overlay/src/inspector/style-model.ts` and `packages/overlay/src/inspector/panel.ts`; reversible local editing is represented by `packages/overlay/src/change-set.ts` and `packages/overlay/src/history.ts`. Chat, prompt construction, streamed agent output, diffs, and user-visible change summaries are handled in `packages/overlay/src/chat/build-request.ts`, `packages/overlay/src/chat/transcript.ts`, and `packages/overlay/src/diff-view.ts`.

#### Agent execution, source attribution, and undo
`packages/core` translates a browser edit request—selected element/source location, prompt, inspector changes, and frames—into an agent run, captures file changes, and returns timeline/diff data. The runner and shared contracts are `packages/core/src/runner.ts`, `packages/core/src/agent.ts`, and `packages/core/src/models.ts`. Provider adapters isolate agent-specific subprocess/protocol behavior: `packages/core/src/providers/claude.ts`, `packages/core/src/providers/codex.ts`, and `packages/core/src/providers/opencode.ts`. Source-location extraction and project-path handling sit behind `packages/source/src/browser.ts`, `packages/source/src/server.ts`, and `packages/core/src/paths.ts`. Claude can use captured pre-edit content; Codex/OpenCode reconstruct baselines through Git, implemented by `packages/core/src/diff-capture.ts` and `packages/git/src/index.ts`.

#### Safety, protocol, and distribution surfaces
A shared protocol package defines browser/server/core message and model contracts: `packages/protocol/src/models.ts` and `packages/protocol/src/tokens.ts`. Agent safety policy is centralized in `packages/core/src/sandbox.ts`; actual strength varies by backend, with Codex receiving a real sandbox and Claude/OpenCode relying on command/edit checks. External dependencies are local target dev servers, Git for some diff/undo flows, installed/authenticated coding-agent CLIs and their model-provider credentials; Airship itself uses no hosted control plane or telemetry. The marketing site is a separate Vite/TanStack Router application, rooted at `apps/web/src/router.tsx` and `apps/web/src/routes/index.tsx`, rather than part of the editor runtime.

Main entry points: [`packages/server/src/index.ts`](https://github.com/0xnyn/airship/blob/main/packages/server/src/index.ts) (Proxy session server), [`packages/core/src/runner.ts`](https://github.com/0xnyn/airship/blob/main/packages/core/src/runner.ts) (Edit runner), [`packages/overlay/src/app.ts`](https://github.com/0xnyn/airship/blob/main/packages/overlay/src/app.ts) (Editor overlay), [`apps/cli/src/commands/serve.ts`](https://github.com/0xnyn/airship/blob/main/apps/cli/src/commands/serve.ts) (Serve orchestration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI launch"]
  node_cli_entry{{"Published CLI<br/>Node CLI<br/>[index.ts]"}}
  node_serve["Serve orchestration<br/>CLI command<br/>[serve.ts]"]
  node_cli_config["Settings resolution<br/>configuration boundary<br/>[config.ts]"]
  node_target_detect["Target discovery<br/>dev-server detection<br/>[detect.ts]"]
  node_doctor["Doctor<br/>diagnostic command<br/>[doctor.ts]"]
end

subgraph group_server["Local server"]
  node_local_server["Proxy session server<br/>local HTTP server<br/>[index.ts]"]
  node_proxy_safety["Proxy access policy<br/>HTTP safety layer<br/>[proxy.ts]"]
end

subgraph group_editor["Browser editor"]
  node_overlay["Editor overlay<br/>browser application<br/>[app.ts]"]
  node_canvas["Canvas device frames<br/>multi-frame editor<br/>[frames.ts]"]
  node_inspector["Inspector and local changes<br/>visual editing state<br/>[style-model.ts]"]
  node_chat_diff["Chat and diff UI<br/>agent interaction UI<br/>[build-request.ts]"]
  node_protocol["Shared protocol<br/>message contracts<br/>[models.ts]"]
end

subgraph group_agents["Edit execution"]
  node_edit_runner["Edit runner<br/>agent orchestration<br/>[runner.ts]"]
  node_source_attribution["Source attribution<br/>source-location service<br/>[server.ts]"]
  node_providers["Agent providers<br/>provider adapters<br/>[claude.ts]"]
  node_safety["Agent safety policy<br/>execution policy<br/>[sandbox.ts]"]
  node_diff_undo["Diff capture and undo<br/>change baseline<br/>[diff-capture.ts]"]
end

subgraph group_external["External systems"]
  node_target_app["Target dev server<br/>external HTTP server"]
  node_agent_clis["Coding-agent CLIs<br/>external executables"]
  node_git[("Git<br/>external VCS")]
  node_marketing_site["Marketing site<br/>Vite web app<br/>[router.tsx]"]
end

node_cli_entry -->|"launches"| node_serve
node_cli_entry -->|"diagnostics"| node_doctor
node_serve -->|"resolves settings"| node_cli_config
node_serve -->|"finds target"| node_target_detect
node_serve -->|"starts"| node_local_server
node_target_detect -->|"detects or starts"| node_target_app
node_local_server -->|"enforces"| node_proxy_safety
node_local_server -->|"proxies"| node_target_app
node_local_server -->|"serves and connects"| node_overlay
node_overlay -->|"hosts shell mode"| node_canvas
node_overlay -->|"drives selection and edits"| node_inspector
node_overlay -->|"hosts"| node_chat_diff
node_overlay -->|"uses"| node_protocol
node_local_server -->|"uses"| node_protocol
node_local_server -->|"submits edit jobs"| node_edit_runner
node_chat_diff -->|"sends edit requests"| node_edit_runner
node_edit_runner -->|"resolves selected source"| node_source_attribution
node_edit_runner -->|"applies policy"| node_safety
node_edit_runner -->|"dispatches"| node_providers
node_providers -->|"executes"| node_agent_clis
node_edit_runner -->|"captures changes"| node_diff_undo
node_diff_undo -.->|"reconstructs baselines"| node_git
node_edit_runner -->|"returns timeline and diffs"| node_local_server

click node_cli_entry "https://github.com/0xnyn/airship/blob/main/apps/cli/src/index.ts"
click node_serve "https://github.com/0xnyn/airship/blob/main/apps/cli/src/commands/serve.ts"
click node_cli_config "https://github.com/0xnyn/airship/blob/main/apps/cli/src/lib/config.ts"
click node_target_detect "https://github.com/0xnyn/airship/blob/main/apps/cli/src/lib/detect.ts"
click node_doctor "https://github.com/0xnyn/airship/blob/main/apps/cli/src/commands/doctor.ts"
click node_local_server "https://github.com/0xnyn/airship/blob/main/packages/server/src/index.ts"
click node_proxy_safety "https://github.com/0xnyn/airship/blob/main/packages/server/src/proxy.ts"
click node_overlay "https://github.com/0xnyn/airship/blob/main/packages/overlay/src/app.ts"
click node_canvas "https://github.com/0xnyn/airship/blob/main/packages/overlay/src/canvas/frames.ts"
click node_inspector "https://github.com/0xnyn/airship/blob/main/packages/overlay/src/inspector/style-model.ts"
click node_chat_diff "https://github.com/0xnyn/airship/blob/main/packages/overlay/src/chat/build-request.ts"
click node_protocol "https://github.com/0xnyn/airship/blob/main/packages/protocol/src/models.ts"
click node_edit_runner "https://github.com/0xnyn/airship/blob/main/packages/core/src/runner.ts"
click node_source_attribution "https://github.com/0xnyn/airship/blob/main/packages/source/src/server.ts"
click node_providers "https://github.com/0xnyn/airship/blob/main/packages/core/src/providers/claude.ts"
click node_safety "https://github.com/0xnyn/airship/blob/main/packages/core/src/sandbox.ts"
click node_diff_undo "https://github.com/0xnyn/airship/blob/main/packages/core/src/diff-capture.ts"
click node_marketing_site "https://github.com/0xnyn/airship/blob/main/apps/web/src/router.tsx"

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_entry,node_serve,node_cli_config,node_target_detect,node_doctor toneBlue
class node_local_server,node_proxy_safety toneAmber
class node_overlay,node_canvas,node_inspector,node_chat_diff,node_protocol toneMint
class node_edit_runner,node_source_attribution,node_providers,node_safety,node_diff_undo toneRose
class node_target_app,node_agent_clis,node_git,node_marketing_site toneIndigo
```

## Components

### CLI launch

- [Published CLI](https://github.com/0xnyn/airship/blob/main/apps/cli/src/index.ts): Node CLI · Primary local entry point. · `apps/cli/src/index.ts`
- [Serve orchestration](https://github.com/0xnyn/airship/blob/main/apps/cli/src/commands/serve.ts): CLI command · Resolves launch settings and starts the local editor stack. · `apps/cli/src/commands/serve.ts`
- [Settings resolution](https://github.com/0xnyn/airship/blob/main/apps/cli/src/lib/config.ts): configuration boundary · Combines flags, environment, project settings, and defaults. · `apps/cli/src/lib/config.ts`
- [Target discovery](https://github.com/0xnyn/airship/blob/main/apps/cli/src/lib/detect.ts): dev-server detection · Finds the target port and can start its dev command. · `apps/cli/src/lib/detect.ts`
- [Doctor](https://github.com/0xnyn/airship/blob/main/apps/cli/src/commands/doctor.ts): diagnostic command · Separate prerequisite diagnostic path. · `apps/cli/src/commands/doctor.ts`

### Local server

- [Proxy session server](https://github.com/0xnyn/airship/blob/main/packages/server/src/index.ts): local HTTP server · Loopback server, proxy boundary, jobs, history, and editor launch. · `packages/server/src/index.ts`
- [Proxy access policy](https://github.com/0xnyn/airship/blob/main/packages/server/src/proxy.ts): HTTP safety layer · Validates hosts and adapts CSP and frame headers. · `packages/server/src/proxy.ts`

### Browser editor

- [Editor overlay](https://github.com/0xnyn/airship/blob/main/packages/overlay/src/app.ts): browser application · Injected editor lifecycle and server integration. · `packages/overlay/src/app.ts`
- [Canvas device frames](https://github.com/0xnyn/airship/blob/main/packages/overlay/src/canvas/frames.ts): multi-frame editor · Shell mode manages multiple live device frames. · `packages/overlay/src/canvas/frames.ts`
- [Inspector and local changes](https://github.com/0xnyn/airship/blob/main/packages/overlay/src/inspector/style-model.ts): visual editing state · Models style controls and reversible browser-side edits. · `packages/overlay/src/inspector/style-model.ts`
- [Chat and diff UI](https://github.com/0xnyn/airship/blob/main/packages/overlay/src/chat/build-request.ts): agent interaction UI · Builds requests and presents streamed output and changes. · `packages/overlay/src/chat/build-request.ts`
- [Shared protocol](https://github.com/0xnyn/airship/blob/main/packages/protocol/src/models.ts): message contracts · Browser, server, and core models and tokens. · `packages/protocol/src/models.ts`

### Edit execution

- [Edit runner](https://github.com/0xnyn/airship/blob/main/packages/core/src/runner.ts): agent orchestration · Turns selection, prompts, styles, and frames into edit runs and timelines. · `packages/core/src/runner.ts`
- [Source attribution](https://github.com/0xnyn/airship/blob/main/packages/source/src/server.ts): source-location service · Maps browser selections to project source paths. · `packages/source/src/server.ts`
- [Agent providers](https://github.com/0xnyn/airship/blob/main/packages/core/src/providers/claude.ts): provider adapters · Claude, Codex, and OpenCode subprocess/protocol adapters. · `packages/core/src/providers/claude.ts`
- [Agent safety policy](https://github.com/0xnyn/airship/blob/main/packages/core/src/sandbox.ts): execution policy · Central policy; backend enforcement strength varies. · `packages/core/src/sandbox.ts`
- [Diff capture and undo](https://github.com/0xnyn/airship/blob/main/packages/core/src/diff-capture.ts): change baseline · Uses captured content or Git baselines for diffs and undo. · `packages/core/src/diff-capture.ts`

### External systems

- **Target dev server**: external HTTP server · Existing application being edited.
- **Coding-agent CLIs**: external executables · Installed and authenticated Claude, Codex, or OpenCode.
- **Git**: external VCS · Baseline source for Codex/OpenCode flows.
- [Marketing site](https://github.com/0xnyn/airship/blob/main/apps/web/src/router.tsx): Vite web app · Separate from the editor runtime. · `apps/web/src/router.tsx`

## Connections

- Published CLI → Serve orchestration: launches
- Published CLI → Doctor: diagnostics
- Serve orchestration → Settings resolution: resolves settings
- Serve orchestration → Target discovery: finds target
- Serve orchestration → Proxy session server: starts
- Target discovery → Target dev server: detects or starts
- Proxy session server → Proxy access policy: enforces
- Proxy session server → Target dev server: proxies
- Proxy session server → Editor overlay: serves and connects
- Editor overlay → Canvas device frames: hosts shell mode
- Editor overlay → Inspector and local changes: drives selection and edits
- Editor overlay → Chat and diff UI: hosts
- Editor overlay → Shared protocol: uses
- Proxy session server → Shared protocol: uses
- Proxy session server → Edit runner: submits edit jobs
- Chat and diff UI → Edit runner: sends edit requests
- Edit runner → Source attribution: resolves selected source
- Edit runner → Agent safety policy: applies policy
- Edit runner → Agent providers: dispatches
- Agent providers → Coding-agent CLIs: executes
- Edit runner → Diff capture and undo: captures changes
- Diff capture and undo → Git: reconstructs baselines
- Edit runner → Proxy session server: returns timeline and diffs
