How rpm-software-management/libdnf works
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: dnf-sack.cpp Sack · dnf-context.cpp Context · hy-query.cpp Hawkey API · tests Tests
Components 22
Core engine
Configuration, repo ingestion, sack modeling, solving, and transactions.
- Context · Assembles config, locks, repos, sack, and transaction state for a run.
libdnf/dnf-context.cpp - Config · Parses and stores main and repo configuration plus typed options.
libdnf/conf - Repo loader · Coordinates repository metadata loading and external repo access.
libdnf/dnf-repo-loader.cpp - Repo · Repository boundary for metadata, packages, signatures, and dependency splitting.
libdnf/repo/Repo.cpp - Crypto · Signature and GPG-related repository trust handling.
libdnf/repo/Crypto.cpp - Sack · In-memory package universe that holds solvables, advisories, and module context.
libdnf/dnf-sack.cpp - Query · Package querying and selection primitives over the sack.
libdnf/sack/query.cpp - Goal · Turns package intent into a dependency-solving goal and solution.
libdnf/goal/Goal.cpp - Identity · Normalizes package identity and dependency expressions for matching.
libdnf/nevra.cpp - RPM bridge · Connects libdnf to the installed RPM database and transaction set.
libdnf/dnf-rpmts.cpp - Locking · Serializes package-management operations to avoid concurrent conflicts.
libdnf/dnf-lock.cpp - Keyring · Manages keys used to verify repository and package trust.
libdnf/dnf-keyring.cpp - Transaction · Represents, merges, transforms, and persists package transactions.
libdnf/transaction/Transaction.cpp - History SQL · SQLite schema and migrations for transaction history storage.
libdnf/transaction/sql/create_tables.sql - Modules · Modularity metadata and module package container support.
libdnf/module/ModulePackageContainer.cpp - Advisories · 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 · Legacy hawkey-compatible API backed by libdnf internals.
libdnf/hy-query.cpp
Extensions
Bindings and plugins that sit alongside the core engine.
Connections 26
- 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.