# yarnpkg/yarn architecture

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

## Overview

Yarn 1.x is a command-line dependency manager. The main user workflow is invoking a CLI command—especially install—to resolve dependency patterns, retrieve packages, and link them into a project while maintaining lockfile state. The README also documents caching/offline installs, deterministic resolution, integrity checks, workspaces, and network resilience. The graph includes these major runtime areas, but several links are dashed because the supplied excerpts and source index do not establish their exact call order.

Main entry points: [`src/cli/commands/install.js`](https://github.com/yarnpkg/yarn/blob/master/src/cli/commands/install.js) (Install command), [`src/package-resolver.js`](https://github.com/yarnpkg/yarn/blob/master/src/package-resolver.js) (Package resolver), [`src/cli/commands/audit.js`](https://github.com/yarnpkg/yarn/blob/master/src/cli/commands/audit.js) (Audit command), [`src/package-linker.js`](https://github.com/yarnpkg/yarn/blob/master/src/package-linker.js) (Package linker)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI and commands"]
  node_cli["CLI dispatcher<br/>[index.js]"]
  node_commands["CLI commands<br/>[index.js]"]
  node_installcmd["Install command<br/>[install.js]"]
  node_audit["Audit command<br/>[audit.js]"]
end

subgraph group_resolve["Dependency resolution"]
  node_resolver["Package resolver"]
  node_requests["Package requests<br/>[package-request.js]"]
  node_resolvers["Source resolvers<br/>[index.js]"]
  node_workspace["Workspace layout"]
end

subgraph group_install["Install and storage"]
  node_lockfile["Lockfile<br/>[index.js]"]
  node_fetchers["Package fetchers<br/>[index.js]"]
  node_cache[("Package cache<br/>[base-fetcher.js]")]
  node_linker["Package linker<br/>[package-linker.js]"]
  node_hoister["Dependency hoister<br/>[package-hoister.js]"]
  node_scripts["Install scripts"]
  node_integrity["Integrity checking"]
  node_pnp["Plug'n'Play support"]
end

subgraph group_runtime["Runtime services"]
  node_config["Configuration<br/>[config.js]"]
  node_registries["Package registries<br/>[index.js]"]
  node_network["HTTP request manager<br/>[request-manager.js]"]
  node_reporters["Output reporters<br/>[index.js]"]
end

node_user(("CLI user"))

node_user -.->|"invokes"| node_cli
node_cli -->|"dispatches"| node_commands
node_commands -.->|"routes install"| node_installcmd
node_installcmd -->|"uses configuration"| node_config
node_installcmd -->|"resolves dependencies"| node_resolver
node_installcmd -->|"reads and writes"| node_lockfile
node_installcmd -->|"links packages"| node_linker
node_installcmd -->|"fetches packages"| node_fetchers
node_installcmd -->|"runs scripts"| node_scripts
node_installcmd -->|"checks integrity"| node_integrity
node_installcmd -->|"reports progress"| node_reporters
node_audit -->|"inspects dependencies"| node_resolver
node_audit -->|"reads installed tree"| node_linker
node_audit -->|"reads lockfile"| node_lockfile
node_audit -->|"reports findings"| node_reporters
node_resolver -->|"creates requests"| node_requests
node_resolver -->|"selects resolver"| node_resolvers
node_resolver -->|"consults lock data"| node_lockfile
node_resolver -->|"uses workspace layout"| node_workspace
node_requests -->|"selects fetcher"| node_fetchers
node_config -->|"creates manager"| node_network
node_registries -->|"uses requests"| node_network
node_fetchers -.->|"fetches into cache"| node_cache
node_linker -->|"builds hoisted tree"| node_hoister
node_linker -->|"runs install scripts"| node_scripts
node_installcmd -.->|"supports PnP"| node_pnp
node_installcmd -.->|"supports workspaces"| node_workspace

click node_cli "https://github.com/yarnpkg/yarn/blob/master/src/cli/index.js"
click node_commands "https://github.com/yarnpkg/yarn/blob/master/src/cli/commands/index.js"
click node_installcmd "https://github.com/yarnpkg/yarn/blob/master/src/cli/commands/install.js"
click node_audit "https://github.com/yarnpkg/yarn/blob/master/src/cli/commands/audit.js"
click node_config "https://github.com/yarnpkg/yarn/blob/master/src/config.js"
click node_resolver "https://github.com/yarnpkg/yarn/blob/master/src/package-resolver.js"
click node_requests "https://github.com/yarnpkg/yarn/blob/master/src/package-request.js"
click node_resolvers "https://github.com/yarnpkg/yarn/blob/master/src/resolvers/index.js"
click node_workspace "https://github.com/yarnpkg/yarn/blob/master/src/workspace-layout.js"
click node_lockfile "https://github.com/yarnpkg/yarn/blob/master/src/lockfile/index.js"
click node_registries "https://github.com/yarnpkg/yarn/blob/master/src/registries/index.js"
click node_network "https://github.com/yarnpkg/yarn/blob/master/src/util/request-manager.js"
click node_fetchers "https://github.com/yarnpkg/yarn/blob/master/src/fetchers/index.js"
click node_cache "https://github.com/yarnpkg/yarn/blob/master/src/fetchers/base-fetcher.js"
click node_linker "https://github.com/yarnpkg/yarn/blob/master/src/package-linker.js"
click node_hoister "https://github.com/yarnpkg/yarn/blob/master/src/package-hoister.js"
click node_scripts "https://github.com/yarnpkg/yarn/blob/master/src/package-install-scripts.js"
click node_reporters "https://github.com/yarnpkg/yarn/blob/master/src/reporters/index.js"
click node_integrity "https://github.com/yarnpkg/yarn/blob/master/src/integrity-checker.js"
click node_pnp "https://github.com/yarnpkg/yarn/blob/master/src/util/generate-pnp-map.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_commands,node_installcmd,node_audit,node_user toneBlue
class node_resolver,node_requests,node_resolvers,node_workspace toneAmber
class node_lockfile,node_fetchers,node_cache,node_linker,node_hoister,node_scripts,node_integrity,node_pnp toneMint
class node_config,node_registries,node_network,node_reporters toneRose
```

## Components

### CLI and commands

- [CLI dispatcher](https://github.com/yarnpkg/yarn/blob/master/src/cli/index.js): `src/cli/index.js`
- [CLI commands](https://github.com/yarnpkg/yarn/blob/master/src/cli/commands/index.js): `src/cli/commands/index.js`
- [Install command](https://github.com/yarnpkg/yarn/blob/master/src/cli/commands/install.js): `src/cli/commands/install.js`
- [Audit command](https://github.com/yarnpkg/yarn/blob/master/src/cli/commands/audit.js): `src/cli/commands/audit.js`

### Dependency resolution

- [Package resolver](https://github.com/yarnpkg/yarn/blob/master/src/package-resolver.js): `src/package-resolver.js`
- [Package requests](https://github.com/yarnpkg/yarn/blob/master/src/package-request.js): `src/package-request.js`
- [Source resolvers](https://github.com/yarnpkg/yarn/blob/master/src/resolvers/index.js): `src/resolvers/index.js`
- [Workspace layout](https://github.com/yarnpkg/yarn/blob/master/src/workspace-layout.js): `src/workspace-layout.js`

### Install and storage

- [Lockfile](https://github.com/yarnpkg/yarn/blob/master/src/lockfile/index.js): `src/lockfile/index.js`
- [Package fetchers](https://github.com/yarnpkg/yarn/blob/master/src/fetchers/index.js): `src/fetchers/index.js`
- [Package cache](https://github.com/yarnpkg/yarn/blob/master/src/fetchers/base-fetcher.js): `src/fetchers/base-fetcher.js`
- [Package linker](https://github.com/yarnpkg/yarn/blob/master/src/package-linker.js): `src/package-linker.js`
- [Dependency hoister](https://github.com/yarnpkg/yarn/blob/master/src/package-hoister.js): `src/package-hoister.js`
- [Install scripts](https://github.com/yarnpkg/yarn/blob/master/src/package-install-scripts.js): `src/package-install-scripts.js`
- [Integrity checking](https://github.com/yarnpkg/yarn/blob/master/src/integrity-checker.js): `src/integrity-checker.js`
- [Plug'n'Play support](https://github.com/yarnpkg/yarn/blob/master/src/util/generate-pnp-map.js): `src/util/generate-pnp-map.js`

### Runtime services

- [Configuration](https://github.com/yarnpkg/yarn/blob/master/src/config.js): `src/config.js`
- [Package registries](https://github.com/yarnpkg/yarn/blob/master/src/registries/index.js): `src/registries/index.js`
- [HTTP request manager](https://github.com/yarnpkg/yarn/blob/master/src/util/request-manager.js): `src/util/request-manager.js`
- [Output reporters](https://github.com/yarnpkg/yarn/blob/master/src/reporters/index.js): `src/reporters/index.js`

### Other components

- **CLI user**

## Connections

- CLI user → CLI dispatcher: invokes
- CLI dispatcher → CLI commands: dispatches (evidence: `src/cli/index.js`)
- CLI commands → Install command: routes install
- Install command → Configuration: uses configuration (evidence: `src/cli/commands/install.js`)
- Install command → Package resolver: resolves dependencies (evidence: `src/cli/commands/install.js`)
- Install command → Lockfile: reads and writes (evidence: `src/cli/commands/install.js`)
- Install command → Package linker: links packages (evidence: `src/cli/commands/install.js`)
- Install command → Package fetchers: fetches packages (evidence: `src/cli/commands/install.js`)
- Install command → Install scripts: runs scripts (evidence: `src/cli/commands/install.js`)
- Install command → Integrity checking: checks integrity (evidence: `src/cli/commands/install.js`)
- Install command → Output reporters: reports progress (evidence: `src/cli/commands/install.js`)
- Audit command → Package resolver: inspects dependencies (evidence: `src/cli/commands/audit.js`)
- Audit command → Package linker: reads installed tree (evidence: `src/cli/commands/audit.js`)
- Audit command → Lockfile: reads lockfile (evidence: `src/cli/commands/audit.js`)
- Audit command → Output reporters: reports findings (evidence: `src/cli/commands/audit.js`)
- Package resolver → Package requests: creates requests (evidence: `src/package-resolver.js`)
- Package resolver → Source resolvers: selects resolver (evidence: `src/package-resolver.js`)
- Package resolver → Lockfile: consults lock data (evidence: `src/package-resolver.js`)
- Package resolver → Workspace layout: uses workspace layout (evidence: `src/package-resolver.js`)
- Package requests → Package fetchers: selects fetcher (evidence: `src/package-request.js`)
- Configuration → HTTP request manager: creates manager (evidence: `src/config.js`)
- Package registries → HTTP request manager: uses requests (evidence: `src/registries/npm-registry.js`)
- Package fetchers → Package cache: fetches into cache (evidence: `src/fetchers/index.js`)
- Package linker → Dependency hoister: builds hoisted tree (evidence: `src/package-linker.js`)
- Package linker → Install scripts: runs install scripts (evidence: `src/package-linker.js`)
- Install command → Plug'n'Play support: supports PnP (evidence: `src/cli/commands/install.js`)
- Install command → Workspace layout: supports workspaces (evidence: `src/cli/commands/install.js`)
