# sigoden/upt architecture

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

- Interactive diagram: https://gitdiagram.com/sigoden/upt
- Repository: https://github.com/sigoden/upt

## Overview

1. **Repository purpose**
   - `upt` is a single Rust CLI binary that acts as a cross-platform wrapper over native package managers.
   - The core architectural idea is not to implement package management itself, but to translate a unified command like `upt install pkg` into the correct platform/tool-specific command.

2. **Top-level shape**
   - This is a small, self-contained Rust crate with one binary entrypoint and a library split across a handful of modules.
   - There are no external backend services, databases, or web components; the main runtime dependency is the host OS and whichever package manager it launches.

3. **CLI entrypoint**
   - `src/main.rs` is the executable entrypoint.
   - `src/lib.rs` likely exposes the shared application logic so the same command routing and resolution can be reused cleanly from `main`.
   - The CLI surface is centered around package operations such as install, remove, upgrade, search, info, update, and list.

4. **Command interpretation and dispatch**
   - `src/action.rs` is the command-routing layer.
   - It maps the user’s requested action to an abstract operation, then chooses the concrete syntax for the selected package tool.
   - This is the key translation boundary between “unified UPT commands” and “native package-manager commands.”

5. **Task execution model**
   - `src/task.rs` likely represents a resolved package-manager invocation: the selected tool, the operation, and the final argument list.
   - This module is the execution boundary where high-level intent becomes a process spawn against the system package manager.
   - From an architecture perspective, this is where the repo stops being a parser and becomes a launcher.

6. **Vendor / platform detection**
   - `src/vendor.rs` is the platform-detection subsystem.
   - It determines the current OS/distribution family and selects a default tool based on the supported matrix in the README.
   - It also likely handles the ordering rules for platforms with multiple candidates, and the `UPT_TOOL` override that forces a specific backend.

7. **Utilities and shared helpers**
   - `src/utils.rs` contains cross-cutting helpers used by the resolver and executor layers.
   - In a project like this, that usually includes OS probing, string handling, command lookup, environment access, and process-related convenience functions.

8. **Error handling**
   - `src/error.rs` defines the crate’s error type and user-facing failures.
   - Likely failure points include unsupported OS/tool combinations, missing executables, invalid CLI usage, and subprocess execution errors.
   - This keeps the CLI experience consistent when resolution or command launch fails.

9. **Macro support**
   - `src/macros.rs` suggests the crate uses macros to reduce repetitive boilerplate.
   - In a command-dispatch tool, that commonly means helpers for defining repeated tool mappings or error-conversion patterns.

10. **Core data flow**
   - Input starts as CLI arguments.
   - The action layer interprets the requested operation.
   - Vendor detection chooses the package manager, unless `UPT_TOOL` overrides it.
   - Task construction produces the exact command/arguments.
   - The tool is then executed on the host system and its output/error code is propagated back to the user.

11. **Configuration and precedence**
   - The only explicit user configuration called out in the README is `UPT_TOOL`.
   - That environment variable acts as a hard override over automatic OS/tool selection, which is important for architecture diagrams because it creates a second control path into tool resolution.

12. **Packaging and release pipeline**
   - `.github/workflows/ci.yml` handles validation/building in CI.
   - `.github/workflows/release.yml` handles publishing or release artifact generation.
   - `install.sh` supports shell-based installation on macOS/Linux, while releases and `cargo install` provide the other distribution paths.

13. **Boundary of responsibility**
   - `upt` does not maintain package indexes, install packages itself, or normalize package metadata.
   - It is a thin compatibility and ergonomics layer over native package managers, so the main architectural boundary is “tool selection + command translation + process execution.”

14. **What to show in an architecture diagram**
   - A single CLI client at the top.
   - A resolution layer in the middle with action parsing and vendor detection.
   - A process-execution layer at the bottom that shells out to native tools like `apt`, `brew`, `pacman`, `dnf`, `zypper`, `winget`, etc.
   - A side input from the environment (`UPT_TOOL`) and a side output to the host OS/package-manager process.

