Skip to content

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 --release from 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 (tsi or tsi.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

  1. Package (core/package.rs)
  2. JSON manifest parsing
  3. Package metadata handling
  4. Dependency tracking

  5. Registry (core/registry.rs)

  6. Package manifest loading
  7. Repository directory scanning
  8. Package lookup

  9. Resolver (core/resolver.rs)

  10. Topological sorting
  11. Dependency graph construction
  12. Build order determination

  13. Database (core/database.rs)

  14. Installed package tracking
  15. JSON-based storage
  16. Package metadata persistence

  17. Config (core/config.rs)

  18. tsi.toml parsing
  19. User preferences and overrides

  20. Fetch (ops/fetch.rs)

  21. Git repository cloning
  22. HTTP download (built-in)
  23. Archive extraction (built-in)
  24. Local source handling

  25. Build (ops/build.rs)

  26. Autotools support
  27. CMake support
  28. Meson support
  29. Plain Makefile support
  30. Custom build commands

  31. CLI (cli/)

  32. Command-line interface (clap)
  33. Subcommands: install, uninstall, upgrade, list, search, info, update, doctor
  34. Argument parsing and dispatch

  35. Platform (platform/)

  36. os_name(): darwin, linux, windows, freebsd, etc.
  37. default_prefix(): ~/.tsi (Unix) or %USERPROFILE%\.tsi (Windows)
  38. 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

  1. Minimal Requirements: Pre-built binary or Rust toolchain for building
  2. Source-Based: Everything built from source
  3. Isolated Installation: Packages installed to separate prefix
  4. Distribution Independent: No reliance on system package managers
  5. Self-Contained: Single binary, no runtime dependencies

Build Process

  1. cargo build --release produces target/release/tsi (or tsi.exe on Windows)
  2. Optional: Static linking for maximum portability
  3. Install to system or user directory via make install or 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/)