# vercel/pkg architecture

> Architecture diagram of the GitHub repository vercel/pkg, 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/vercel/pkg
- Repository: https://github.com/vercel/pkg

## Overview

pkg is a CLI that turns a Node.js project into a standalone executable for selected Node versions, platforms, and architectures. Its principal workflow resolves the requested entrypoint and configuration, discovers dependencies and assets, prepares package records, and produces an executable using a target Node binary. The README also documents bytecode generation, compression, and cross-platform builds. Edges reflect the excerpts, source-index references, or README; the prelude’s runtime role is documented only indirectly, so its connection is unverified.

Main entry points: [`lib/index.ts`](https://github.com/vercel/pkg/blob/main/lib/index.ts) (Packaging Orchestrator), [`lib/walker.ts`](https://github.com/vercel/pkg/blob/main/lib/walker.ts) (Dependency Walker), [`lib/producer.ts`](https://github.com/vercel/pkg/blob/main/lib/producer.ts) (Executable Producer), [`lib/bin.ts`](https://github.com/vercel/pkg/blob/main/lib/bin.ts) (CLI Launcher)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["CLI and Inputs"]
  node_cli["CLI Launcher<br/>[bin.ts]"]
  node_orchestrator["Packaging Orchestrator<br/>[index.ts]"]
  node_help["CLI Help<br/>[help.ts]"]
  node_common["Path and Snapshot Utilities<br/>[common.ts]"]
end

subgraph group_discovery["Dependency Discovery"]
  node_walker["Dependency Walker<br/>[walker.ts]"]
  node_detector["Source Detector<br/>[detector.ts]"]
  node_resolver["File Resolver<br/>[follow.ts]"]
  node_refiner["Record Refiner<br/>[refiner.ts]"]
end

subgraph group_packaging["Executable Packaging"]
  node_packer["Content Packer<br/>[packer.ts]"]
  node_producer["Executable Producer<br/>[producer.ts]"]
  node_fabricator["Bytecode Fabricator<br/>[fabricator.ts]"]
  node_compression["Compression Options<br/>[compress_type.ts]"]
end

subgraph group_runtime["Packaged Runtime"]
  node_prelude["Snapshot Runtime Prelude<br/>[bootstrap.js]"]
  node_diagnostic["Runtime Diagnostics<br/>[diagnostic.js]"]
end

node_user(("CLI User"))
node_target["Target Node Binary"]

node_user -->|"invokes"| node_cli
node_cli -->|"starts"| node_orchestrator
node_orchestrator -->|"loads help"| node_help
node_orchestrator -->|"discovers files"| node_walker
node_walker -->|"analyzes source"| node_detector
node_walker -->|"resolves paths"| node_resolver
node_orchestrator -->|"refines records"| node_refiner
node_orchestrator -->|"packs records"| node_packer
node_orchestrator -->|"produces executable"| node_producer
node_producer -->|"generates bytecode"| node_fabricator
node_orchestrator -->|"fetches target"| node_target
node_orchestrator -->|"reads option"| node_compression
node_producer -.->|"embeds runtime"| node_prelude
node_prelude -.->|"uses diagnostics"| node_diagnostic

click node_cli "https://github.com/vercel/pkg/blob/main/lib/bin.ts"
click node_orchestrator "https://github.com/vercel/pkg/blob/main/lib/index.ts"
click node_help "https://github.com/vercel/pkg/blob/main/lib/help.ts"
click node_common "https://github.com/vercel/pkg/blob/main/lib/common.ts"
click node_walker "https://github.com/vercel/pkg/blob/main/lib/walker.ts"
click node_detector "https://github.com/vercel/pkg/blob/main/lib/detector.ts"
click node_resolver "https://github.com/vercel/pkg/blob/main/lib/follow.ts"
click node_refiner "https://github.com/vercel/pkg/blob/main/lib/refiner.ts"
click node_packer "https://github.com/vercel/pkg/blob/main/lib/packer.ts"
click node_producer "https://github.com/vercel/pkg/blob/main/lib/producer.ts"
click node_fabricator "https://github.com/vercel/pkg/blob/main/lib/fabricator.ts"
click node_compression "https://github.com/vercel/pkg/blob/main/lib/compress_type.ts"
click node_prelude "https://github.com/vercel/pkg/blob/main/prelude/bootstrap.js"
click node_diagnostic "https://github.com/vercel/pkg/blob/main/prelude/diagnostic.js"

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_orchestrator,node_help,node_common,node_user toneBlue
class node_walker,node_detector,node_resolver,node_refiner toneAmber
class node_packer,node_producer,node_fabricator,node_compression toneMint
class node_prelude,node_diagnostic toneRose
class node_target toneIndigo
```

## Components

### CLI and Inputs

- [CLI Launcher](https://github.com/vercel/pkg/blob/main/lib/bin.ts): `lib/bin.ts`
- [Packaging Orchestrator](https://github.com/vercel/pkg/blob/main/lib/index.ts): `lib/index.ts`
- [CLI Help](https://github.com/vercel/pkg/blob/main/lib/help.ts): `lib/help.ts`
- [Path and Snapshot Utilities](https://github.com/vercel/pkg/blob/main/lib/common.ts): `lib/common.ts`

### Dependency Discovery

- [Dependency Walker](https://github.com/vercel/pkg/blob/main/lib/walker.ts): `lib/walker.ts`
- [Source Detector](https://github.com/vercel/pkg/blob/main/lib/detector.ts): `lib/detector.ts`
- [File Resolver](https://github.com/vercel/pkg/blob/main/lib/follow.ts): `lib/follow.ts`
- [Record Refiner](https://github.com/vercel/pkg/blob/main/lib/refiner.ts): `lib/refiner.ts`

### Executable Packaging

- [Content Packer](https://github.com/vercel/pkg/blob/main/lib/packer.ts): `lib/packer.ts`
- [Executable Producer](https://github.com/vercel/pkg/blob/main/lib/producer.ts): `lib/producer.ts`
- [Bytecode Fabricator](https://github.com/vercel/pkg/blob/main/lib/fabricator.ts): `lib/fabricator.ts`
- [Compression Options](https://github.com/vercel/pkg/blob/main/lib/compress_type.ts): `lib/compress_type.ts`

### Packaged Runtime

- [Snapshot Runtime Prelude](https://github.com/vercel/pkg/blob/main/prelude/bootstrap.js): `prelude/bootstrap.js`
- [Runtime Diagnostics](https://github.com/vercel/pkg/blob/main/prelude/diagnostic.js): `prelude/diagnostic.js`

### Other components

- **CLI User**
- **Target Node Binary**

## Connections

- CLI User → CLI Launcher: invokes
- CLI Launcher → Packaging Orchestrator: starts (evidence: `lib/bin.ts`)
- Packaging Orchestrator → CLI Help: loads help (evidence: `lib/index.ts`)
- Packaging Orchestrator → Dependency Walker: discovers files (evidence: `lib/index.ts`)
- Dependency Walker → Source Detector: analyzes source (evidence: `lib/walker.ts`)
- Dependency Walker → File Resolver: resolves paths (evidence: `lib/walker.ts`)
- Packaging Orchestrator → Record Refiner: refines records (evidence: `lib/index.ts`)
- Packaging Orchestrator → Content Packer: packs records (evidence: `lib/index.ts`)
- Packaging Orchestrator → Executable Producer: produces executable (evidence: `lib/index.ts`)
- Executable Producer → Bytecode Fabricator: generates bytecode (evidence: `lib/producer.ts`)
- Packaging Orchestrator → Target Node Binary: fetches target (evidence: `lib/index.ts`)
- Packaging Orchestrator → Compression Options: reads option (evidence: `lib/index.ts`)
- Executable Producer → Snapshot Runtime Prelude: embeds runtime
- Snapshot Runtime Prelude → Runtime Diagnostics: uses diagnostics
