# rpm-software-management/dnf architecture

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

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

## Overview

##### Project type and purpose
- This repository implements Dandified YUM 4 (DNF4), a command-line package manager and Python API for RPM-based systems.
- It ties together Python modules (in the `dnf/` tree) with native libraries (libsolv, hawkey, librepo, libcomps) to resolve dependencies, retrieve metadata, and drive RPM transactions.

##### High-level architecture inferred from the file tree and README
- Top-level executables (`bin/dnf`, `bin/dnf-automatic`) launch the Python runtime.
- The `dnf/cli` package parses arguments, dispatches subcommands, handles output.
- The “core engine” (packages like `dnf/base.py`, `dnf/goal.py`, `dnf/query.py`, `dnf/transaction.py`) implements dependency resolution, transaction building, I/O orchestration.
- Subsystems:
- Configuration subsystem (`dnf/conf`) reads `/etc/dnf/*.conf`.
- Repository subsystem (`dnf/repo`, hawkey/librepo) fetches and caches metadata.
- Dependency solver (`dnf/rpm` + libsolv/hawkey).
- Comps group handling (libcomps + `dnf/comps.py`).
- Module support (`dnf/module`).
- Database & history (`dnf/db`, SQLite for transaction history).
- Plugin/callback mechanism (`dnf/plugin`, `dnf/callback.py`) for extensibility.
- External/native components:
- libsolv/hawkey: dependency solving engine
- librepo: HTTP downloads of RPM and metadata
- libcomps: comps group parsing
- RPM C library: package installation, signature checking
- Persistence & caches:
- RPM database (on-disk)
- DNF metadata cache (`~/.cache/dnf`)
- SQLite history DB

a. Front-end: CLI layer
- Executables (`bin/dnf-2`, `bin/dnf-3`, `dnf/cli/main.py`)
- Option parser, command dispatcher, shell/completion helpers
b. Core engine
- Dependency graph builder (`Goal`)
- Query interface (`Query`, `Subject`, `Selector`)
- Transaction manager (`Transaction`, `drpm`)
c. Configuration manager
- Reads `/etc/dnf/` + user overrides → produces settings object
d. Repository manager
- Uses librepo/hawkey → fetches metadata, exposes solvables
e. Dependency solver
- Calls into libsolv/hawkey via Python bindings in `dnf/rpm`
f. Comps & modules
- libcomps parser → group/module definitions → fed into the goal
g. Persistence
- SQLite for history (`dnf/db`)
- RPM database → via C-API bindings in `dnf/rpm/connection.py`
h. Plugin/callback pipeline
- Hooks at key events (pre-transaction, post-transaction, progress)
i. External services
- Remote repositories (HTTP/HTTPS)
- COPR or custom repos
j. Output/rendering
- Progress bars (`dnf/cli/progress.py`), formatters, completions

##### Architectural patterns & design principles
- Layered architecture: CLI → engine → external libs → persistence
- Adapter pattern: Python bindings wrap C/C++ libraries
- Observer/plugin pattern: `dnf/plugin`, `dnf/callback.py`
- Modular design: each subsystem in its own package (conf, cli, repo, rpm, module, automatic)
- Single responsibility: clear separation between parsing, solving, downloading, installing

