# tanixlu/pyfuze architecture

> Architecture diagram of the GitHub repository tanixlu/pyfuze, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tanixlu/pyfuze
- Repository: https://github.com/tanixlu/pyfuze

## Overview

#### Purpose and Entry Points
pyfuze is a Python packaging CLI that turns a Python script or project directory into a single executable. Its public command entry is implemented in `src/pyfuze/__main__.py` and `src/pyfuze/cli.py`; package exports/version metadata are in `src/pyfuze/__init__.py`. The generated executable is driven at runtime by a compiled C launcher.

#### CLI Orchestration
`src/pyfuze/cli.py` is the primary control plane: it accepts the project input plus mode, entry point, dependency, inclusion/exclusion, extraction, environment, and Windows GUI options. It resolves either a single script or a folder project, selects one of Bundle, Online, or Portable packaging paths, and coordinates artifact creation. Shared Python-side filesystem/process logic belongs in `src/pyfuze/utils.py`.

#### Project Assembly Boundary
The packager constructs an application payload from the supplied project, its entry file, inferred Python/package sources, and explicit extra files. Dependency definitions can enter through requirements, `pyproject.toml`, and `uv.lock`; they are packaging-time inputs rather than application runtime code. Example project shape and intended folder-entry behavior are represented by `examples/complex/app.py`, `examples/complex/pyproject.toml`, and `examples/complex/uv.lock`.

#### Packaging Modes
Bundle is the default same-platform path: it embeds Python and resolved dependencies and extracts them before execution. Online builds a smaller cross-platform payload that bootstraps Python/dependencies at runtime through uv. Portable creates an extraction-free Cosmopolitan APE-style executable, restricted to pure-Python projects/dependencies and a fixed Cosmopolitan Python release. Mode dispatch and artifact generation are centered in `src/pyfuze/cli.py`.

#### Native Runtime Launcher
The embedded launcher is C code in `csrc/main.c`, with runtime configuration encoding/decoding in `csrc/config.c` and `csrc/config.h`. It is the execution boundary between the produced native executable and packaged Python payload: it determines runtime setup, extraction/working behavior, then starts the selected Python entry point. Native utility support is in `csrc/utils.c` and `csrc/utils.h`; `compile_csrc.sh` builds this launcher for inclusion in packaging output.

#### Runtime Filesystem and Environment Flow
For Bundle and Online artifacts, launch-time content is unpacked under the configured unzip path, with the default working directory `<unzip-path>/src`. The launcher exposes executable location and invocation directory through `PYFUZE_EXECUTABLE_PATH` and `PYFUZE_INVOKE_DIR`, allowing packaged applications to deliberately choose persistent or caller-relative paths. Windows GUI behavior is also passed from CLI packaging options into launcher/runtime behavior.

#### External Dependencies and Distribution
Cosmopolitan underpins Portable mode and executable portability; uv handles dependency resolution/installation and constrains Online mode’s platform coverage. Online runtime can retrieve uv, Python, and packages from public or user-specified installer/index mirrors. The Python package is built/published from `pyproject.toml`, while PyPI publication automation is defined in `.github/workflows/publish2pypi.yml`.

