# air-verse/air architecture

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

- Interactive diagram: https://gitdiagram.com/air-verse/air
- Repository: https://github.com/air-verse/air

## Overview

#### Purpose and Runtime

Air is a Go CLI for development-time live reload of Go applications. It watches a project tree, rebuilds on relevant changes, terminates/restarts the configured executable, and can optionally proxy HTTP traffic to inject browser reload support. It is not a production deployment system.

The primary binary entry point is `main.go`; release version metadata is in `version.go`. The main runtime is Go 1.25+ and is designed to run on Linux, macOS, and Windows.

#### CLI Bootstrap and Configuration

CLI parsing, command modes (`air`, `air init`), configuration selection, and argument forwarding are centered in:
- `main.go`
- `runner/flag.go`
- `runner/config.go`

Configuration is normally loaded from `.air.toml` in the target working directory or an explicit `-c` path. CLI flags can override config fields, including nested build settings. Config defines watch filters, build commands, executable entrypoint/arguments, environment files, platform-specific build settings, logging, and proxy behavior.

#### Runner Orchestration Engine

`runner/engine.go` is the central control plane: it initializes configured services, starts watching, coordinates initial and subsequent builds, and owns rebuild/restart lifecycle decisions.
- `runner/engine.go`
- `runner/common.go`
- `runner/exiter.go`

The engine forms the principal boundary between filesystem events and process lifecycle: events are filtered/debounced into rebuild requests; builds either leave the existing application intact on failure or replace it after successful output.

#### Filesystem Watch Pipeline

Watch registration and event handling are encapsulated by:
- `runner/watcher.go`
- `runner/util.go`
- `runner/util_linux.go`

The watcher recursively observes configured directories and handles new directories appearing after startup. It applies inclusion/exclusion rules from configuration (directories, extensions, named files), suppresses irrelevant/generated paths, and sends meaningful changes toward the engine rather than directly invoking builds. OS-specific utility files support platform differences, with corresponding Unix and Windows implementations in `runner/util_unix.go` and `runner/util_windows.go`.

#### Build and Managed Application Process

Build execution is configured rather than hardcoded: pre-build commands, the main build command, post-build commands, environment-file loading, and OS-specific overrides establish the artifact. The configured `entrypoint` then resolves to an executable plus default/configured/CLI-supplied arguments.

Process and command concerns are concentrated in:
- `runner/engine.go`
- `runner/cmdarg_test.go` (behavioral contract)
- `runner/util_windows.go`

Air manages child-process termination and restart, including platform-specific process handling. This is a strong isolation boundary: the watched project’s compiler and executable are external subprocesses, while Air only supervises their invocation and I/O.

#### Optional Development Proxy and Browser Reload

An optional proxy sits between a browser and the watched application:
- `runner/proxy.go`
- `runner/proxy_stream.go`
- `runner/proxy.js`

When enabled, Air listens on a proxy port, forwards traffic to the application port, and can alter suitable HTML responses to support reload behavior after static-file changes. Stream handling preserves proxying for response types that should not be buffered or transformed. Browser-side behavior is carried by the embedded JavaScript assets `runner/proxy.js` and `runner/worker.js`.

#### Packaging, Container Use, and Delivery

The project ships as a Go binary and supports containerized development:
- `Dockerfile`
- `.goreleaser.yml`
- `.github/workflows/release.yml`

`Dockerfile` provides a runnable image context; mounted source trees are expected for live reload. GoReleaser and GitHub Actions produce release artifacts. Smoke tests exercise rebuild behavior through a separate sample Go application under `smoke_test/check_rebuild/`, validating the end-to-end watch → build → restart path.

