# rpm-software-management/libdnf architecture

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

- Interactive diagram: https://gitdiagram.com/rpm-software-management/libdnf
- Repository: https://github.com/rpm-software-management/libdnf

## Overview

1. **What this repository is**
   - `libdnf` is a library, not an application. It is the core package-management engine used by tools like DNF, PackageKit, and rpm-ostree.
   - Its main job is to ingest repository metadata, model packages and modules, resolve dependency goals, and record/manage transactions.

2. **Top-level architecture**
   - The code is split into a **core C/C++ library**, **compatibility layers**, **language bindings**, **plugins**, **tests/fixtures**, and **documentation**.
   - The key runtime dependencies are **librepo** for fetching repo metadata/packages, **libsolv** for dependency solving, **rpm** for package/database interaction, **SQLite** for transaction history, and **modulemd** for modular metadata.

3. **Core repository and package model**
   - The `libdnf/repo`, `libdnf/sack`, and `libdnf/goal` areas form the central dependency-resolution pipeline.
   - Repository metadata is loaded into a **sack** (package universe), represented as solvables/packages, queried through `query`/`selector`, and then fed into a **goal** that computes an install/update/remove solution.

4. **Repository ingestion boundary**
   - `libdnf/repo/Repo`, `dnf-repo-loader`, and `repo/Crypto` are the boundary for talking to external repositories.
   - This layer handles metadata loading, package download coordination, dependency splitting, and signature/GPG-related checks.
   - It is the main interface to the outside world: remote YUM/DNF-style repos and their `repodata`.

5. **Configuration and runtime context**
   - `libdnf/conf` parses and stores configuration such as main config, repo config, and typed options.
   - `dnf-context` acts as the orchestration object tying together config, locks, repos, sack, and transaction logic.
   - This is where per-run state is assembled before any solving or transaction work happens.

6. **Dependency-solving and package identity**
   - Package identity and matching are normalized through `nevra`, `nsvcap`, `reldep`, and the `hy-*` compatibility classes.
   - The dependency solver boundary is centered around `goal`, `selector`, `query`, and `package` objects, which wrap the lower-level solver concepts from libsolv.
   - This layer converts repository/package metadata into solver-friendly objects and back into user-facing package results.

7. **Transaction and history subsystem**
   - `libdnf/transaction` contains transaction items, merging/transforming logic, and persistence helpers.
   - `transaction/sql` defines the schema and migrations for the transaction history database.
   - The flow is: solver output → transaction objects → persisted history / replay / migration support.

8. **RPM and system integration**
   - `dnf-rpmts`, `dnf-db`, `dnf-package`, and related classes bridge libdnf to the installed system’s RPM database and transaction set.
   - `dnf-lock` handles serialization/locking so only one package-management operation can safely proceed at a time.
   - `dnf-keyring` supports key management for verifying repository/package trust.

9. **Module and advisory support**
   - `libdnf/module` and `libdnf/module/modulemd` implement modularity support using ModuleMD metadata.
   - The advisory-related code (`dnf-advisory*`, `sack/advisory*`) models security/errata metadata alongside package metadata.
   - This means the sack is not just packages; it also carries modular streams and advisory context used during selection and updates.

10. **Compatibility layer: hawkey**
   - The `hy-*` files and `python/hawkey` tree are the old hawkey API layer kept inside libdnf for compatibility.
   - This is important architecturally: consumers can still use hawkey-style APIs while the implementation is backed by libdnf internals.
   - The Python package exposes that compatibility surface through generated bindings and handwritten Python glue.

11. **Language bindings**
   - `bindings/swig` plus `bindings/python` and `bindings/perl` provide generated bindings from the C/C++ APIs.
   - The `python/hawkey` package is the primary Python-facing interface in this repo, with its own test suite.
   - These bindings sit on top of the core library; they do not implement package management logic themselves.

12. **Utilities and shared infrastructure**
   - `libdnf/utils` contains shared support code: compression, filesystem helpers, logging, ini parsing, SQLite wrapper, URL encoding, regex, and UI table formatting.
   - `po/` provides translations, and `docs/` contains both API and project documentation.
   - `plugins/` shows the plugin boundary, including an example plugin and RHSM integration.