Main entry points: [`src/action.rs`](https://github.com/sigoden/upt/blob/main/src/action.rs) (actions), [`src/vendor.rs`](https://github.com/sigoden/upt/blob/main/src/vendor.rs) (vendor), [`src/task.rs`](https://github.com/sigoden/upt/blob/main/src/task.rs) (task), [`src/lib.rs`](https://github.com/sigoden/upt/blob/main/src/lib.rs) (lib)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_cli["CLI"]
  node_n_main(("main<br/>binary entrypoint<br/>[main.rs]"))
  node_n_lib["lib<br/>shared crate API<br/>[lib.rs]"]
end

subgraph group_grp_core["Resolution"]
  node_n_action["actions<br/>command router<br/>[action.rs]"]
  node_n_vendor["vendor<br/>platform detector<br/>[vendor.rs]"]
  node_n_error{{"errors<br/>error model<br/>[error.rs]"}}
  node_n_utils["utils<br/>shared helpers<br/>[utils.rs]"]
  node_n_macros["macros<br/>boilerplate helpers<br/>[macros.rs]"]
  node_n_env(("UPT_TOOL<br/>env override"))
end

subgraph group_grp_exec["Execution"]
  node_n_task["task<br/>invocation model<br/>[task.rs]"]
  node_n_pm[("pkg managers<br/>native backends")]
  node_n_os(("host OS<br/>runtime platform"))
end

subgraph group_grp_dist["Delivery"]
  node_n_ci["CI<br/>workflow<br/>[ci.yml]"]
  node_n_release["release<br/>workflow<br/>[release.yml]"]
  node_n_install["install.sh<br/>installer script<br/>[install.sh]"]
end

node_n_main -->|"calls"| node_n_lib
node_n_lib -->|"routes"| node_n_action
node_n_action -->|"resolves"| node_n_vendor
node_n_vendor -.->|"overridden by"| node_n_env
node_n_vendor -->|"inspects"| node_n_os
node_n_action -->|"builds"| node_n_task
node_n_task -->|"spawns"| node_n_pm
node_n_task -->|"reports"| node_n_error
node_n_action -->|"rejects"| node_n_error
node_n_utils -.->|"supports"| node_n_vendor
node_n_utils -.->|"supports"| node_n_task
node_n_macros -.->|"generates"| node_n_action
node_n_macros -.->|"generates"| node_n_error
node_n_ci -->|"validates"| node_n_lib
node_n_release -->|"publishes"| node_n_install

click node_n_main "https://github.com/sigoden/upt/blob/main/src/main.rs"
click node_n_lib "https://github.com/sigoden/upt/blob/main/src/lib.rs"
click node_n_action "https://github.com/sigoden/upt/blob/main/src/action.rs"
click node_n_vendor "https://github.com/sigoden/upt/blob/main/src/vendor.rs"
click node_n_task "https://github.com/sigoden/upt/blob/main/src/task.rs"
click node_n_error "https://github.com/sigoden/upt/blob/main/src/error.rs"
click node_n_utils "https://github.com/sigoden/upt/blob/main/src/utils.rs"
click node_n_macros "https://github.com/sigoden/upt/blob/main/src/macros.rs"
click node_n_ci "https://github.com/sigoden/upt/blob/main/.github/workflows/ci.yml"
click node_n_release "https://github.com/sigoden/upt/blob/main/.github/workflows/release.yml"
click node_n_install "https://github.com/sigoden/upt/blob/main/install.sh"

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_n_main,node_n_lib toneBlue
class node_n_action,node_n_vendor,node_n_error,node_n_utils,node_n_macros,node_n_env toneAmber
class node_n_task,node_n_pm,node_n_os toneMint
class node_n_ci,node_n_release,node_n_install toneRose
```

## Components

### CLI

User entrypoint and shared crate surface

- [main](https://github.com/sigoden/upt/blob/main/src/main.rs): binary entrypoint · Starts the CLI and hands off to shared app logic · `src/main.rs`
- [lib](https://github.com/sigoden/upt/blob/main/src/lib.rs): shared crate API · Exposes the reusable application logic for the binary · `src/lib.rs`

### Resolution

Command routing and backend selection

- [actions](https://github.com/sigoden/upt/blob/main/src/action.rs): command router · Maps unified commands to abstract operations and tool-specific syntax · `src/action.rs`
- [vendor](https://github.com/sigoden/upt/blob/main/src/vendor.rs): platform detector · Chooses the package manager from OS and distribution support rules · `src/vendor.rs`
- [errors](https://github.com/sigoden/upt/blob/main/src/error.rs): error model · Defines user-facing failures and execution errors · `src/error.rs`
- [utils](https://github.com/sigoden/upt/blob/main/src/utils.rs): shared helpers · Cross-cutting helpers used by resolution and execution code · `src/utils.rs`
- [macros](https://github.com/sigoden/upt/blob/main/src/macros.rs): boilerplate helpers · Macro support for repeated mapping and conversion patterns · `src/macros.rs`
- **UPT_TOOL**: env override · Forces a specific backend and overrides auto-detection

### Execution

Process launch and host tool interaction

- [task](https://github.com/sigoden/upt/blob/main/src/task.rs): invocation model · Represents the resolved backend command and final argument list · `src/task.rs`
- **pkg managers**: native backends · Host tools such as apt, brew, pacman, dnf, zypper, and winget
- **host OS**: runtime platform · Underlying operating system and distribution family

### Delivery

Build and installation paths

- [CI](https://github.com/sigoden/upt/blob/main/.github/workflows/ci.yml): workflow · Build and validation workflow in GitHub Actions · `.github/workflows/ci.yml`
- [release](https://github.com/sigoden/upt/blob/main/.github/workflows/release.yml): workflow · Release and publishing workflow in GitHub Actions · `.github/workflows/release.yml`
- [install.sh](https://github.com/sigoden/upt/blob/main/install.sh): installer script · Shell-based installation path for Unix-like systems · `install.sh`

## Connections

- main → lib: calls · Binary delegates shared application startup
- lib → actions: routes · Library wires parsed CLI intent into command routing
- actions → vendor: resolves · Command routing asks for the appropriate backend
- vendor → UPT_TOOL: overridden by · Environment variable can force a specific tool
- vendor → host OS: inspects · Detection uses the current host platform
- actions → task: builds · Translated operation becomes an executable task
- task → pkg managers: spawns · Task launches the native package manager process
- task → errors: reports · Execution failures are converted to crate errors
- actions → errors: rejects · Invalid commands and unsupported mappings surface as errors
- utils → vendor: supports · Shared helpers assist detection and environment probing
- utils → task: supports · Shared helpers assist command assembly and process handling
- macros → actions: generates · Macros reduce repetitive dispatch definitions
- macros → errors: generates · Macros help standardize error conversion patterns
- CI → lib: validates · CI builds and checks the crate
- release → install.sh: publishes · Release workflow supports distributable installation paths