Main entry points: [`runner/engine.go`](https://github.com/air-verse/air/blob/master/runner/engine.go) (Runner engine), [`main.go`](https://github.com/air-verse/air/blob/master/main.go) (Air CLI), [`runner/proxy.go`](https://github.com/air-verse/air/blob/master/runner/proxy.go) (Development proxy), [`runner/watcher.go`](https://github.com/air-verse/air/blob/master/runner/watcher.go) (Filesystem watcher)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI &amp; Config"]
  node_main["Air CLI<br/>Go entrypoint<br/>[main.go]"]
  node_version["Version metadata<br/>Go metadata<br/>[version.go]"]
  node_flags["Flag parsing<br/>CLI parser<br/>[flag.go]"]
  node_config["Config loading<br/>configuration<br/>[config.go]"]
end

subgraph group_runtime["Reload Runtime"]
  node_engine{{"Runner engine<br/>orchestrator<br/>[engine.go]"}}
  node_lifecycle["Lifecycle control<br/>process lifecycle<br/>[exiter.go]"]
  node_watcher["Filesystem watcher<br/>watch pipeline<br/>[watcher.go]"]
  node_platform_utils["Platform utilities<br/>OS adapter<br/>[util.go]"]
  node_build["Configured build<br/>subprocess pipeline<br/>[engine.go]"]
  node_app_process["Managed application<br/>child process"]
end

subgraph group_proxy["Optional Proxy"]
  node_proxy_server["Development proxy<br/>HTTP proxy<br/>[proxy.go]"]
  node_proxy_stream["Streaming proxy path<br/>HTTP stream handler<br/>[proxy_stream.go]"]
  node_browser_assets["Browser reload assets<br/>embedded JavaScript<br/>[proxy.js]"]
end

subgraph group_delivery["Delivery"]
  node_container["Container image<br/>Docker packaging"]
  node_release["Release pipeline<br/>artifact delivery<br/>[release.yml]"]
  node_goreleaser["GoReleaser config<br/>release manifest<br/>[.goreleaser.yml]"]
end

node_project_tree["Watched project tree<br/>external source tree"]

node_main -->|"reports version"| node_version
node_main -->|"parses CLI"| node_flags
node_flags -->|"selects and overrides"| node_config
node_config -->|"configures"| node_engine
node_main -->|"starts"| node_engine
node_engine -->|"registers watches"| node_watcher
node_project_tree -->|"file changes"| node_watcher
node_watcher -.->|"uses OS support"| node_platform_utils
node_watcher -->|"filtered rebuild requests"| node_engine
node_engine -->|"runs on relevant change"| node_build
node_build -->|"successful artifact replaces"| node_app_process
node_engine -->|"terminates and restarts"| node_app_process
node_engine -->|"uses shutdown control"| node_lifecycle
node_engine -->|"starts when enabled"| node_proxy_server
node_proxy_server -->|"forwards requests"| node_app_process
node_proxy_server -->|"routes streaming responses"| node_proxy_stream
node_proxy_server -->|"injects reload client"| node_browser_assets
node_container -->|"packages"| node_main
node_release -->|"runs"| node_goreleaser
node_goreleaser -->|"builds releases"| node_main

click node_main "https://github.com/air-verse/air/blob/master/main.go"
click node_version "https://github.com/air-verse/air/blob/master/version.go"
click node_flags "https://github.com/air-verse/air/blob/master/runner/flag.go"
click node_config "https://github.com/air-verse/air/blob/master/runner/config.go"
click node_engine "https://github.com/air-verse/air/blob/master/runner/engine.go"
click node_lifecycle "https://github.com/air-verse/air/blob/master/runner/exiter.go"
click node_watcher "https://github.com/air-verse/air/blob/master/runner/watcher.go"
click node_platform_utils "https://github.com/air-verse/air/blob/master/runner/util.go"
click node_build "https://github.com/air-verse/air/blob/master/runner/engine.go"
click node_proxy_server "https://github.com/air-verse/air/blob/master/runner/proxy.go"
click node_proxy_stream "https://github.com/air-verse/air/blob/master/runner/proxy_stream.go"
click node_browser_assets "https://github.com/air-verse/air/blob/master/runner/proxy.js"
click node_container "https://github.com/air-verse/air/tree/master/Dockerfile"
click node_release "https://github.com/air-verse/air/blob/master/.github/workflows/release.yml"
click node_goreleaser "https://github.com/air-verse/air/blob/master/.goreleaser.yml"

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_main,node_version,node_flags,node_config toneBlue
class node_engine,node_lifecycle,node_watcher,node_platform_utils,node_build,node_app_process toneAmber
class node_proxy_server,node_proxy_stream,node_browser_assets toneMint
class node_container,node_release,node_goreleaser toneRose
class node_project_tree toneNeutral
```

## Components

### CLI & Config

- [Air CLI](https://github.com/air-verse/air/blob/master/main.go): Go entrypoint · Selects command mode and starts the runner. · `main.go`
- [Version metadata](https://github.com/air-verse/air/blob/master/version.go): Go metadata · `version.go`
- [Flag parsing](https://github.com/air-verse/air/blob/master/runner/flag.go): CLI parser · Parses Air commands and forwards application arguments. · `runner/flag.go`
- [Config loading](https://github.com/air-verse/air/blob/master/runner/config.go): configuration · Loads .air.toml or an explicit config path and applies overrides. · `runner/config.go`

### Reload Runtime

- [Runner engine](https://github.com/air-verse/air/blob/master/runner/engine.go): orchestrator · Coordinates watch events, builds, and application replacement. · `runner/engine.go`
- [Lifecycle control](https://github.com/air-verse/air/blob/master/runner/exiter.go): process lifecycle · Owns shutdown and common runner behavior. · `runner/exiter.go`
- [Filesystem watcher](https://github.com/air-verse/air/blob/master/runner/watcher.go): watch pipeline · Recursively observes configured project directories and filters changes. · `runner/watcher.go`
- [Platform utilities](https://github.com/air-verse/air/blob/master/runner/util.go): OS adapter · Supports watch and process differences across operating systems. · `runner/util.go`
- [Configured build](https://github.com/air-verse/air/blob/master/runner/engine.go): subprocess pipeline · Runs pre-build, build, and post-build commands with configured environment. · `runner/engine.go`
- **Managed application**: child process · Configured executable restarted only after successful builds.

### Optional Proxy

- [Development proxy](https://github.com/air-verse/air/blob/master/runner/proxy.go): HTTP proxy · Forwards browser traffic and injects reload support into suitable HTML. · `runner/proxy.go`
- [Streaming proxy path](https://github.com/air-verse/air/blob/master/runner/proxy_stream.go): HTTP stream handler · Preserves response streaming when content should not be transformed. · `runner/proxy_stream.go`
- [Browser reload assets](https://github.com/air-verse/air/blob/master/runner/proxy.js): embedded JavaScript · Client and worker code used for browser reload behavior. · `runner/proxy.js`

### Delivery

- [Container image](https://github.com/air-verse/air/tree/master/Dockerfile): Docker packaging · Provides a runnable Air image for mounted development source trees. · `Dockerfile`
- [Release pipeline](https://github.com/air-verse/air/blob/master/.github/workflows/release.yml): artifact delivery · GitHub Actions and GoReleaser produce distributable binaries. · `.github/workflows/release.yml`
- [GoReleaser config](https://github.com/air-verse/air/blob/master/.goreleaser.yml): release manifest · `.goreleaser.yml`

### Other components

- **Watched project tree**: external source tree · Application source and static files mounted or selected as the watch target.

## Connections

- Air CLI → Version metadata: reports version
- Air CLI → Flag parsing: parses CLI
- Flag parsing → Config loading: selects and overrides
- Config loading → Runner engine: configures
- Air CLI → Runner engine: starts
- Runner engine → Filesystem watcher: registers watches
- Watched project tree → Filesystem watcher: file changes
- Filesystem watcher → Platform utilities: uses OS support
- Filesystem watcher → Runner engine: filtered rebuild requests
- Runner engine → Configured build: runs on relevant change
- Configured build → Managed application: successful artifact replaces
- Runner engine → Managed application: terminates and restarts
- Runner engine → Lifecycle control: uses shutdown control
- Runner engine → Development proxy: starts when enabled
- Development proxy → Managed application: forwards requests
- Development proxy → Streaming proxy path: routes streaming responses
- Development proxy → Browser reload assets: injects reload client
- Container image → Air CLI: packages
- Release pipeline → GoReleaser config: runs
- GoReleaser config → Air CLI: builds releases