Main entry points: [`src/pyfuze/cli.py`](https://github.com/tanixlu/pyfuze/blob/main/src/pyfuze/cli.py) (Packaging orchestrator), [`csrc/main.c`](https://github.com/tanixlu/pyfuze/blob/main/csrc/main.c) (C launcher), [`examples/complex/pyproject.toml`](https://github.com/tanixlu/pyfuze/blob/main/examples/complex/pyproject.toml) (Dependency definitions), [`src/pyfuze/__main__.py`](https://github.com/tanixlu/pyfuze/blob/main/src/pyfuze/__main__.py) (CLI entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_python["Python packager"]
  node_entry["CLI entry<br/>Python module<br/>[__main__.py]"]
  node_cli["Packaging orchestrator<br/>Python CLI<br/>[cli.py]"]
  node_package["Package metadata<br/>Python package<br/>[__init__.py]"]
  node_py_utils["Shared utilities<br/>Python support<br/>[utils.py]"]
end

subgraph group_assembly["Payload assembly"]
  node_project_input["Project or script input<br/>source application"]
  node_dependency_inputs["Dependency definitions<br/>packaging input<br/>[pyproject.toml]"]
  node_example_lock["Example uv lock<br/>lockfile example<br/>[uv.lock]"]
  node_example_entry["Example app entry<br/>example application<br/>[app.py]"]
  node_payload["Application payload<br/>packaged content"]
  node_bundle["Bundle mode<br/>packaging mode<br/>[cli.py]"]
  node_online["Online mode<br/>packaging mode<br/>[cli.py]"]
  node_portable["Portable mode<br/>packaging mode<br/>[cli.py]"]
end

subgraph group_runtime["Generated runtime"]
  node_artifact{{"Generated executable<br/>distribution artifact"}}
  node_launcher["C launcher<br/>native runtime<br/>[main.c]"]
  node_launcher_config["Launcher configuration<br/>C runtime config<br/>[config.c]"]
  node_launcher_utils["Native utilities<br/>C support<br/>[utils.c]"]
  node_launcher_build["Launcher build<br/>build script<br/>[compile_csrc.sh]"]
  node_runtime_fs[("Extracted runtime workspace<br/>runtime filesystem")]
end

subgraph group_external["External tooling"]
  node_uv["uv<br/>external resolver"]
  node_cosmopolitan["Cosmopolitan<br/>external runtime"]
  node_publication["PyPI publication<br/>release automation<br/>[publish2pypi.yml]"]
  node_build_metadata["Build metadata<br/>Python project metadata<br/>[pyproject.toml]"]
end

node_entry -->|"invokes"| node_cli
node_cli -->|"uses"| node_py_utils
node_project_input -->|"sources and entry"| node_payload
node_example_entry -.->|"illustrates"| node_project_input
node_dependency_inputs -->|"defines dependencies"| node_payload
node_example_lock -.->|"illustrates lock input"| node_dependency_inputs
node_cli -->|"assembles"| node_payload
node_cli -->|"dispatches"| node_bundle
node_cli -->|"dispatches"| node_online
node_cli -->|"dispatches"| node_portable
node_payload -->|"embedded content"| node_bundle
node_payload -->|"bootstrap payload"| node_online
node_payload -->|"pure-Python content"| node_portable
node_bundle -->|"produces"| node_artifact
node_online -->|"produces"| node_artifact
node_portable -->|"produces"| node_artifact
node_launcher_build -->|"compiles"| node_launcher
node_launcher_config -->|"runtime options"| node_launcher
node_launcher_utils -->|"supports"| node_launcher
node_launcher -->|"embedded in"| node_artifact
node_artifact -->|"Bundle/Online unpack"| node_runtime_fs
node_launcher -->|"sets workspace and env"| node_runtime_fs
node_uv -->|"resolves"| node_dependency_inputs
node_uv -->|"runtime bootstrap"| node_online
node_cosmopolitan -->|"fixed runtime"| node_portable
node_build_metadata -->|"package release"| node_publication

click node_entry "https://github.com/tanixlu/pyfuze/blob/main/src/pyfuze/__main__.py"
click node_cli "https://github.com/tanixlu/pyfuze/blob/main/src/pyfuze/cli.py"
click node_package "https://github.com/tanixlu/pyfuze/blob/main/src/pyfuze/__init__.py"
click node_py_utils "https://github.com/tanixlu/pyfuze/blob/main/src/pyfuze/utils.py"
click node_dependency_inputs "https://github.com/tanixlu/pyfuze/blob/main/examples/complex/pyproject.toml"
click node_example_lock "https://github.com/tanixlu/pyfuze/blob/main/examples/complex/uv.lock"
click node_example_entry "https://github.com/tanixlu/pyfuze/blob/main/examples/complex/app.py"
click node_bundle "https://github.com/tanixlu/pyfuze/blob/main/src/pyfuze/cli.py"
click node_online "https://github.com/tanixlu/pyfuze/blob/main/src/pyfuze/cli.py"
click node_portable "https://github.com/tanixlu/pyfuze/blob/main/src/pyfuze/cli.py"
click node_launcher "https://github.com/tanixlu/pyfuze/blob/main/csrc/main.c"
click node_launcher_config "https://github.com/tanixlu/pyfuze/blob/main/csrc/config.c"
click node_launcher_utils "https://github.com/tanixlu/pyfuze/blob/main/csrc/utils.c"
click node_launcher_build "https://github.com/tanixlu/pyfuze/blob/main/compile_csrc.sh"
click node_publication "https://github.com/tanixlu/pyfuze/blob/main/.github/workflows/publish2pypi.yml"
click node_build_metadata "https://github.com/tanixlu/pyfuze/blob/main/pyproject.toml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entry,node_cli,node_package,node_py_utils toneBlue
class node_project_input,node_dependency_inputs,node_example_lock,node_example_entry,node_payload,node_bundle,node_online,node_portable toneAmber
class node_artifact,node_launcher,node_launcher_config,node_launcher_utils,node_launcher_build,node_runtime_fs toneMint
class node_uv,node_cosmopolitan,node_publication,node_build_metadata toneRose
```

## Components

### Python packager

- [CLI entry](https://github.com/tanixlu/pyfuze/blob/main/src/pyfuze/__main__.py): Python module · `src/pyfuze/__main__.py`
- [Packaging orchestrator](https://github.com/tanixlu/pyfuze/blob/main/src/pyfuze/cli.py): Python CLI · Selects mode, resolves project input, and produces artifacts. · `src/pyfuze/cli.py`
- [Package metadata](https://github.com/tanixlu/pyfuze/blob/main/src/pyfuze/__init__.py): Python package · `src/pyfuze/__init__.py`
- [Shared utilities](https://github.com/tanixlu/pyfuze/blob/main/src/pyfuze/utils.py): Python support · Filesystem and process operations used during packaging. · `src/pyfuze/utils.py`

### Payload assembly

- **Project or script input**: source application · A single script or directory project with a selected entry file.
- [Dependency definitions](https://github.com/tanixlu/pyfuze/blob/main/examples/complex/pyproject.toml): packaging input · Requirements, pyproject metadata, and uv lock data. · `examples/complex/pyproject.toml`
- [Example uv lock](https://github.com/tanixlu/pyfuze/blob/main/examples/complex/uv.lock): lockfile example · Represents locked dependency input for folder projects. · `examples/complex/uv.lock`
- [Example app entry](https://github.com/tanixlu/pyfuze/blob/main/examples/complex/app.py): example application · `examples/complex/app.py`
- **Application payload**: packaged content · Entry source, inferred packages, dependencies, and explicit included files.
- [Bundle mode](https://github.com/tanixlu/pyfuze/blob/main/src/pyfuze/cli.py): packaging mode · Embeds Python and dependencies for same-platform extraction. · `src/pyfuze/cli.py`
- [Online mode](https://github.com/tanixlu/pyfuze/blob/main/src/pyfuze/cli.py): packaging mode · Produces a small payload that bootstraps its runtime through uv. · `src/pyfuze/cli.py`
- [Portable mode](https://github.com/tanixlu/pyfuze/blob/main/src/pyfuze/cli.py): packaging mode · Builds an extraction-free pure-Python Cosmopolitan executable. · `src/pyfuze/cli.py`

### Generated runtime

- **Generated executable**: distribution artifact
- [C launcher](https://github.com/tanixlu/pyfuze/blob/main/csrc/main.c): native runtime · Configures execution and starts the packaged Python entry point. · `csrc/main.c`
- [Launcher configuration](https://github.com/tanixlu/pyfuze/blob/main/csrc/config.c): C runtime config · Encodes packaging options for launcher behavior. · `csrc/config.c`
- [Native utilities](https://github.com/tanixlu/pyfuze/blob/main/csrc/utils.c): C support · `csrc/utils.c`
- [Launcher build](https://github.com/tanixlu/pyfuze/blob/main/compile_csrc.sh): build script · Compiles the native launcher included in packaging output. · `compile_csrc.sh`
- **Extracted runtime workspace**: runtime filesystem · Bundle and Online unpack under the unzip path; default workdir is src.

### External tooling

- **uv**: external resolver · Resolves build dependencies and installs Online runtime components.
- **Cosmopolitan**: external runtime · Provides the fixed APE-style Python runtime for Portable mode.
- [PyPI publication](https://github.com/tanixlu/pyfuze/blob/main/.github/workflows/publish2pypi.yml): release automation · `.github/workflows/publish2pypi.yml`
- [Build metadata](https://github.com/tanixlu/pyfuze/blob/main/pyproject.toml): Python project metadata · Defines Python package build and publication inputs. · `pyproject.toml`

## Connections

- CLI entry → Packaging orchestrator: invokes
- Packaging orchestrator → Shared utilities: uses
- Project or script input → Application payload: sources and entry
- Example app entry → Project or script input: illustrates
- Dependency definitions → Application payload: defines dependencies
- Example uv lock → Dependency definitions: illustrates lock input
- Packaging orchestrator → Application payload: assembles
- Packaging orchestrator → Bundle mode: dispatches
- Packaging orchestrator → Online mode: dispatches
- Packaging orchestrator → Portable mode: dispatches
- Application payload → Bundle mode: embedded content
- Application payload → Online mode: bootstrap payload
- Application payload → Portable mode: pure-Python content
- Bundle mode → Generated executable: produces
- Online mode → Generated executable: produces
- Portable mode → Generated executable: produces
- Launcher build → C launcher: compiles
- Launcher configuration → C launcher: runtime options
- Native utilities → C launcher: supports
- C launcher → Generated executable: embedded in
- Generated executable → Extracted runtime workspace: Bundle/Online unpack
- C launcher → Extracted runtime workspace: sets workspace and env · Exposes executable and invocation paths to the application.
- uv → Dependency definitions: resolves
- uv → Online mode: runtime bootstrap
- Cosmopolitan → Portable mode: fixed runtime
- Build metadata → PyPI publication: package release
