The Module Architecture¶
At its core, Protostar is not a monolithic script; it is a polymorphic module resolution engine. The CLI parser's sole responsibility is translating a matrix of boolean flags (e.g., --python --astro --ruff) into an ordered array of instantiated module objects.
These modules act as autonomous, stateless plugins that interact strictly with the EnvironmentManifest. They do not know about each other, they do not read the host filesystem, and they do not execute system commands directly.
-
Polymorphic Contracts
Every toolchain component inherits from a base abstract class (
BootstrapModuleorPresetModule). This enforces a standardized API (pre_flightandbuild) that the Orchestrator can blindly iterate over. -
Topological Sequencing
Modules are loaded into the Orchestrator in a highly specific layering hierarchy (OS $\rightarrow$ IDE $\rightarrow$ Language $\rightarrow$ Tooling $\rightarrow$ Presets). This prevents dependency race conditions during AST compilation.
-
Strict Decoupling
A module only declares intent. Because modules never execute their own side-effects, testing a new language implementation simply requires asserting the state of the manifest in-memory.
The Layering Model¶
If multiple modules attempt to modify the same conceptual space (e.g., both the Python module and the Ruff module modifying IDE telemetry), the Orchestrator relies on sequence order to determine precedence.
graph TD
%% Styling
classDef layer fill:#1e293b,stroke:#3b82f6,stroke-width:2px,color:#fff,font-weight:bold;
classDef base fill:#0f172a,stroke:#00e5ff,stroke-width:3px,color:#fff;
classDef top fill:#334155,stroke:#f43f5e,stroke-width:2px,color:#fff;
subgraph Stack [ ]
direction BT
L1[1. System Layer]:::base
L2[2. Language Layer]:::layer
L3[3. Tooling Layer]:::layer
L4[4. Presets]:::top
%% Relationships showing precedence flow
L1 --> L2 --> L3 --> L4
end
%% Annotations
Note1[<b>Foundation</b><br/>Universal Hygiene] -- Initialized first --> L1
Note2[<b>Final Overrides</b><br/>Domain-specific wrappers] -- Loaded last --> L4
style Stack fill:transparent,stroke:#475569,stroke-dasharray: 5 5
The stack is resolved and executed in the following strict order:
1. System Layer¶
Configures universal environment artifacts and workspace hygiene. The deterministic SystemWorkspaceModule ignores standard host artifacts (.DS_Store), IDE directories (.idea/, .vscode/), and credentials (.env) across all initialized environments.
2. Language Layer¶
The core runtime environment (i.e., Python). This layer establishes the primary dependency managers (like uv or pip), injects the baseline project configuration files (like pyproject.toml), and conditionally evaluates the global configuration to inject IDE-specific setup (such as pointing VS Code to the generated Python interpreter).
3. Tooling Layer¶
Ancillary development tools that latch onto the language layer. Tools like ruff, mypy, or pre-commit evaluate the manifest to inject specific configuration blocks into the language layer's files.
4. Presets¶
Domain-specific wrappers. Presets are loaded last because they often act as "meta-modules," bundling libraries for specific use cases (like astrophysics data pipelines or machine learning environments) and overriding default tool configurations.
The Module Contract¶
When extending Protostar, developers implement specific methods dictated by the base classes. The Orchestrator guarantees these methods are called at the correct execution boundary during the lifecycle.
pre_flight()¶
The fail-fast perimeter. If a module requires external binaries (e.g., git, uv, cargo) to function, it must verify their presence in the system $PATH here. If the check fails, an exception is raised before any filesystem mutation occurs, protecting the workspace from partial scaffolding.
build(manifest: EnvironmentManifest)¶
The aggregation phase. Modules receive the mutable manifest object and use its API to register dependencies, directory structures, ignored files, and AST payloads.
# Example: A simplified tool implementation
class MyPyModule(BootstrapModule):
def build(self, manifest: EnvironmentManifest) -> None:
# Register the dependency
manifest.add_dev_dependency("mypy")
# Inject the AST payload for pyproject.toml
manifest.add_file_append("pyproject.toml", """
[tool.mypy]
strict = true
warn_return_any = true
""")
API Reference¶
Core Interface: BootstrapModule
protostar.modules.base.BootstrapModule ¶
Bases: ABC
Appends module-specific requirements to the environment manifest.
Source code in src/protostar/modules/base.py
cli_flags
class-attribute
¶
The CLI flags to trigger this module (e.g., ('-p', '--python')).
config_key
class-attribute
¶
The global configuration key used to evaluate if this module is active.
aliases
property
¶
Returns a list of configuration aliases that map to this module.
Used for dynamic resolution from the global configuration file.
collision_markers
property
¶
Returns a list of critical filesystem paths to evaluate for collisions during pre-flight.
Returns:
| Type | Description |
|---|---|
list[Path]
|
A list of Path objects representing critical configuration files or directories |
list[Path]
|
managed by this module. Defaults to an empty list. |
pre_flight ¶
Verifies system prerequisites before manifest building begins.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If a critical dependency (e.g., 'uv', 'cargo') is missing. |
build
abstractmethod
¶
Appends module-specific requirements to the environment manifest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifest
|
EnvironmentManifest
|
The centralized state object. |
required |
Core Interface: PresetModule
protostar.presets.base.PresetModule ¶
Bases: ABC
Appends module-specific requirements to the environment manifest.
Source code in src/protostar/presets/base.py
cli_flags
class-attribute
¶
The CLI flags to trigger this preset (e.g., ('-a', '--astro')).
default_dependencies
property
¶
Returns a list of default packages to inject for this preset.
default_directories
property
¶
Returns a list of default directories to scaffold for this preset.
default_ignores
property
¶
Returns a list of default VCS ignore patterns for this preset.
build ¶
Appends preset-specific dependencies and directories to the manifest.
Automatically applies configuration overrides if present. Otherwise, injects the default packages, directories, and ignores defined by the preset subclass.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifest
|
EnvironmentManifest
|
The centralized state object. |
required |