##### Diagramming recommendations
- CLI → Engine
- Engine → Repo fetcher → Remote repos
- Engine → Solver → libsolv/hawkey
- Engine → Transaction → RPM C library → RPM database
- Engine → History subsystem → SQLite
- Engine → Plugin callbacks
- Python modules (e.g., light blue)
- Native libraries (e.g., orange)
- Rectangles for components/packages
- Clouds for external repositories
- **Labels**:
- Name each component (e.g., “CLI Dispatcher”, “Dependency Solver”)
- Call out key Python modules and native libs (librepo, libsolv, libcomps)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% CLI Layer
    subgraph "CLI Layer"
        binDNF["bin/dnf.in"]:::python
        binDNFAuto["bin/dnf-automatic.in"]:::python
        main["main.py"]:::python
        cliDispatcher["cli.py"]:::python
        optionParser["option_parser.py"]:::python
        subcommands["commands/*.py"]:::python
        completion["completion_helper.py.in"]:::python
        output["output.py"]:::python
        progressBar["progress.py"]:::python
    end

    %% Core Engine
    subgraph "Core Engine"
        base["base.py"]:::python
        goal["goal.py"]:::python
        query["query.py"]:::python
        transaction["transaction.py"]:::python
        transactionSR["transaction_sr.py"]:::python
        drpm["drpm.py"]:::python
        sack["sack.py"]:::python
    end

    %% Configuration Subsystem
    subgraph "Configuration"
        configReader["config.py"]:::python
        confRead["read.py"]:::python
        substitutions["substitutions.py"]:::python
    end

    %% Repository Manager
    subgraph "Repository Manager"
        repo["repo.py"]:::python
        repodict["repodict.py"]:::python
    end

    %% Dependency Solver
    subgraph "Dependency Solver"
        connection["connection.py"]:::python
        miscutils["miscutils.py"]:::python
    end

    %% Comps & Module Support
    subgraph "Comps & Module"
        comps["comps.py"]:::python
        moduleBase["module_base.py"]:::python
        moduleExceptions["exceptions.py"]:::python
        moduleInit["__init__.py"]:::python
    end

    %% Persistence & History
    subgraph "Persistence & History"
        historyDB["history.py"]:::python
        groupDB["group.py"]:::python
        rpmDB["connection.py"]:::python
        sqlite["SQLite History"]:::data
        rpmDatabase["RPM Database"]:::data
        metadataCache["DNF Metadata Cache"]:::data
    end

    %% Plugin / Callback
    subgraph "Plugin & Callbacks"
        pluginFramework["plugin.py"]:::python
        callbackHooks["callback.py"]:::python
    end

    %% Native Libraries
    subgraph "Native Libraries"
        libsolv["libsolv / hawkey"]:::native
        librepo["librepo"]:::native
        libcomps["libcomps"]:::native
        rpmCLib["RPM C Library"]:::native
    end

    %% External Services
    subgraph "External Repositories"
        remoteRepos["HTTP/HTTPS Repos"]:::external
    end

    %% Data Flows
    binDNF --> main
    binDNFAuto --> main
    main --> cliDispatcher
    cliDispatcher --> optionParser
    cliDispatcher --> subcommands
    cliDispatcher --> completion
    cliDispatcher --> output
    cliDispatcher --> progressBar

    cliDispatcher --> base
    base --> goal
    base --> query
    base --> transaction
    base --> sack

    goal --> connection
    goal --> comps
    goal --> moduleBase

    base --> repo
    repo --> librepo
    repo --> repodict
    librepo --> remoteRepos

    connection --> libsolv
    connection --> rpmCLib
    miscutils --> libsolv

    transaction --> rpmCLib
    transaction --> drpm

    drpm --> libcomps

    base --> configReader
    base --> confRead
    base --> substitutions

    base --> historyDB
    base --> groupDB
    historyDB --> sqlite
    groupDB --> sqlite

    rpmDB --> rpmCLib
    base --> rpmDB
    base --> metadataCache

    base --> pluginFramework
    pluginFramework --> callbackHooks

    %% Click events
    click binDNF "https://github.com/rpm-software-management/dnf/blob/master/bin/dnf.in"
    click binDNFAuto "https://github.com/rpm-software-management/dnf/blob/master/bin/dnf-automatic.in"
    click main "https://github.com/rpm-software-management/dnf/blob/master/dnf/cli/main.py"
    click cliDispatcher "https://github.com/rpm-software-management/dnf/blob/master/dnf/cli/cli.py"
    click optionParser "https://github.com/rpm-software-management/dnf/blob/master/dnf/cli/option_parser.py"
    click subcommands "https://github.com/rpm-software-management/dnf/tree/master/dnf/cli/commands"
    click completion "https://github.com/rpm-software-management/dnf/blob/master/dnf/cli/completion_helper.py.in"
    click output "https://github.com/rpm-software-management/dnf/blob/master/dnf/cli/output.py"
    click progressBar "https://github.com/rpm-software-management/dnf/blob/master/dnf/cli/progress.py"
    click base "https://github.com/rpm-software-management/dnf/blob/master/dnf/base.py"
    click goal "https://github.com/rpm-software-management/dnf/blob/master/dnf/goal.py"
    click query "https://github.com/rpm-software-management/dnf/blob/master/dnf/query.py"
    click transaction "https://github.com/rpm-software-management/dnf/blob/master/dnf/transaction.py"
    click transactionSR "https://github.com/rpm-software-management/dnf/blob/master/dnf/transaction_sr.py"
    click drpm "https://github.com/rpm-software-management/dnf/blob/master/dnf/drpm.py"
    click sack "https://github.com/rpm-software-management/dnf/blob/master/dnf/sack.py"
    click configReader "https://github.com/rpm-software-management/dnf/blob/master/dnf/conf/config.py"
    click confRead "https://github.com/rpm-software-management/dnf/blob/master/dnf/conf/read.py"
    click substitutions "https://github.com/rpm-software-management/dnf/blob/master/dnf/conf/substitutions.py"
    click repo "https://github.com/rpm-software-management/dnf/blob/master/dnf/repo.py"
    click repodict "https://github.com/rpm-software-management/dnf/blob/master/dnf/repodict.py"
    click connection "https://github.com/rpm-software-management/dnf/blob/master/dnf/rpm/connection.py"
    click miscutils "https://github.com/rpm-software-management/dnf/blob/master/dnf/rpm/miscutils.py"
    click comps "https://github.com/rpm-software-management/dnf/blob/master/dnf/comps.py"
    click moduleBase "https://github.com/rpm-software-management/dnf/blob/master/dnf/module/module_base.py"
    click moduleExceptions "https://github.com/rpm-software-management/dnf/blob/master/dnf/module/exceptions.py"
    click moduleInit "https://github.com/rpm-software-management/dnf/blob/master/dnf/module/__init__.py"
    click historyDB "https://github.com/rpm-software-management/dnf/blob/master/dnf/db/history.py"
    click groupDB "https://github.com/rpm-software-management/dnf/blob/master/dnf/db/group.py"
    click pluginFramework "https://github.com/rpm-software-management/dnf/blob/master/dnf/plugin.py"
    click callbackHooks "https://github.com/rpm-software-management/dnf/blob/master/dnf/callback.py"

    %% Styles
    classDef python fill:#D6EAF8,stroke:#3498DB,color:#154360
    classDef native fill:#FAD7A0,stroke:#D68910,color:#873600
    classDef data fill:#D5F5E3,stroke:#28B463,color:#145A32
    classDef external fill:#EAECEE,stroke:#ABB2B9,color:#566573
```
