# lesgourg/class_public architecture

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

- Interactive diagram: https://gitdiagram.com/lesgourg/class_public
- Repository: https://github.com/lesgourg/class_public

## Overview

CLASS is a cosmological Boltzmann solver. Its principal workflow takes cosmological and precision parameters, computes the expansion and thermal history, evolves perturbations, and produces primordial, transfer, and observable spectra for output. The repository also includes nonlinear-spectrum prescriptions, spectral distortions, recombination and energy-injection implementations, a C++ engine, and a plotting utility. The README documents the solver and plotting capability; several connections among runtime stages are not visible in the sampled excerpts, so those links are marked unverified rather than asserted as source-confirmed calls.

Main entry points: [`source/thermodynamics.c`](https://github.com/lesgourg/class_public/blob/master/source/thermodynamics.c) (Thermal history), [`source/fourier.c`](https://github.com/lesgourg/class_public/blob/master/source/fourier.c) (Fourier spectra), [`source/perturbations.c`](https://github.com/lesgourg/class_public/blob/master/source/perturbations.c) (Perturbation evolution), [`main/class.c`](https://github.com/lesgourg/class_public/blob/master/main/class.c) (CLASS runner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Inputs and orchestration"]
  node_parser["Input parser<br/>[parser.c]"]
  node_input_config["Parameter setup<br/>[input.c]"]
  node_class_runner["CLASS runner<br/>[class.c]"]
end

subgraph group_physics["Cosmological evolution"]
  node_background["Background evolution<br/>[background.c]"]
  node_thermodynamics["Thermal history<br/>[thermodynamics.c]"]
  node_perturbations["Perturbation evolution<br/>[perturbations.c]"]
end

subgraph group_spectra["Spectra and observables"]
  node_primordial["Primordial spectra<br/>[primordial.c]"]
  node_transfer["Transfer functions<br/>[transfer.c]"]
  node_fourier["Fourier spectra<br/>[fourier.c]"]
  node_lensing["Lensing<br/>[lensing.c]"]
end

subgraph group_extensions["Physics extensions"]
  node_hyrec["HyRec recombination<br/>[history.c]"]
  node_recfast["RECFAST wrapper<br/>[wrap_recfast.c]"]
  node_energy_injection["Energy injection<br/>[injection.c]"]
  node_hmcode["HMcode nonlinear<br/>[hmcode.c]"]
  node_halofit["Halofit nonlinear<br/>[halofit.c]"]
  node_distortions["Spectral distortions<br/>[distortions.c]"]
end

subgraph group_interfaces["Interfaces and output"]
  node_output["Results output<br/>[output.c]"]
  node_cpp_engine["C++ engine<br/>[ClassEngine.cc]"]
  node_plotter["CLASS plotter<br/>[CPU.py]"]
end

node_user(("Researcher"))
node_parameter_files["Parameter files"]
node_result_files["Output files"]

node_user -->|"sets parameters"| node_parameter_files
node_parameter_files -.->|"provides input"| node_parser
node_parser -->|"parses values"| node_input_config
node_input_config -.->|"configures run"| node_class_runner
node_class_runner -.->|"runs solver"| node_background
node_background -.->|"feeds history"| node_thermodynamics
node_thermodynamics -->|"uses recombination"| node_hyrec
node_thermodynamics -->|"uses recombination"| node_recfast
node_thermodynamics -->|"uses injection"| node_energy_injection
node_thermodynamics -->|"supplies history"| node_perturbations
node_background -.->|"supplies expansion"| node_perturbations
node_perturbations -->|"supplies perturbations"| node_primordial
node_primordial -.->|"feeds spectra"| node_transfer
node_transfer -.->|"feeds spectra"| node_fourier
node_fourier -->|"provides linear spectra"| node_hmcode
node_fourier -->|"provides linear spectra"| node_halofit
node_fourier -.->|"feeds lensing"| node_lensing
node_perturbations -.->|"feeds distortions"| node_distortions
node_class_runner -.->|"writes results"| node_output
node_user -.->|"requests calculations"| node_cpp_engine
node_cpp_engine -->|"queries spectra"| node_lensing
node_user -->|"selects results"| node_plotter
node_output -.->|"writes files"| node_result_files
node_result_files -->|"plots results"| node_plotter

click node_parser "https://github.com/lesgourg/class_public/blob/master/tools/parser.c"
click node_input_config "https://github.com/lesgourg/class_public/blob/master/source/input.c"
click node_class_runner "https://github.com/lesgourg/class_public/blob/master/main/class.c"
click node_background "https://github.com/lesgourg/class_public/blob/master/source/background.c"
click node_thermodynamics "https://github.com/lesgourg/class_public/blob/master/source/thermodynamics.c"
click node_hyrec "https://github.com/lesgourg/class_public/blob/master/external/HyRec2020/history.c"
click node_recfast "https://github.com/lesgourg/class_public/blob/master/external/RecfastCLASS/wrap_recfast.c"
click node_energy_injection "https://github.com/lesgourg/class_public/blob/master/external/heating/injection.c"
click node_perturbations "https://github.com/lesgourg/class_public/blob/master/source/perturbations.c"
click node_primordial "https://github.com/lesgourg/class_public/blob/master/source/primordial.c"
click node_transfer "https://github.com/lesgourg/class_public/blob/master/source/transfer.c"
click node_fourier "https://github.com/lesgourg/class_public/blob/master/source/fourier.c"
click node_hmcode "https://github.com/lesgourg/class_public/blob/master/external/HMcode/hmcode.c"
click node_halofit "https://github.com/lesgourg/class_public/blob/master/external/Halofit/halofit.c"
click node_lensing "https://github.com/lesgourg/class_public/blob/master/source/lensing.c"
click node_distortions "https://github.com/lesgourg/class_public/blob/master/source/distortions.c"
click node_output "https://github.com/lesgourg/class_public/blob/master/source/output.c"
click node_cpp_engine "https://github.com/lesgourg/class_public/blob/master/cpp/ClassEngine.cc"
click node_plotter "https://github.com/lesgourg/class_public/blob/master/CPU.py"

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_parser,node_input_config,node_class_runner toneBlue
class node_background,node_thermodynamics,node_perturbations toneAmber
class node_primordial,node_transfer,node_fourier,node_lensing toneMint
class node_hyrec,node_recfast,node_energy_injection,node_hmcode,node_halofit,node_distortions toneRose
class node_output,node_cpp_engine,node_plotter,node_user,node_parameter_files,node_result_files toneIndigo
```

## Components

### Inputs and orchestration

- [Input parser](https://github.com/lesgourg/class_public/blob/master/tools/parser.c): `tools/parser.c`
- [Parameter setup](https://github.com/lesgourg/class_public/blob/master/source/input.c): `source/input.c`
- [CLASS runner](https://github.com/lesgourg/class_public/blob/master/main/class.c): `main/class.c`

### Cosmological evolution

- [Background evolution](https://github.com/lesgourg/class_public/blob/master/source/background.c): `source/background.c`
- [Thermal history](https://github.com/lesgourg/class_public/blob/master/source/thermodynamics.c): `source/thermodynamics.c`
- [Perturbation evolution](https://github.com/lesgourg/class_public/blob/master/source/perturbations.c): `source/perturbations.c`

### Spectra and observables

- [Primordial spectra](https://github.com/lesgourg/class_public/blob/master/source/primordial.c): `source/primordial.c`
- [Transfer functions](https://github.com/lesgourg/class_public/blob/master/source/transfer.c): `source/transfer.c`
- [Fourier spectra](https://github.com/lesgourg/class_public/blob/master/source/fourier.c): `source/fourier.c`
- [Lensing](https://github.com/lesgourg/class_public/blob/master/source/lensing.c): `source/lensing.c`

### Physics extensions

- [HyRec recombination](https://github.com/lesgourg/class_public/blob/master/external/HyRec2020/history.c): `external/HyRec2020/history.c`
- [RECFAST wrapper](https://github.com/lesgourg/class_public/blob/master/external/RecfastCLASS/wrap_recfast.c): `external/RecfastCLASS/wrap_recfast.c`
- [Energy injection](https://github.com/lesgourg/class_public/blob/master/external/heating/injection.c): `external/heating/injection.c`
- [HMcode nonlinear](https://github.com/lesgourg/class_public/blob/master/external/HMcode/hmcode.c): `external/HMcode/hmcode.c`
- [Halofit nonlinear](https://github.com/lesgourg/class_public/blob/master/external/Halofit/halofit.c): `external/Halofit/halofit.c`
- [Spectral distortions](https://github.com/lesgourg/class_public/blob/master/source/distortions.c): `source/distortions.c`

### Interfaces and output

- [Results output](https://github.com/lesgourg/class_public/blob/master/source/output.c): `source/output.c`
- [C++ engine](https://github.com/lesgourg/class_public/blob/master/cpp/ClassEngine.cc): `cpp/ClassEngine.cc`
- [CLASS plotter](https://github.com/lesgourg/class_public/blob/master/CPU.py): `CPU.py`

### Other components

- **Researcher**
- **Parameter files**
- **Output files**

## Connections

- Researcher → Parameter files: sets parameters
- Parameter files → Input parser: provides input
- Input parser → Parameter setup: parses values (evidence: `source/input.c`)
- Parameter setup → CLASS runner: configures run
- CLASS runner → Background evolution: runs solver
- Background evolution → Thermal history: feeds history
- Thermal history → HyRec recombination: uses recombination
- Thermal history → RECFAST wrapper: uses recombination
- Thermal history → Energy injection: uses injection
- Thermal history → Perturbation evolution: supplies history
- Background evolution → Perturbation evolution: supplies expansion
- Perturbation evolution → Primordial spectra: supplies perturbations
- Primordial spectra → Transfer functions: feeds spectra
- Transfer functions → Fourier spectra: feeds spectra
- Fourier spectra → HMcode nonlinear: provides linear spectra (evidence: `external/HMcode/hmcode.c`)
- Fourier spectra → Halofit nonlinear: provides linear spectra (evidence: `external/Halofit/halofit.c`)
- Fourier spectra → Lensing: feeds lensing
- Perturbation evolution → Spectral distortions: feeds distortions
- CLASS runner → Results output: writes results
- Researcher → C++ engine: requests calculations
- C++ engine → Lensing: queries spectra (evidence: `cpp/ClassEngine.cc`)
- Researcher → CLASS plotter: selects results
- Results output → Output files: writes files
- Output files → CLASS plotter: plots results
