TSI Architecture
Current Implementation (Rust)
TSI is implemented in Rust with a single static binary and zero runtime dependencies.
Advantages
- Cross-platform: macOS, Linux, Windows
- Single binary: Statically linked, no shared libraries required
- Built-in HTTP: No system curl needed for downloads
- Built-in archive extraction: No system tar/unzip needed
- Memory safety: Rust guarantees prevent common C pitfalls
- Easy bootstrap: Pre-built binaries available; or
cargo build --releasefrom source - Distribution independent: Works on any supported OS
Implementation Details
- Language: Rust (edition 2021)
- Build System: Cargo
- Dependencies: Minimal crates (serde, clap, reqwest, etc.)
- Output: Single executable (
tsiortsi.exe)
Module Layout
src/
├── main.rs # Entry point
├── lib.rs # Library root
├── cli/ # Command-line interface
│ ├── mod.rs # Clap parser, command dispatch
│ ├── install.rs
│ ├── uninstall.rs
│ ├── upgrade.rs
│ ├── list.rs
│ ├── search.rs
│ ├── info.rs
│ ├── update.rs
│ └── doctor.rs
├── core/ # Core data structures and logic
│ ├── mod.rs
│ ├── package.rs # Package manifest parsing
│ ├── registry.rs # Package repository loading
│ ├── resolver.rs # Dependency resolution
│ ├── database.rs # Installed package tracking
│ └── config.rs # Configuration (tsi.toml)
├── ops/ # Operations (fetch, build, install)
│ ├── mod.rs
│ ├── fetch.rs # Git clone, HTTP download, archive extraction
│ ├── build.rs # Autotools, CMake, Meson, Make
│ ├── install.rs # Copy artifacts to prefix
│ ├── uninstall.rs # Remove installed package
│ └── link.rs # Symlink management
├── ui/ # User-facing output
│ ├── mod.rs
│ ├── output.rs # Homebrew-style output
│ ├── progress.rs # Progress indicators
│ └── table.rs # Tabular display
└── platform/ # Platform-specific code
├── mod.rs # os_name(), default_prefix(), resolve_prefix()
├── unix.rs # Unix-specific paths and behavior
└── windows.rs # Windows-specific paths and behavior
Core Components
- Package (
core/package.rs) - JSON manifest parsing
- Package metadata handling
-
Dependency tracking
-
Registry (
core/registry.rs) - Package manifest loading
- Repository directory scanning
-
Package lookup
-
Resolver (
core/resolver.rs) - Topological sorting
- Dependency graph construction
-
Build order determination
-
Database (
core/database.rs) - Installed package tracking
- JSON-based storage
-
Package metadata persistence
-
Config (
core/config.rs) tsi.tomlparsing-
User preferences and overrides
-
Fetch (
ops/fetch.rs) - Git repository cloning
- HTTP download (built-in)
- Archive extraction (built-in)
-
Local source handling
-
Build (
ops/build.rs) - Autotools support
- CMake support
- Meson support
- Plain Makefile support
-
Custom build commands
-
CLI (
cli/) - Command-line interface (clap)
- Subcommands: install, uninstall, upgrade, list, search, info, update, doctor
-
Argument parsing and dispatch
-
Platform (
platform/) os_name(): darwin, linux, windows, freebsd, etc.default_prefix():~/.tsi(Unix) or%USERPROFILE%\.tsi(Windows)resolve_prefix(): User override or binary location detection
Dependency Flow
flowchart TD
CLI[cli/] --> Ops[ops/]
CLI --> Core[core/]
CLI --> UI[ui/]
Ops --> Core
Ops --> Platform[platform/]
Ops --> UI
Core --> Platform
Design Principles
- Minimal Requirements: Pre-built binary or Rust toolchain for building
- Source-Based: Everything built from source
- Isolated Installation: Packages installed to separate prefix
- Distribution Independent: No reliance on system package managers
- Self-Contained: Single binary, no runtime dependencies
Build Process
cargo build --releaseproducestarget/release/tsi(ortsi.exeon Windows)- Optional: Static linking for maximum portability
- Install to system or user directory via
make installor bootstrap script
Testing
- Unit tests: In-module
#[cfg(test)]tests - Integration tests:
tests/package_parse.rs,tests/resolver.rs - Docker: Minimal systems and various Linux distributions (see
docker/)