# evanw/esbuild architecture

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

- Interactive diagram: https://gitdiagram.com/evanw/esbuild
- Repository: https://github.com/evanw/esbuild

## Overview

esbuild is a fast JavaScript and CSS bundler with CLI, Go, and JavaScript APIs. A typical build starts with a user invoking an API, resolves entry points and dependencies, parses and transforms source, links modules, then prints generated files and optional source maps. The README also documents plugins, watch mode, a local server, tree shaking, and minification. The graph reflects documented capabilities and indexed module references; unsampled implementation details are represented cautiously rather than treated as inspected.

Main entry points: [`internal/bundler/bundler.go`](https://github.com/evanw/esbuild/blob/main/internal/bundler/bundler.go) (Build and transform), [`pkg/api/api_impl.go`](https://github.com/evanw/esbuild/blob/main/pkg/api/api_impl.go) (Go API), [`internal/linker/linker.go`](https://github.com/evanw/esbuild/blob/main/internal/linker/linker.go) (Linker), [`compat-table/src/index.ts`](https://github.com/evanw/esbuild/blob/main/compat-table/src/index.ts) (Compatibility table generator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["Interfaces and lifecycle"]
  node_cli["CLI<br/>[cli_impl.go]"]
  node_goapi["Go API<br/>[api_impl.go]"]
  node_jsapi["JavaScript API<br/>[node.ts]"]
  node_service["Service protocol<br/>[service.go]"]
  node_watchserve["Watch and serve"]
  node_plugins["Plugin hooks<br/>[api_impl.go]"]
end

subgraph group_build["Build orchestration"]
  node_bundler["Build and transform<br/>[bundler.go]"]
  node_resolver["Module resolver<br/>[resolver.go]"]
  node_graph["Module graph<br/>[graph.go]"]
  node_linker["Linker<br/>[linker.go]"]
  node_outputs["Generated files"]
end

subgraph group_language["Language processing"]
  node_jslexer["JS lexer<br/>[js_lexer.go]"]
  node_jsparser["JS parser and lowering"]
  node_jsprinter["JS printer<br/>[js_printer.go]"]
  node_cssparser["CSS parser<br/>[css_parser.go]"]
  node_cssprinter["CSS printer<br/>[css_printer.go]"]
  node_sourcemaps["Source maps<br/>[sourcemap.go]"]
end

subgraph group_support["Compatibility data"]
  node_compat["Runtime compatibility"]
  node_compatgen["Compatibility table generator<br/>[index.ts]"]
  node_jstable["JavaScript support data<br/>[js_table.ts]"]
  node_csstable["CSS support data<br/>[css_table.ts]"]
  node_mdndata["MDN data source<br/>[mdn.ts]"]
  node_caniuse["Can I Use data source<br/>[caniuse.ts]"]
end

node_user(("Developer"))

node_user -->|"invokes"| node_cli
node_user -.->|"uses"| node_goapi
node_user -.->|"uses"| node_jsapi
node_cli -->|"calls"| node_goapi
node_jsapi -.->|"exchanges requests"| node_service
node_goapi -.->|"builds or transforms"| node_bundler
node_goapi -.->|"links build output"| node_linker
node_goapi -.->|"supports lifecycle"| node_watchserve
node_goapi -->|"registers hooks"| node_plugins
node_bundler -->|"resolves imports"| node_resolver
node_bundler -->|"scans JavaScript"| node_jslexer
node_bundler -->|"parses JavaScript"| node_jsparser
node_bundler -->|"parses CSS"| node_cssparser
node_bundler -->|"builds module graph"| node_graph
node_linker -->|"reads module graph"| node_graph
node_linker -->|"prints JavaScript"| node_jsprinter
node_linker -->|"prints CSS"| node_cssprinter
node_linker -->|"generates files"| node_outputs
node_bundler -.->|"emits build results"| node_outputs
node_jsprinter -->|"adds mappings"| node_sourcemaps
node_cssprinter -->|"adds mappings"| node_sourcemaps
node_jsparser -->|"checks targets"| node_compat
node_cssparser -->|"checks support"| node_compat
node_compatgen -->|"generates table"| node_jstable
node_compatgen -->|"generates table"| node_csstable
node_compatgen -->|"uses data"| node_mdndata
node_compatgen -->|"uses data"| node_caniuse

click node_cli "https://github.com/evanw/esbuild/blob/main/pkg/cli/cli_impl.go"
click node_goapi "https://github.com/evanw/esbuild/blob/main/pkg/api/api_impl.go"
click node_jsapi "https://github.com/evanw/esbuild/blob/main/lib/npm/node.ts"
click node_service "https://github.com/evanw/esbuild/blob/main/cmd/esbuild/service.go"
click node_watchserve "https://github.com/evanw/esbuild/tree/main/pkg/api"
click node_plugins "https://github.com/evanw/esbuild/blob/main/pkg/api/api_impl.go"
click node_bundler "https://github.com/evanw/esbuild/blob/main/internal/bundler/bundler.go"
click node_resolver "https://github.com/evanw/esbuild/blob/main/internal/resolver/resolver.go"
click node_graph "https://github.com/evanw/esbuild/blob/main/internal/graph/graph.go"
click node_linker "https://github.com/evanw/esbuild/blob/main/internal/linker/linker.go"
click node_outputs "https://github.com/evanw/esbuild/tree/main/internal/bundler"
click node_jslexer "https://github.com/evanw/esbuild/blob/main/internal/js_lexer/js_lexer.go"
click node_jsparser "https://github.com/evanw/esbuild/tree/main/internal/js_parser"
click node_jsprinter "https://github.com/evanw/esbuild/blob/main/internal/js_printer/js_printer.go"
click node_cssparser "https://github.com/evanw/esbuild/blob/main/internal/css_parser/css_parser.go"
click node_cssprinter "https://github.com/evanw/esbuild/blob/main/internal/css_printer/css_printer.go"
click node_sourcemaps "https://github.com/evanw/esbuild/blob/main/internal/sourcemap/sourcemap.go"
click node_compat "https://github.com/evanw/esbuild/tree/main/internal/compat"
click node_compatgen "https://github.com/evanw/esbuild/blob/main/compat-table/src/index.ts"
click node_jstable "https://github.com/evanw/esbuild/blob/main/compat-table/src/js_table.ts"
click node_csstable "https://github.com/evanw/esbuild/blob/main/compat-table/src/css_table.ts"
click node_mdndata "https://github.com/evanw/esbuild/blob/main/compat-table/src/mdn.ts"
click node_caniuse "https://github.com/evanw/esbuild/blob/main/compat-table/src/caniuse.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_goapi,node_jsapi,node_service,node_watchserve,node_plugins toneBlue
class node_bundler,node_resolver,node_graph,node_linker,node_outputs toneAmber
class node_jslexer,node_jsparser,node_jsprinter,node_cssparser,node_cssprinter,node_sourcemaps toneMint
class node_compat,node_compatgen,node_jstable,node_csstable,node_mdndata,node_caniuse toneRose
class node_user toneIndigo
```

## Components

### Interfaces and lifecycle

- [CLI](https://github.com/evanw/esbuild/blob/main/pkg/cli/cli_impl.go): `pkg/cli/cli_impl.go`
- [Go API](https://github.com/evanw/esbuild/blob/main/pkg/api/api_impl.go): `pkg/api/api_impl.go`
- [JavaScript API](https://github.com/evanw/esbuild/blob/main/lib/npm/node.ts): `lib/npm/node.ts`
- [Service protocol](https://github.com/evanw/esbuild/blob/main/cmd/esbuild/service.go): `cmd/esbuild/service.go`
- [Watch and serve](https://github.com/evanw/esbuild/tree/main/pkg/api): `pkg/api`
- [Plugin hooks](https://github.com/evanw/esbuild/blob/main/pkg/api/api_impl.go): `pkg/api/api_impl.go`

### Build orchestration

- [Build and transform](https://github.com/evanw/esbuild/blob/main/internal/bundler/bundler.go): `internal/bundler/bundler.go`
- [Module resolver](https://github.com/evanw/esbuild/blob/main/internal/resolver/resolver.go): `internal/resolver/resolver.go`
- [Module graph](https://github.com/evanw/esbuild/blob/main/internal/graph/graph.go): `internal/graph/graph.go`
- [Linker](https://github.com/evanw/esbuild/blob/main/internal/linker/linker.go): `internal/linker/linker.go`
- [Generated files](https://github.com/evanw/esbuild/tree/main/internal/bundler): `internal/bundler`

### Language processing

- [JS lexer](https://github.com/evanw/esbuild/blob/main/internal/js_lexer/js_lexer.go): `internal/js_lexer/js_lexer.go`
- [JS parser and lowering](https://github.com/evanw/esbuild/tree/main/internal/js_parser): `internal/js_parser`
- [JS printer](https://github.com/evanw/esbuild/blob/main/internal/js_printer/js_printer.go): `internal/js_printer/js_printer.go`
- [CSS parser](https://github.com/evanw/esbuild/blob/main/internal/css_parser/css_parser.go): `internal/css_parser/css_parser.go`
- [CSS printer](https://github.com/evanw/esbuild/blob/main/internal/css_printer/css_printer.go): `internal/css_printer/css_printer.go`
- [Source maps](https://github.com/evanw/esbuild/blob/main/internal/sourcemap/sourcemap.go): `internal/sourcemap/sourcemap.go`

### Compatibility data

- [Runtime compatibility](https://github.com/evanw/esbuild/tree/main/internal/compat): `internal/compat`
- [Compatibility table generator](https://github.com/evanw/esbuild/blob/main/compat-table/src/index.ts): `compat-table/src/index.ts`
- [JavaScript support data](https://github.com/evanw/esbuild/blob/main/compat-table/src/js_table.ts): `compat-table/src/js_table.ts`
- [CSS support data](https://github.com/evanw/esbuild/blob/main/compat-table/src/css_table.ts): `compat-table/src/css_table.ts`
- [MDN data source](https://github.com/evanw/esbuild/blob/main/compat-table/src/mdn.ts): `compat-table/src/mdn.ts`
- [Can I Use data source](https://github.com/evanw/esbuild/blob/main/compat-table/src/caniuse.ts): `compat-table/src/caniuse.ts`

### Other components

- **Developer**

## Connections

- Developer → CLI: invokes
- Developer → Go API: uses
- Developer → JavaScript API: uses
- CLI → Go API: calls (evidence: `pkg/cli/cli_impl.go`)
- JavaScript API → Service protocol: exchanges requests
- Go API → Build and transform: builds or transforms
- Go API → Linker: links build output
- Go API → Watch and serve: supports lifecycle
- Go API → Plugin hooks: registers hooks (evidence: `pkg/api/api_impl.go`)
- Build and transform → Module resolver: resolves imports (evidence: `internal/bundler/bundler.go`)
- Build and transform → JS lexer: scans JavaScript (evidence: `internal/bundler/bundler.go`)
- Build and transform → JS parser and lowering: parses JavaScript (evidence: `internal/bundler/bundler.go`)
- Build and transform → CSS parser: parses CSS (evidence: `internal/bundler/bundler.go`)
- Build and transform → Module graph: builds module graph (evidence: `internal/bundler/bundler.go`)
- Linker → Module graph: reads module graph (evidence: `internal/linker/linker.go`)
- Linker → JS printer: prints JavaScript (evidence: `internal/linker/linker.go`)
- Linker → CSS printer: prints CSS (evidence: `internal/linker/linker.go`)
- Linker → Generated files: generates files (evidence: `internal/linker/linker.go`)
- Build and transform → Generated files: emits build results
- JS printer → Source maps: adds mappings (evidence: `internal/js_printer/js_printer.go`)
- CSS printer → Source maps: adds mappings (evidence: `internal/css_printer/css_printer.go`)
- JS parser and lowering → Runtime compatibility: checks targets (evidence: `internal/js_parser/js_parser_lower.go`)
- CSS parser → Runtime compatibility: checks support (evidence: `internal/css_parser/css_parser.go`)
- Compatibility table generator → JavaScript support data: generates table (evidence: `compat-table/src/index.ts`)
- Compatibility table generator → CSS support data: generates table (evidence: `compat-table/src/index.ts`)
- Compatibility table generator → MDN data source: uses data (evidence: `compat-table/src/index.ts`)
- Compatibility table generator → Can I Use data source: uses data (evidence: `compat-table/src/index.ts`)
