Skip to content

Commit ecdf478

Browse files
docs: add architecture overview docs
Also add an AGENTS.md rule to keep the docs in sync when the architecture changes. Closes: #1247 Co-Authored-By: Claude <claude@anthropic.com> Signed-off-by: Lalatendu Mohanty <lmohanty@redhat.com>
1 parent fdf55b3 commit ecdf478

7 files changed

Lines changed: 629 additions & 0 deletions

‎AGENTS.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ Look at these before writing code:
102102

103103
- Use single backticks around function and class names in markdown (e.g. `req_ctxvar_context()`, `WorkContext`), double backticks in .rst (reStructuredText)
104104
- Use Sphinx `versionadded`, `versionremoved`, `versionchanged` directives for user-facing changes (get next version from last git tag)
105+
- When code changes affect the architecture described in `docs/concepts/`, update the relevant doc:
106+
- `architecture-overview.rst` — major subsystems, data flow, extension points, key data structures
107+
- `bootstrapper-architecture.rst` — phase pipeline, class hierarchy, bootstrapper-phase interaction
108+
- `resolver-architecture.rst` — resolution strategies, provider hierarchy, version filtering
109+
- `hooks-and-overrides.rst` — override hook points, global hooks, plugin discovery
110+
- `package-settings.rst` — settings loading flow, merge order, PackageBuildInfo facade
105111

