# nodejs/corepack architecture

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

- Interactive diagram: https://gitdiagram.com/nodejs/corepack
- Repository: https://github.com/nodejs/corepack

## Overview

Corepack bridges project package-manager declarations to Yarn, npm, or pnpm: CLI invocations are classified, project and environment settings select a compatible release, Corepack obtains and caches it, then launches its binary. Utility commands manage shims, cache contents, global defaults, offline archives, and local package-manager declarations. The source index and excerpts establish the principal wiring; several command implementations and Engine internals were not shown, so those relationships are limited to documented or indexed references.

Main entry points: [`sources/main.ts`](https://github.com/nodejs/corepack/blob/main/sources/main.ts) (CLI dispatcher), [`sources/Engine.ts`](https://github.com/nodejs/corepack/blob/main/sources/Engine.ts) (Package manager engine), [`sources/corepackUtils.ts`](https://github.com/nodejs/corepack/blob/main/sources/corepackUtils.ts) (Package manager install and run), [`sources/commands/Base.ts`](https://github.com/nodejs/corepack/blob/main/sources/commands/Base.ts) (Command base)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["CLI and dispatch"]
  node_main["CLI dispatcher<br/>[main.ts]"]
  node_engine["Package manager engine<br/>[Engine.ts]"]
end

subgraph group_selection["Package selection"]
  node_spec["Project spec and env<br/>[specUtils.ts]"]
  node_semver["Version matching<br/>[semverUtils.ts]"]
  node_config["Manager definitions<br/>[config.json]"]
end

subgraph group_distribution["Download and cache"]
  node_coreutils["Package manager install and run<br/>[corepackUtils.ts]"]
  node_cache[("Package manager cache<br/>[folderUtils.ts]")]
  node_registry["Registry metadata and integrity"]
  node_http["HTTP requests<br/>[httpUtils.ts]"]
end

subgraph group_commands["Management commands"]
  node_base["Command base<br/>[Base.ts]"]
  node_enable["Enable shims<br/>[Enable.ts]"]
  node_disable["Disable shims<br/>[Disable.ts]"]
  node_cachecmd["Cache commands<br/>[Cache.ts]"]
  node_global["Global install<br/>[InstallGlobal.ts]"]
  node_local["Local install<br/>[InstallLocal.ts]"]
  node_pack["Offline pack<br/>[Pack.ts]"]
  node_up["Update defaults<br/>[Up.ts]"]
  node_use["Select version<br/>[Use.ts]"]
  node_prepare["Prepare archive<br/>[Prepare.ts]"]
  node_hydrate["Hydrate cache<br/>[Hydrate.ts]"]
end

subgraph group_support["Runtime support"]
  node_nodeutils["Node filesystem helpers<br/>[nodeUtils.ts]"]
  node_debug["Debug logging<br/>[debugUtils.ts]"]
end

node_user(("Developer"))
node_manager["Package manager binary"]
node_npm["npm registry"]

node_user -->|"runs CLI"| node_main
node_main -->|"dispatches request"| node_engine
node_main -->|"registers command"| node_enable
node_main -->|"registers command"| node_disable
node_main -->|"registers command"| node_cachecmd
node_main -->|"registers command"| node_global
node_main -->|"registers command"| node_local
node_main -->|"registers command"| node_pack
node_main -->|"registers command"| node_up
node_main -->|"registers command"| node_use
node_main -->|"registers command"| node_prepare
node_main -->|"registers command"| node_hydrate
node_main -->|"parses manager request"| node_spec
node_engine -->|"reads project selection"| node_spec
node_engine -->|"matches versions"| node_semver
node_engine -->|"uses definitions"| node_config
node_engine -->|"installs and runs manager"| node_coreutils
node_coreutils -->|"uses cache folders"| node_cache
node_coreutils -->|"resolves package releases"| node_registry
node_registry -->|"fetches metadata"| node_http
node_http -->|"requests registry"| node_npm
node_coreutils -->|"loads manager binary"| node_manager
node_base -->|"resolves project specs"| node_spec
node_base -->|"runs selected manager"| node_coreutils
node_global -->|"resolves and installs"| node_engine
node_prepare -->|"resolves and prepares"| node_engine
node_prepare -->|"reads project spec"| node_spec
node_prepare -->|"archives install paths"| node_cache
node_enable -->|"gets shim binaries"| node_engine
node_enable -->|"creates executable shims"| node_manager
node_cachecmd -->|"clears cache"| node_cache
node_local -->|"uses command helpers"| node_base
node_pack -->|"uses command helpers"| node_base
node_up -->|"uses command helpers"| node_base
node_use -->|"uses command helpers"| node_base
node_coreutils -->|"uses filesystem helpers"| node_nodeutils
node_spec -->|"normalizes manifest text"| node_nodeutils
node_engine -->|"logs resolution"| node_debug
node_coreutils -->|"logs installation"| node_debug

click node_main "https://github.com/nodejs/corepack/blob/main/sources/main.ts"
click node_engine "https://github.com/nodejs/corepack/blob/main/sources/Engine.ts"
click node_spec "https://github.com/nodejs/corepack/blob/main/sources/specUtils.ts"
click node_semver "https://github.com/nodejs/corepack/blob/main/sources/semverUtils.ts"
click node_config "https://github.com/nodejs/corepack/blob/main/config.json"
click node_base "https://github.com/nodejs/corepack/blob/main/sources/commands/Base.ts"
click node_enable "https://github.com/nodejs/corepack/blob/main/sources/commands/Enable.ts"
click node_disable "https://github.com/nodejs/corepack/blob/main/sources/commands/Disable.ts"
click node_cachecmd "https://github.com/nodejs/corepack/blob/main/sources/commands/Cache.ts"
click node_global "https://github.com/nodejs/corepack/blob/main/sources/commands/InstallGlobal.ts"
click node_local "https://github.com/nodejs/corepack/blob/main/sources/commands/InstallLocal.ts"
click node_pack "https://github.com/nodejs/corepack/blob/main/sources/commands/Pack.ts"
click node_up "https://github.com/nodejs/corepack/blob/main/sources/commands/Up.ts"
click node_use "https://github.com/nodejs/corepack/blob/main/sources/commands/Use.ts"
click node_prepare "https://github.com/nodejs/corepack/blob/main/sources/commands/deprecated/Prepare.ts"
click node_hydrate "https://github.com/nodejs/corepack/blob/main/sources/commands/deprecated/Hydrate.ts"
click node_coreutils "https://github.com/nodejs/corepack/blob/main/sources/corepackUtils.ts"
click node_cache "https://github.com/nodejs/corepack/blob/main/sources/folderUtils.ts"
click node_registry "https://github.com/nodejs/corepack/blob/main/sources/npmRegistryUtils.ts"
click node_http "https://github.com/nodejs/corepack/blob/main/sources/httpUtils.ts"
click node_nodeutils "https://github.com/nodejs/corepack/blob/main/sources/nodeUtils.ts"
click node_debug "https://github.com/nodejs/corepack/blob/main/sources/debugUtils.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_main,node_engine toneBlue
class node_spec,node_semver,node_config toneAmber
class node_coreutils,node_cache,node_registry,node_http toneMint
class node_base,node_enable,node_disable,node_cachecmd,node_global,node_local,node_pack,node_up,node_use,node_prepare,node_hydrate toneRose
class node_nodeutils,node_debug,node_user,node_manager,node_npm toneIndigo
```

## Components

### CLI and dispatch

- [CLI dispatcher](https://github.com/nodejs/corepack/blob/main/sources/main.ts): `sources/main.ts`
- [Package manager engine](https://github.com/nodejs/corepack/blob/main/sources/Engine.ts): `sources/Engine.ts`

### Package selection

- [Project spec and env](https://github.com/nodejs/corepack/blob/main/sources/specUtils.ts): `sources/specUtils.ts`
- [Version matching](https://github.com/nodejs/corepack/blob/main/sources/semverUtils.ts): `sources/semverUtils.ts`
- [Manager definitions](https://github.com/nodejs/corepack/blob/main/config.json): `config.json`

### Download and cache

- [Package manager install and run](https://github.com/nodejs/corepack/blob/main/sources/corepackUtils.ts): `sources/corepackUtils.ts`
- [Package manager cache](https://github.com/nodejs/corepack/blob/main/sources/folderUtils.ts): `sources/folderUtils.ts`
- [Registry metadata and integrity](https://github.com/nodejs/corepack/blob/main/sources/npmRegistryUtils.ts): `sources/npmRegistryUtils.ts`
- [HTTP requests](https://github.com/nodejs/corepack/blob/main/sources/httpUtils.ts): `sources/httpUtils.ts`

### Management commands

- [Command base](https://github.com/nodejs/corepack/blob/main/sources/commands/Base.ts): `sources/commands/Base.ts`
- [Enable shims](https://github.com/nodejs/corepack/blob/main/sources/commands/Enable.ts): `sources/commands/Enable.ts`
- [Disable shims](https://github.com/nodejs/corepack/blob/main/sources/commands/Disable.ts): `sources/commands/Disable.ts`
- [Cache commands](https://github.com/nodejs/corepack/blob/main/sources/commands/Cache.ts): `sources/commands/Cache.ts`
- [Global install](https://github.com/nodejs/corepack/blob/main/sources/commands/InstallGlobal.ts): `sources/commands/InstallGlobal.ts`
- [Local install](https://github.com/nodejs/corepack/blob/main/sources/commands/InstallLocal.ts): `sources/commands/InstallLocal.ts`
- [Offline pack](https://github.com/nodejs/corepack/blob/main/sources/commands/Pack.ts): `sources/commands/Pack.ts`
- [Update defaults](https://github.com/nodejs/corepack/blob/main/sources/commands/Up.ts): `sources/commands/Up.ts`
- [Select version](https://github.com/nodejs/corepack/blob/main/sources/commands/Use.ts): `sources/commands/Use.ts`
- [Prepare archive](https://github.com/nodejs/corepack/blob/main/sources/commands/deprecated/Prepare.ts): `sources/commands/deprecated/Prepare.ts`
- [Hydrate cache](https://github.com/nodejs/corepack/blob/main/sources/commands/deprecated/Hydrate.ts): `sources/commands/deprecated/Hydrate.ts`

### Runtime support

- [Node filesystem helpers](https://github.com/nodejs/corepack/blob/main/sources/nodeUtils.ts): `sources/nodeUtils.ts`
- [Debug logging](https://github.com/nodejs/corepack/blob/main/sources/debugUtils.ts): `sources/debugUtils.ts`

### Other components

- **Developer**
- **Package manager binary**
- **npm registry**

## Connections

- Developer → CLI dispatcher: runs CLI (evidence: `README.md`)
- CLI dispatcher → Package manager engine: dispatches request (evidence: `sources/main.ts`)
- CLI dispatcher → Enable shims: registers command (evidence: `sources/main.ts`)
- CLI dispatcher → Disable shims: registers command (evidence: `sources/main.ts`)
- CLI dispatcher → Cache commands: registers command (evidence: `sources/main.ts`)
- CLI dispatcher → Global install: registers command (evidence: `sources/main.ts`)
- CLI dispatcher → Local install: registers command (evidence: `sources/main.ts`)
- CLI dispatcher → Offline pack: registers command (evidence: `sources/main.ts`)
- CLI dispatcher → Update defaults: registers command (evidence: `sources/main.ts`)
- CLI dispatcher → Select version: registers command (evidence: `sources/main.ts`)
- CLI dispatcher → Prepare archive: registers command (evidence: `sources/main.ts`)
- CLI dispatcher → Hydrate cache: registers command (evidence: `sources/main.ts`)
- CLI dispatcher → Project spec and env: parses manager request (evidence: `sources/main.ts`)
- Package manager engine → Project spec and env: reads project selection (evidence: `sources/Engine.ts`)
- Package manager engine → Version matching: matches versions (evidence: `sources/Engine.ts`)
- Package manager engine → Manager definitions: uses definitions (evidence: `sources/Engine.ts`)
- Package manager engine → Package manager install and run: installs and runs manager (evidence: `sources/Engine.ts`)
- Package manager install and run → Package manager cache: uses cache folders (evidence: `sources/corepackUtils.ts`)
- Package manager install and run → Registry metadata and integrity: resolves package releases (evidence: `sources/corepackUtils.ts`)
- Registry metadata and integrity → HTTP requests: fetches metadata (evidence: `sources/npmRegistryUtils.ts`)
- HTTP requests → npm registry: requests registry (evidence: `sources/httpUtils.ts`)
- Package manager install and run → Package manager binary: loads manager binary (evidence: `README.md`)
- Command base → Project spec and env: resolves project specs (evidence: `sources/commands/Base.ts`)
- Command base → Package manager install and run: runs selected manager (evidence: `sources/commands/Base.ts`)
- Global install → Package manager engine: resolves and installs (evidence: `sources/commands/InstallGlobal.ts`)
- Prepare archive → Package manager engine: resolves and prepares (evidence: `sources/commands/deprecated/Prepare.ts`)
- Prepare archive → Project spec and env: reads project spec (evidence: `sources/commands/deprecated/Prepare.ts`)
- Prepare archive → Package manager cache: archives install paths (evidence: `sources/commands/deprecated/Prepare.ts`)
- Enable shims → Package manager engine: gets shim binaries (evidence: `sources/commands/Enable.ts`)
- Enable shims → Package manager binary: creates executable shims (evidence: `sources/commands/Enable.ts`)
- Cache commands → Package manager cache: clears cache (evidence: `sources/commands/Cache.ts`)
- Local install → Command base: uses command helpers (evidence: `sources/commands/InstallLocal.ts`)
- Offline pack → Command base: uses command helpers (evidence: `sources/commands/Pack.ts`)
- Update defaults → Command base: uses command helpers (evidence: `sources/commands/Up.ts`)
- Select version → Command base: uses command helpers (evidence: `sources/commands/Use.ts`)
- Package manager install and run → Node filesystem helpers: uses filesystem helpers (evidence: `sources/corepackUtils.ts`)
- Project spec and env → Node filesystem helpers: normalizes manifest text (evidence: `sources/specUtils.ts`)
- Package manager engine → Debug logging: logs resolution (evidence: `sources/Engine.ts`)
- Package manager install and run → Debug logging: logs installation (evidence: `sources/corepackUtils.ts`)
