How debian/apt works
Project Type and Purpose
• This is a large, modular C++‐based command-line package manager (“apt”) for Debian and derivatives.
• It exposes multiple client binaries (apt-get, apt-cache, apt, etc.) that sit on top of core libraries (libapt-pkg, libapt-inst).
• Responsibilities include: reading config, fetching and parsing package indices, resolving dependencies, downloading packages via pluggable “methods,” and invoking dpkg to install.
High-Level Architectural Components
a. CLI Frontends
• Binaries under cmdline/ and top-level executables (apt-get, apt-cache, apt, apt-ftparchive, etc.).
• Each binary parses arguments, loads configuration, then invokes core library APIs.
b. Core Libraries
• libapt-pkg: configuration, cache management, index parsing, dependency resolution (pkgDepCache, pkgProblemResolver), progress, JSON hooks.
• libapt-inst: interfaces to installation routines and dpkg (“pkgDpkgPm”).
c. Acquisition Subsystem
• AcquireWorker and AcquireMethod abstractions (“methods/”): HTTP, FTP, file, copy, cdrom, etc.
• A simple text-protocol between core and method backends.
• pluggable modules for different transport protocols.
d. Package Index Tools
• apt-ftparchive (ftparchive/): generates Packages, Sources, Release files.
e. Configuration & Localization
• Configuration readers under apt-pkg/aptconfiguration.* reading /etc/apt/apt.conf, overrides, environment.
• Internationalization pipelines (po/, translations in doc/).
f. Integration Points
• External dependency solvers (EDSP) & installation planners (EIPP) via protocol specs in doc/.
• Invocation of dpkg for actual package unpack/install.
• Interaction with underlying filesystem (private-cache, private-utils).
g. Test Harnesses
• Integration tests (test/integration/) using shell‐based framework.
• Unit tests (test/libapt/) using Google Test.
• Interactive helper tools (test/interactive-helper/).
Relationships & Data Flows
• User → CLI Frontend: command invocation.
• CLI → Core Library: passes parsed options.
• Core Library → Config Module: loads config files.
• Core Library → Cache & Index Parser: reads local package lists or generates indices via ftparchive.
• Core Library → Dependency Resolver: marks packages, runs pkgProblemResolver.
• Core Library → Acquire Subsystem: requests downloads; AcquireWorker dispatches to a specific method plugin.
• Acquire Method → Remote Service: HTTP/FTP/CDROM → retrieves .deb and index files.
• Core Library → libapt-inst: orchestrates package installation order, calls pkgDpkgPm → dpkg.
• Core Library → External Solvers/Planners (optional) via EDSP/EIPP protocols.
• Core Library → CLI: reports progress, errors, output.
Architectural Patterns & Principles
• Layered Architecture:
1. Presentation (CLI)
2. Application (Core Library: config, cache, resolver)
3. Service Layer (Acquisition subsystem)
4. Infrastructure (OS, dpkg, network)
• Plugin/Strategy Pattern for “methods” (download strategies).
• Dependency Inversion: core logic depends on abstract AcquireMethod interface.
• Separation of concerns: index generation (ftparchive), dependency solving, downloading, installation.
• Extensive use of CMake for build modularization, per-component targets.