# spack/spack architecture

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

- Interactive diagram: https://gitdiagram.com/spack/spack
- Repository: https://github.com/spack/spack

## Overview

Spack is a multi-platform package manager for building and installing software in multiple versions and configurations. The principal workflow starts with a user’s package spec, resolves it into a concrete dependency configuration, then builds and installs it into a non-destructive package store. Environments and configuration support that workflow; package repositories supply recipes. The README documents the user-facing install workflow, while source-index references support several internal links. Other README capabilities such as binary build caches, module files, containers, and CI are retained as distinct branches; unsampled wiring is left unasserted.

Main entry points: [`lib/spack/spack/main.py`](https://github.com/spack/spack/blob/develop/lib/spack/spack/main.py) (CLI dispatch), [`lib/spack/spack/database.py`](https://github.com/spack/spack/blob/develop/lib/spack/spack/database.py) (Install database), [`lib/spack/spack/spec.py`](https://github.com/spack/spack/blob/develop/lib/spack/spack/spec.py) (Spec model), [`lib/spack/spack/package.py`](https://github.com/spack/spack/blob/develop/lib/spack/spack/package.py) (Package API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["CLI and environments"]
  node_cli["CLI dispatch<br/>[main.py]"]
  node_env["Environments<br/>[environment.py]"]
  node_color["Terminal output<br/>[color.py]"]
end

subgraph group_model["Specs and recipes"]
  node_spec["Spec model<br/>[spec.py]"]
  node_variant["Variant model<br/>[variant.py]"]
  node_repo["Package repositories<br/>[repo.py]"]
  node_solver["Dependency solver<br/>[asp.py]"]
  node_traverse["Dependency traversal<br/>[traverse.py]"]
  node_platform["Target platforms"]
end

subgraph group_build["Build and install"]
  node_package["Package API<br/>[package.py]"]
  node_packagebase["Package base<br/>[package_base.py]"]
  node_installer["Build and install<br/>[core.py]"]
  node_environmentmod["Build environment<br/>[environment.py]"]
  node_executable["Process execution<br/>[executable.py]"]
end

subgraph group_state["Configuration and storage"]
  node_config["Configuration<br/>[config.py]"]
  node_store[("Install store<br/>[store.py]")]
  node_database[("Install database<br/>[database.py]")]
  node_filesystem["Filesystem utilities<br/>[filesystem.py]"]
  node_locking["File locking<br/>[lock.py]"]
  node_yaml["YAML support<br/>[spack_yaml.py]"]
  node_lang["Language utilities<br/>[lang.py]"]
end

subgraph group_extensions["Distribution and integrations"]
  node_git["Git support<br/>[git.py]"]
  node_binary["Binary build caches"]
  node_modules["Environment modules<br/>[common.py]"]
  node_containers["Containers"]
  node_ci["Build pipelines"]
end

node_user(("Package user"))

node_user -->|"runs commands"| node_cli
node_cli -->|"supports environments"| node_env
node_cli -->|"loads configuration"| node_config
node_cli -->|"dispatches solving"| node_solver
node_user -->|"specifies package"| node_spec
node_solver -->|"resolves specs"| node_spec
node_solver -->|"traverses dependencies"| node_traverse
node_spec -->|"looks up package"| node_repo
node_env -->|"manages specs"| node_spec
node_repo -->|"loads recipes"| node_packagebase
node_package -->|"uses environment changes"| node_environmentmod
node_package -->|"runs processes"| node_executable
node_package -->|"uses file operations"| node_filesystem
node_user -->|"requests installation"| node_installer
node_installer -.->|"installs packages"| node_store
node_store -->|"tracks installs"| node_database
node_database -->|"uses repositories"| node_repo
node_database -->|"stores specs"| node_spec
node_database -->|"traverses records"| node_traverse
node_database -->|"uses file operations"| node_filesystem
node_database -->|"uses locks"| node_locking
node_config -->|"uses file operations"| node_filesystem
node_config -->|"reads YAML"| node_yaml
node_cli -->|"offers build caches"| node_binary
node_cli -->|"offers module files"| node_modules
node_cli -->|"supports containers"| node_containers
node_cli -->|"supports build pipelines"| node_ci
node_cli -->|"supports platforms"| node_platform
node_cli -->|"uses Git metadata"| node_git
node_cli -->|"uses terminal colors"| node_color
node_cli -->|"uses utilities"| node_lang
node_variant -.->|"models options"| node_spec

click node_cli "https://github.com/spack/spack/blob/develop/lib/spack/spack/main.py"
click node_env "https://github.com/spack/spack/blob/develop/lib/spack/spack/environment/environment.py"
click node_config "https://github.com/spack/spack/blob/develop/lib/spack/spack/config.py"
click node_spec "https://github.com/spack/spack/blob/develop/lib/spack/spack/spec.py"
click node_variant "https://github.com/spack/spack/blob/develop/lib/spack/spack/variant.py"
click node_repo "https://github.com/spack/spack/blob/develop/lib/spack/spack/repo.py"
click node_solver "https://github.com/spack/spack/blob/develop/lib/spack/spack/solver/asp.py"
click node_traverse "https://github.com/spack/spack/blob/develop/lib/spack/spack/traverse.py"
click node_package "https://github.com/spack/spack/blob/develop/lib/spack/spack/package.py"
click node_packagebase "https://github.com/spack/spack/blob/develop/lib/spack/spack/package_base.py"
click node_installer "https://github.com/spack/spack/blob/develop/lib/spack/spack/installer/core.py"
click node_store "https://github.com/spack/spack/blob/develop/lib/spack/spack/store.py"
click node_database "https://github.com/spack/spack/blob/develop/lib/spack/spack/database.py"
click node_environmentmod "https://github.com/spack/spack/blob/develop/lib/spack/spack/util/environment.py"
click node_executable "https://github.com/spack/spack/blob/develop/lib/spack/spack/util/executable.py"
click node_filesystem "https://github.com/spack/spack/blob/develop/lib/spack/spack/util/filesystem.py"
click node_locking "https://github.com/spack/spack/blob/develop/lib/spack/spack/util/lock.py"
click node_yaml "https://github.com/spack/spack/blob/develop/lib/spack/spack/util/spack_yaml.py"
click node_git "https://github.com/spack/spack/blob/develop/lib/spack/spack/util/git.py"
click node_lang "https://github.com/spack/spack/blob/develop/lib/spack/spack/util/lang.py"
click node_color "https://github.com/spack/spack/blob/develop/lib/spack/spack/util/tty/color.py"
click node_binary "https://github.com/spack/spack/blob/develop/lib/spack/spack/binary_distribution.py"
click node_modules "https://github.com/spack/spack/blob/develop/lib/spack/spack/modules/common.py"
click node_containers "https://github.com/spack/spack/tree/develop/lib/spack/spack/container"
click node_ci "https://github.com/spack/spack/tree/develop/lib/spack/spack/ci"
click node_platform "https://github.com/spack/spack/tree/develop/lib/spack/spack/platforms"

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_env,node_color,node_user toneBlue
class node_spec,node_variant,node_repo,node_solver,node_traverse,node_platform toneAmber
class node_package,node_packagebase,node_installer,node_environmentmod,node_executable toneMint
class node_config,node_store,node_database,node_filesystem,node_locking,node_yaml,node_lang toneRose
class node_git,node_binary,node_modules,node_containers,node_ci toneIndigo
```

## Components

### CLI and environments

- [CLI dispatch](https://github.com/spack/spack/blob/develop/lib/spack/spack/main.py): `lib/spack/spack/main.py`
- [Environments](https://github.com/spack/spack/blob/develop/lib/spack/spack/environment/environment.py): `lib/spack/spack/environment/environment.py`
- [Terminal output](https://github.com/spack/spack/blob/develop/lib/spack/spack/util/tty/color.py): `lib/spack/spack/util/tty/color.py`

### Specs and recipes

- [Spec model](https://github.com/spack/spack/blob/develop/lib/spack/spack/spec.py): `lib/spack/spack/spec.py`
- [Variant model](https://github.com/spack/spack/blob/develop/lib/spack/spack/variant.py): `lib/spack/spack/variant.py`
- [Package repositories](https://github.com/spack/spack/blob/develop/lib/spack/spack/repo.py): `lib/spack/spack/repo.py`
- [Dependency solver](https://github.com/spack/spack/blob/develop/lib/spack/spack/solver/asp.py): `lib/spack/spack/solver/asp.py`
- [Dependency traversal](https://github.com/spack/spack/blob/develop/lib/spack/spack/traverse.py): `lib/spack/spack/traverse.py`
- [Target platforms](https://github.com/spack/spack/tree/develop/lib/spack/spack/platforms): `lib/spack/spack/platforms`

### Build and install

- [Package API](https://github.com/spack/spack/blob/develop/lib/spack/spack/package.py): `lib/spack/spack/package.py`
- [Package base](https://github.com/spack/spack/blob/develop/lib/spack/spack/package_base.py): `lib/spack/spack/package_base.py`
- [Build and install](https://github.com/spack/spack/blob/develop/lib/spack/spack/installer/core.py): `lib/spack/spack/installer/core.py`
- [Build environment](https://github.com/spack/spack/blob/develop/lib/spack/spack/util/environment.py): `lib/spack/spack/util/environment.py`
- [Process execution](https://github.com/spack/spack/blob/develop/lib/spack/spack/util/executable.py): `lib/spack/spack/util/executable.py`

### Configuration and storage

- [Configuration](https://github.com/spack/spack/blob/develop/lib/spack/spack/config.py): `lib/spack/spack/config.py`
- [Install store](https://github.com/spack/spack/blob/develop/lib/spack/spack/store.py): `lib/spack/spack/store.py`
- [Install database](https://github.com/spack/spack/blob/develop/lib/spack/spack/database.py): `lib/spack/spack/database.py`
- [Filesystem utilities](https://github.com/spack/spack/blob/develop/lib/spack/spack/util/filesystem.py): `lib/spack/spack/util/filesystem.py`
- [File locking](https://github.com/spack/spack/blob/develop/lib/spack/spack/util/lock.py): `lib/spack/spack/util/lock.py`
- [YAML support](https://github.com/spack/spack/blob/develop/lib/spack/spack/util/spack_yaml.py): `lib/spack/spack/util/spack_yaml.py`
- [Language utilities](https://github.com/spack/spack/blob/develop/lib/spack/spack/util/lang.py): `lib/spack/spack/util/lang.py`

### Distribution and integrations

- [Git support](https://github.com/spack/spack/blob/develop/lib/spack/spack/util/git.py): `lib/spack/spack/util/git.py`
- [Binary build caches](https://github.com/spack/spack/blob/develop/lib/spack/spack/binary_distribution.py): `lib/spack/spack/binary_distribution.py`
- [Environment modules](https://github.com/spack/spack/blob/develop/lib/spack/spack/modules/common.py): `lib/spack/spack/modules/common.py`
- [Containers](https://github.com/spack/spack/tree/develop/lib/spack/spack/container): `lib/spack/spack/container`
- [Build pipelines](https://github.com/spack/spack/tree/develop/lib/spack/spack/ci): `lib/spack/spack/ci`

### Other components

- **Package user**

## Connections

- Package user → CLI dispatch: runs commands (evidence: `README.md`)
- CLI dispatch → Environments: supports environments (evidence: `lib/spack/spack/main.py`)
- CLI dispatch → Configuration: loads configuration (evidence: `lib/spack/spack/main.py`)
- CLI dispatch → Dependency solver: dispatches solving (evidence: `lib/spack/spack/main.py`)
- Package user → Spec model: specifies package (evidence: `README.md`)
- Dependency solver → Spec model: resolves specs (evidence: `lib/spack/spack/solver/asp.py`)
- Dependency solver → Dependency traversal: traverses dependencies (evidence: `lib/spack/spack/solver/asp.py`)
- Spec model → Package repositories: looks up package (evidence: `lib/spack/spack/spec.py`)
- Environments → Spec model: manages specs (evidence: `lib/spack/spack/environment/environment.py`)
- Package repositories → Package base: loads recipes (evidence: `lib/spack/spack/repo.py`)
- Package API → Build environment: uses environment changes (evidence: `lib/spack/spack/package.py`)
- Package API → Process execution: runs processes (evidence: `lib/spack/spack/package.py`)
- Package API → Filesystem utilities: uses file operations (evidence: `lib/spack/spack/package.py`)
- Package user → Build and install: requests installation (evidence: `README.md`)
- Build and install → Install store: installs packages
- Install store → Install database: tracks installs (evidence: `lib/spack/spack/database.py`)
- Install database → Package repositories: uses repositories (evidence: `lib/spack/spack/database.py`)
- Install database → Spec model: stores specs (evidence: `lib/spack/spack/database.py`)
- Install database → Dependency traversal: traverses records (evidence: `lib/spack/spack/database.py`)
- Install database → Filesystem utilities: uses file operations (evidence: `lib/spack/spack/database.py`)
- Install database → File locking: uses locks (evidence: `lib/spack/spack/database.py`)
- Configuration → Filesystem utilities: uses file operations (evidence: `lib/spack/spack/config.py`)
- Configuration → YAML support: reads YAML (evidence: `lib/spack/spack/config.py`)
- CLI dispatch → Binary build caches: offers build caches (evidence: `README.md`)
- CLI dispatch → Environment modules: offers module files (evidence: `README.md`)
- CLI dispatch → Containers: supports containers (evidence: `README.md`)
- CLI dispatch → Build pipelines: supports build pipelines (evidence: `README.md`)
- CLI dispatch → Target platforms: supports platforms (evidence: `README.md`)
- CLI dispatch → Git support: uses Git metadata
- CLI dispatch → Terminal output: uses terminal colors (evidence: `lib/spack/spack/main.py`)
- CLI dispatch → Language utilities: uses utilities (evidence: `lib/spack/spack/main.py`)
- Variant model → Spec model: models options (evidence: `lib/spack/spack/spec.py`)