13. **Testing strategy and data flow fixtures**
   - `tests/` contains C/C++ unit tests for the core library and `python/hawkey/tests` contains Python tests for the binding/API surface.
   - `data/tests/` is extensive fixture data: repo metadata, RPMs, GPG keys, modular repositories, advisories, and config files.
   - These fixtures simulate real-world repo ingestion and solving paths, so the test architecture mirrors production data flow closely.

14. **Build and packaging**
   - The project is built with **CMake**, with SWIG, GTK-doc, and Sphinx/Doc tooling integrated.
   - Packaging metadata exists for distro builds (`libdnf.spec`, `tito`, `.copr`, `.packit.yaml`), which matters because this library is intended to be shipped as a system component.

15. **Diagramming takeaway**
   - The clean architectural picture is: **external repos/config/RPM DB → config/context → repo loading → sack/model → query/goal/solver → transaction/history/RPM integration**, with **bindings and plugins** as side interfaces and **tests/docs** as supporting subsystems.

Main entry points: [`libdnf/dnf-sack.cpp`](https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/dnf-sack.cpp) (Sack), [`libdnf/dnf-context.cpp`](https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/dnf-context.cpp) (Context), [`libdnf/hy-query.cpp`](https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/hy-query.cpp) (Hawkey API), [`tests`](https://github.com/rpm-software-management/libdnf/tree/dnf-4-master/tests) (Tests)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core engine"]
  node_dnf_context["Context<br/>orchestrator<br/>[dnf-context.cpp]"]
  node_conf["Config<br/>settings"]
  node_repo_loader["Repo loader<br/>ingestion"]
  node_repo[("Repo<br/>[Repo.cpp]")]
  node_crypto["Crypto<br/>trust checks<br/>[Crypto.cpp]"]
  node_sack[("Sack<br/>package universe<br/>[dnf-sack.cpp]")]
  node_query_selector["Query<br/>filtering<br/>[query.cpp]"]
  node_goal{{"Goal<br/>solver input<br/>[Goal.cpp]"}}
  node_pkg_identity["Identity<br/>nevra/reldep<br/>[nevra.cpp]"]
  node_rpm_bridge[("RPM bridge<br/>system bridge<br/>[dnf-rpmts.cpp]")]
  node_lock["Locking<br/>serialization<br/>[dnf-lock.cpp]"]
  node_keyring["Keyring<br/>trust store<br/>[dnf-keyring.cpp]"]
  node_transaction["Transaction<br/>history model<br/>[Transaction.cpp]"]
  node_tx_sql["History SQL<br/>schema/migrations<br/>[create_tables.sql]"]
  node_module["Modules<br/>modulemd"]
  node_advisory["Advisories<br/>errata metadata<br/>[advisory.cpp]"]
end

subgraph group_compat["Compatibility"]
  node_hawkey["Hawkey API<br/>compat layer<br/>[hy-query.cpp]"]
end

subgraph group_ext["Extensions"]
  node_bindings["Bindings<br/>swig/python/perl"]
  node_plugins["Plugins<br/>extension hooks"]
end

subgraph group_support["Support"]
  node_tests["Tests<br/>unit/integration"]
  node_fixtures[("Fixtures<br/>repo data")]
  node_docs["Docs<br/>documentation"]
end

node_dnf_context -->|"loads"| node_conf
node_dnf_context -->|"serializes"| node_lock
node_dnf_context -->|"orchestrates"| node_repo_loader
node_dnf_context -->|"assembles"| node_sack
node_repo_loader -->|"creates/loads"| node_repo
node_repo -->|"verifies"| node_crypto
node_repo -->|"ingests"| node_sack
node_sack -->|"exposes"| node_query_selector
node_query_selector -->|"matches"| node_pkg_identity
node_query_selector -->|"feeds"| node_goal
node_goal -->|"produces"| node_transaction
node_transaction -->|"persists"| node_tx_sql
node_transaction -->|"executes against"| node_rpm_bridge
node_rpm_bridge -->|"trusts"| node_keyring
node_sack -->|"includes"| node_module
node_sack -->|"includes"| node_advisory
node_hawkey -->|"wraps"| node_sack
node_hawkey -->|"wraps"| node_goal
node_bindings -->|"exposes"| node_hawkey
node_bindings -->|"exposes"| node_conf
node_plugins -->|"hooks into"| node_dnf_context
node_tests -->|"uses"| node_fixtures
node_tests -->|"verifies"| node_sack
node_tests -->|"verifies"| node_transaction
node_tests -->|"verifies"| node_hawkey
node_docs -->|"documents"| node_hawkey

click node_dnf_context "https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/dnf-context.cpp"
click node_conf "https://github.com/rpm-software-management/libdnf/tree/dnf-4-master/libdnf/conf"
click node_repo_loader "https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/dnf-repo-loader.cpp"
click node_repo "https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/repo/Repo.cpp"
click node_crypto "https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/repo/Crypto.cpp"
click node_sack "https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/dnf-sack.cpp"
click node_query_selector "https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/sack/query.cpp"
click node_goal "https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/goal/Goal.cpp"
click node_pkg_identity "https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/nevra.cpp"
click node_rpm_bridge "https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/dnf-rpmts.cpp"
click node_lock "https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/dnf-lock.cpp"
click node_keyring "https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/dnf-keyring.cpp"
click node_transaction "https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/transaction/Transaction.cpp"
click node_tx_sql "https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/transaction/sql/create_tables.sql"
click node_module "https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/module/ModulePackageContainer.cpp"
click node_advisory "https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/sack/advisory.cpp"
click node_hawkey "https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/hy-query.cpp"
click node_bindings "https://github.com/rpm-software-management/libdnf/tree/dnf-4-master/bindings/swig"
click node_plugins "https://github.com/rpm-software-management/libdnf/tree/dnf-4-master/plugins"
click node_tests "https://github.com/rpm-software-management/libdnf/tree/dnf-4-master/tests"
click node_fixtures "https://github.com/rpm-software-management/libdnf/tree/dnf-4-master/data/tests"
click node_docs "https://github.com/rpm-software-management/libdnf/tree/dnf-4-master/docs"

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_dnf_context,node_conf,node_repo_loader,node_repo,node_crypto,node_sack,node_query_selector,node_goal,node_pkg_identity,node_rpm_bridge,node_lock,node_keyring,node_transaction,node_tx_sql,node_module,node_advisory toneBlue
class node_hawkey toneAmber
class node_bindings,node_plugins toneMint
class node_tests,node_fixtures,node_docs toneRose
```

## Components

### Core engine

Configuration, repo ingestion, sack modeling, solving, and transactions.

- [Context](https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/dnf-context.cpp): orchestrator · Assembles config, locks, repos, sack, and transaction state for a run. · `libdnf/dnf-context.cpp`
- [Config](https://github.com/rpm-software-management/libdnf/tree/dnf-4-master/libdnf/conf): settings · Parses and stores main and repo configuration plus typed options. · `libdnf/conf`
- [Repo loader](https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/dnf-repo-loader.cpp): ingestion · Coordinates repository metadata loading and external repo access. · `libdnf/dnf-repo-loader.cpp`
- [Repo](https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/repo/Repo.cpp): repo boundary · Repository boundary for metadata, packages, signatures, and dependency splitting. · `libdnf/repo/Repo.cpp`
- [Crypto](https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/repo/Crypto.cpp): trust checks · Signature and GPG-related repository trust handling. · `libdnf/repo/Crypto.cpp`
- [Sack](https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/dnf-sack.cpp): package universe · In-memory package universe that holds solvables, advisories, and module context. · `libdnf/dnf-sack.cpp`
- [Query](https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/sack/query.cpp): filtering · Package querying and selection primitives over the sack. · `libdnf/sack/query.cpp`
- [Goal](https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/goal/Goal.cpp): solver input · Turns package intent into a dependency-solving goal and solution. · `libdnf/goal/Goal.cpp`
- [Identity](https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/nevra.cpp): nevra/reldep · Normalizes package identity and dependency expressions for matching. · `libdnf/nevra.cpp`
- [RPM bridge](https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/dnf-rpmts.cpp): system bridge · Connects libdnf to the installed RPM database and transaction set. · `libdnf/dnf-rpmts.cpp`
- [Locking](https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/dnf-lock.cpp): serialization · Serializes package-management operations to avoid concurrent conflicts. · `libdnf/dnf-lock.cpp`
- [Keyring](https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/dnf-keyring.cpp): trust store · Manages keys used to verify repository and package trust. · `libdnf/dnf-keyring.cpp`
- [Transaction](https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/transaction/Transaction.cpp): history model · Represents, merges, transforms, and persists package transactions. · `libdnf/transaction/Transaction.cpp`
- [History SQL](https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/transaction/sql/create_tables.sql): schema/migrations · SQLite schema and migrations for transaction history storage. · `libdnf/transaction/sql/create_tables.sql`
- [Modules](https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/module/ModulePackageContainer.cpp): modulemd · Modularity metadata and module package container support. · `libdnf/module/ModulePackageContainer.cpp`
- [Advisories](https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/sack/advisory.cpp): errata metadata · Security and advisory metadata carried alongside packages in the sack. · `libdnf/sack/advisory.cpp`

### Compatibility

Legacy hawkey API surface kept on top of libdnf internals.

- [Hawkey API](https://github.com/rpm-software-management/libdnf/blob/dnf-4-master/libdnf/hy-query.cpp): compat layer · Legacy hawkey-compatible API backed by libdnf internals. · `libdnf/hy-query.cpp`

### Extensions

Bindings and plugins that sit alongside the core engine.

- [Bindings](https://github.com/rpm-software-management/libdnf/tree/dnf-4-master/bindings/swig): swig/python/perl · Generated language bindings and handwritten Python glue. · `bindings/swig`
- [Plugins](https://github.com/rpm-software-management/libdnf/tree/dnf-4-master/plugins): extension hooks · Plugin boundary for example and RHSM integration code. · `plugins`

### Support

Tests, fixtures, docs, and translations.

- [Tests](https://github.com/rpm-software-management/libdnf/tree/dnf-4-master/tests): unit/integration · C++ and Python tests covering core behavior and compatibility APIs. · `tests`
- [Fixtures](https://github.com/rpm-software-management/libdnf/tree/dnf-4-master/data/tests): repo data · Repository metadata, RPMs, keys, module data, and other realistic test inputs. · `data/tests`
- [Docs](https://github.com/rpm-software-management/libdnf/tree/dnf-4-master/docs): documentation · API, project, and hawkey documentation. · `docs`

## Connections

- Context → Config: loads · Reads and applies runtime configuration.
- Context → Locking: serializes · Acquires operation locks before package actions.
- Context → Repo loader: orchestrates · Drives repository setup and refresh.
- Context → Sack: assembles · Builds the package universe for a run.
- Repo loader → Repo: creates/loads · Instantiates repos and loads metadata.
- Repo → Crypto: verifies · Checks repository trust and signatures.
- Repo → Sack: ingests · Populates the sack with repository solvables.
- Sack → Query: exposes · Provides query and selector access over packages.
- Query → Identity: matches · Uses normalized identity and dependency forms for filtering.
- Query → Goal: feeds · Selected packages become solver goals.
- Goal → Transaction: produces · Solver output is transformed into transaction items.
- Transaction → History SQL: persists · Stores history and supports migrations.
- Transaction → RPM bridge: executes against · Applies changes to the installed RPM system.
- RPM bridge → Keyring: trusts · Relies on key management for verification.
- Sack → Modules: includes · Carries modular metadata alongside packages.
- Sack → Advisories: includes · Carries advisory and errata context.
- Hawkey API → Sack: wraps · Legacy API is backed by the core sack model.
- Hawkey API → Goal: wraps · Legacy API delegates solving to goal objects.
- Bindings → Hawkey API: exposes · Python-facing compatibility surface and generated bindings.
- Bindings → Config: exposes · Bindings also surface core configuration APIs.
- Plugins → Context: hooks into · Plugins integrate with the main runtime context.
- Tests → Fixtures: uses · Tests consume realistic repo and RPM fixtures.
- Tests → Sack: verifies · Exercises package universe and query behavior.
- Tests → Transaction: verifies · Exercises transaction and migration behavior.
- Tests → Hawkey API: verifies · Covers the compatibility API surface.
- Docs → Hawkey API: documents · Includes hawkey-facing reference and tutorial material.