106112
## Commit Messages
107113

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
Architecture Overview
2+
=====================
3+
4+
Fromager rebuilds complete dependency trees of Python wheels from
5+
source. This document maps the major subsystems and how they connect.
6+
7+
.. seealso::
8+
9+
:doc:`bootstrap-vs-build` explains the two operating modes.
10+
:doc:`bootstrapper-architecture` details the bootstrap engine.
11+
:doc:`resolver-architecture` covers version resolution.
12+
:doc:`hooks-and-overrides` describes the two plugin systems.
13+
:doc:`package-settings` explains the settings layering.
14+
15+
Major Subsystems
16+
----------------
17+
18+
.. code-block:: text
19+
20+
┌───────────────────────────────────────────────────────┐
21+
│ CLI & Context │
22+
│ command parsing, WorkContext, settings │
23+
└───────────────────────────┬───────────────────────────┘
24+
│
25+
▼
26+
┌───────────────────────────────────────────────────────┐
27+
│ Bootstrap Engine │
28+
│ iterative DFS loop over phase pipeline │
29+
│ │
30+
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
31+
│ │ Resolution │ │ Source │ │ Build │ │
32+
│ │ PyPI, graph │ │ Acquisition │ │ System │ │
33+
│ │ git URLs │ │ download, │ │ isolated │ │
34+
│ │ │ │ patch, Rust │ │ envs, │ │
35+
│ │ │ │ vendor │ │ wheels │ │
36+
│ └─────────────┘ └─────────────┘ └─────────────┘ │
37+
└───────────────────────────┬───────────────────────────┘
38+
│
39+
┌────────────────┴────────────────┐
40+
▼ ▼
41+
┌──────────────────┐ ┌──────────────────┐
42+
│ Per-Package │ │ Global Hooks │
43+
│ Overrides │ │ post_bootstrap, │
44+
│ │ │ post_build │
45+
└──────────────────┘ └──────────────────┘
46+
47+
The **bootstrap engine** orchestrates the other subsystems. For each
48+
package it resolves a version, downloads the source, builds a wheel,
49+
and recurses into dependencies. **Resolution**, **source acquisition**,
50+
and **build** are called as needed during each phase of the pipeline.
51+
52+
**Extension points** intercept the pipeline at specific steps, allowing
53+
per-package overrides (e.g. custom download logic) and global hooks
54+
(e.g. post-build notifications).
55+
56+
Data Flow
57+
---------
58+
59+
A ``fromager bootstrap`` invocation flows through the subsystems in
60+
this order:
61+
62+
.. code-block:: text
63+
64+
requirements.txt
65+
│
66+
▼
67+
┌─ CLI & Context ───────────────────────────────────────┐
68+
│ parse args, load settings, create WorkContext │
69+
└───────────────────────────┬───────────────────────────┘
70+
│
71+
▼
72+
┌─ Bootstrap Engine (iterative DFS) ────────────────────┐
73+
│ │
74+
│ ┌─────────────┐ ┌─────────────┐ │
75+
│ │ Resolve │──►│ Download │ │
76+
│ │ version │ │ source │ │
77+
│ └─────────────┘ └──────┬──────┘ │
78+
│ │ │
79+
│ ▼ │
80+
│ ┌─────────────┐ ┌─────────────┐ │
81+
│ │ Extract & │◄──│ Build │ │
82+
│ │ recurse │ │ wheel │ │
83+
│ │ into deps │ │ │ │
84+
│ └─────────────┘ └─────────────┘ │
85+
│ │
86+
└───────────────────────────┬───────────────────────────┘
87+
│
88+
▼
89+
┌── Outputs ──┐
90+
│ graph.json │
91+
│ build-order │
92+
│ wheels/ │
93+
│ constraints │
94+
└─────────────┘
95+
96+
The ``build`` command uses the same source acquisition and build
97+
subsystems but skips resolution and recursion -- it compiles a
98+
single package given a name, version, and source URL.
99+
100+
Extension Points
101+
----------------
102+
103+
Fromager has two plugin systems:
104+
105+
.. list-table::
106+
:header-rows: 1
107+
:widths: 25 35 40
108+
109+
* - System
110+
- Scope
111+
- When it fires
112+
* - **Per-package overrides**
113+
- One package
114+
- At each pipeline step (download, build sdist, build wheel,
115+
dependency extraction, etc.)
116+
* - **Global hooks**
117+
- All packages
118+
- After specific events (``post_bootstrap``, ``post_build``,
119+
``prebuilt_wheel``)
120+
121+
Per-package overrides replace the default implementation of a step for
122+
a specific package. Global hooks run in addition to the default logic
123+
for every package. See :doc:`hooks-and-overrides` for the full
124+
breakdown.
125+
126+
Key Data Structures
127+
-------------------
128+
129+
Four data structures flow between subsystems:
130+
131+
.. list-table::
132+
:header-rows: 1
133+
:widths: 30 70
134+
135+
* - Structure
136+
- Role
137+
* - ``WorkContext``
138+
- Central configuration and state: directory paths, constraints,
139+
dependency graph, settings, and variant info. Passed to every
140+
subsystem.
141+
* - ``DependencyGraph``
142+
- In-memory directed graph of all resolved dependencies.
143+
Serialized to ``graph.json``. Thread-safe.
144+
* - ``PackageBuildInfo``
145+
- Per-package build configuration: environment variables, patches,
146+
resolver settings, and build options. Derived from settings
147+
files.
148+
* - ``BuildEnvironment``
149+
- Isolated virtual environment for building one package. Created
150+
per source build, cleaned up after completion.
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
Bootstrapper Architecture
2+
=========================
3+
4+
The bootstrap command uses an iterative depth-first loop to resolve and
5+
build an entire dependency tree. This document describes the phase
6+
pipeline, class hierarchy, and interaction model at a high level.
7+
8+
.. seealso::
9+
10+
:doc:`architecture-overview` maps the major subsystems.
11+
:doc:`bootstrap-vs-build` covers the difference between bootstrap and
12+
build modes.
13+
14+
Bootstrap Phase Flow
15+
--------------------
16+
17+
Every package passes through a sequence of phases. Source packages
18+
traverse the full pipeline; prebuilt wheels skip the build phases.
19+
20+
.. code-block:: text
21+
22+
RESOLVE ──► START ──► PREPARE_SOURCE ─┬─► PREPARE_BUILD ──► BUILD ─┐
23+
│ │ │
24+
│ (prebuilt)└────────────────────────────┤
25+
│ │
26+
│ ┌────────────────────────────────┘
27+
│ ▼
28+
│ PROCESS_INSTALL_DEPS ──► COMPLETE
29+
│
30+
(already seen) ──► drop
31+
32+
Each phase returns a list of new items to push onto the work stack.
33+
Dependency-discovery phases (``PREPARE_SOURCE``, ``PREPARE_BUILD``,
34+
``PROCESS_INSTALL_DEPS``) also emit ``RESOLVE`` items for newly
35+
discovered dependencies, which drives the recursive traversal.
36+
37+
Phase Class Hierarchy
38+
---------------------
39+
40+
All phases inherit from the ``Phase`` abstract base class, which defines
41+
the contract every phase must satisfy:
42+
43+
- ``run(bt)`` — execute the phase logic; return new items for the stack.
44+
- ``background_work(bt)`` — optionally return a callable for background
45+
I/O (used by ``Resolve`` and ``PrepareSource``).
46+
- ``requires_exclusive_run`` — return ``True`` to drain the thread pool
47+
before running (used by ``Build`` for exclusive builds).
48+
49+
.. list-table::
50+
:header-rows: 1
51+
:widths: 25 75
52+
53+
* - Phase
54+
- Role
55+
* - ``Resolve``
56+
- Resolve available versions; fan out one ``Start`` per version
57+
* - ``Start``
58+
- Add to dependency graph; deduplicate already-seen packages
59+
* - ``PrepareSource``
60+
- Download source or prebuilt wheel; read build-system deps
61+
* - ``PrepareBuild``
62+
- Install build-system deps; discover backend and sdist deps
63+
* - ``Build``
64+
- Build sdist and/or wheel; update the local mirror
65+
* - ``ProcessInstallDeps``
66+
- Run post-bootstrap hooks; extract install deps; record build order
67+
* - ``Complete``
68+
- Clean up build directories (terminal phase)
69+
70+
Each phase wraps a ``WorkItem`` dataclass that accumulates per-package
71+
state (resolved version, build environment, build result, etc.) as it
72+
moves through the pipeline.
73+
74+
Bootstrapper and Phase Interaction
75+
----------------------------------
76+
77+
The ``Bootstrapper`` class owns the work stack and thread pool. It runs
78+
an iterative DFS loop:
79+
80+
.. code-block:: text
81+
82+
┌─────────────────────────────────────────────────────┐
83+
│ Bootstrapper Loop │
84+
│ │
85+
│ while stack: │
86+
│ item = stack.pop() │
87+
│ │
88+
│ if item.requires_exclusive_run: │
89+
│ drain thread pool │
90+
│ │
91+
│ new_items = item.run(self) │
92+
│ │
93+
│ for each new_item in new_items: │
94+
│ stack.push(new_item) │
95+
└─────────────────────────────────────────────────────┘
96+
97+
The ``Bootstrapper`` provides services that phases call back into during
98+
``run()``: dependency graph updates, seen-set tracking, build-order
99+
recording, and work-item creation for discovered dependencies.
100+
101+
Some phases (``Resolve`` and ``PrepareSource``) perform background I/O
102+
in a thread pool. When new items are pushed onto the stack, the
103+
``Bootstrapper`` submits their ``background_work()`` immediately so I/O
104+
overlaps with the main thread processing other items. Each phase is
105+
responsible for blocking on its own ``bg_future`` inside ``run()`` when
106+
it needs the result. Other phases run entirely on the main thread.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
Hooks and Overrides
2+
===================
3+
4+
Fromager has two plugin systems that serve different purposes:
5+
**per-package overrides** replace default behavior for a specific
6+
package, while **global hooks** broadcast notifications after events
7+
for every package.
8+
9+
.. seealso::
10+
11+
:doc:`architecture-overview` maps the major subsystems.
12+
:doc:`/reference/hooks` documents each override hook's arguments and
13+
return values. :doc:`/customization` covers global hooks with code
14+
examples.
15+
16+
Comparison
17+
----------
18+
19+
.. list-table::
20+
:header-rows: 1
21+
:widths: 20 40 40
22+
23+
* - Aspect
24+
- Per-Package Overrides
25+
- Global Hooks
26+
* - **Scope**
27+
- One named package
28+
- Every package
29+
* - **Cardinality**
30+
- At most one override module per package
31+
- Multiple plugins per hook
32+
* - **Semantics**
33+
- Replaces the default implementation
34+
- Runs in addition to the default
35+
* - **Return value**
36+
- Used by the caller
37+
- None (fire-and-forget)
38+
* - **Typical use**
39+
- Custom download, build, or resolution logic
40+
- Publishing wheels, validation, logging
41+
42+
Per-Package Overrides
43+
---------------------
44+
45+
An override module provides alternative implementations for specific
46+
build steps. Fromager looks up the module by the canonicalized package
47+
name. If the module defines the requested method, it is called instead
48+
of the default; otherwise the default runs.
49+
50+
Override hooks cover resolution, source acquisition, building,
51+
dependency extraction, and build environment customization. Third-party
52+
packages register overrides via the ``fromager.project_overrides``
53+
entry-point group in their ``pyproject.toml``, mapping a package name to
54+
a Python module.
55+
56+
See :doc:`/reference/hooks` for the complete list of hooks and their
57+
arguments.
58+
59+
Global Hooks
60+
------------
61+
62+
Global hooks are event callbacks that fire for every package. All
63+
registered plugins for a hook are called sequentially. They cannot
64+
alter the build result — they are purely side-effecting notifications.
65+
66+
.. list-table::
67+
:header-rows: 1
68+
:widths: 25 75
69+
70+
* - Hook
71+
- When it fires
72+
* - ``post_build``
73+
- After a wheel is built from source (not for prebuilt wheels)
74+
* - ``prebuilt_wheel``
75+
- After a prebuilt wheel is downloaded (not built from source)
76+
* - ``post_bootstrap``
77+
- After a package is bootstrapped, before its install dependencies
78+
are processed
79+
80+
Third-party packages register hooks via the ``fromager.hooks``
81+
entry-point group in their ``pyproject.toml``, mapping a hook name to
82+
a callable.
83+
84+
See :doc:`/customization` for examples and argument details.

‎docs/concepts/index.rst‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,23 @@ Key Topics
88

99
These guides explain the fundamental concepts and design principles behind fromager:
1010

11+
* **Architecture Overview** - Major subsystems, data flow, extension points, and key data structures
1112
* **Bootstrap vs Build Modes** - Understand the difference between recursive discovery (bootstrap) and single-package builds (build)
13+
* **Bootstrapper Architecture** - Phase pipeline, class hierarchy, and interaction model of the bootstrap engine
14+
* **Resolver Architecture** - Resolution strategies, provider hierarchy, version filtering, and per-package configuration
15+
* **Hooks and Overrides** - The two plugin systems: per-package overrides and global hooks
16+
* **Package Settings** - Settings loading, merge order, and the ``PackageBuildInfo`` facade
1217
* **Dependency Types** - Learn about build-system, build-backend, build-sdist, and install dependencies
1318

1419
.. toctree::
1520
:maxdepth: 1
1621

22+
architecture-overview
1723
bootstrap-vs-build
24+
bootstrapper-architecture
25+
resolver-architecture
26+
hooks-and-overrides
27+
package-settings
1828
dependencies
1929

2030
Related Practical Guides

0 commit comments

Comments
 (0)