Architecture Overview
Relevant source files
The following files were used as context for generating this wiki page:
The regxa project is a universal package registry client designed as an ESM-only TypeScript library and CLI. Its primary architecture focuses on normalizing package metadata across diverse ecosystems—including npm, PyPI, crates.io, RubyGems, Packagist, and Arch Linux (ALPM)—using Package URLs (PURLs) as the primary addressing mechanism. The system is structured to be "PURL-first," ensuring that disparate registry APIs are abstracted behind a unified interface.
The architecture follows a strict inward dependency direction where higher-level modules like CLI commands and ecosystem adapters depend on a stable core layer, but the core remains agnostic of specific registry implementations. An optional caching layer provides storage-backed persistence and integrity checks using sha256 hashes.
Core Module Structure
The src/core directory houses the foundational contracts and shared logic of the library. It defines the stable interfaces that all registry adapters must implement and provides the centralized HTTP client, PURL parser, and error hierarchy.
Component Breakdown
| Component | Responsibility | Source File |
|---|---|---|
| PURL Parser | Validates and normalizes Package URLs; single source of truth for identifiers. | src/core/AGENTS.md |
| Registry Factory | Manages the register and create lifecycle for ecosystem adapters. | src/core/AGENTS.md |
| Client | Handles all network requests, including retries, timeouts, and rate limiting. | src/core/AGENTS.md, AGENTS.md |
| Types | Defines shared contracts like Package, Version, and Dependency. | src/core/AGENTS.md |
| Normalization | Provides utilities for SPDX license normalization and repository URL cleanup. | src/core/AGENTS.md |
Sources: src/core/AGENTS.md, AGENTS.md:120-130
Dependency Flow
The following diagram illustrates the inward-facing dependency structure. Modules on the periphery (Commands, Registries) depend on the Core primitives, while the Cache acts as an optional decorator around the Core Registry.
Sources: src/AGENTS.md:25-30, AGENTS.md:50-55
Registry Implementation Pattern
Ecosystem adapters (found in src/registries/) are plugin-based. Each adapter implements the Registry interface, which requires methods for fetching packages, versions, dependencies, and maintainers. These adapters are responsible for mapping registry-specific JSON payloads into the normalized regxa data models.
Data Normalization
Adapters must utilize core helpers to ensure consistent output. For example:
- Licenses: Registry-specific strings are passed through
normalizeLicenseorcombineLicensesto produce SPDX-compliant results. - Repositories: URLs are cleaned using
normalizeRepositoryURLto remove.gitsuffixes or trailing slashes. - PURLs: The
buildPURLutility is used to generate proper identifiers for theurls()helper.
Sources: src/registries/npm.ts:133-144, src/registries/alpm.ts:100-120, src/core/AGENTS.md:10-20
ALPM Multi-Source Routing
The AlpmRegistry demonstrates a complex adapter pattern where it routes requests to either the official Arch Linux API or the AUR (Arch User Repository) based on the namespace provided in the PURL.
Sources: src/registries/alpm.ts:80-110
Public API and Helpers
The library provides high-level convenience wrappers in src/helpers.ts. These functions allow developers to perform operations directly using PURL strings without manually managing registry instances or factories.
Key Helper Functions
fetchPackageFromPURL(purl): Resolves the registry and fetches metadata in one call.bulkFetchPackages(purls, options): Executes concurrent fetches (defaulting to 15) with an integrated worker loop and abort signal support.selectVersion(versions, options): Implements a specific resolution logic—prioritizing exact matches, then latest stable, then newest non-negative status version.
Sources: src/helpers.ts:7-25, src/helpers.ts:50-65, src/helpers.ts:88-115
Request Execution Flow
The following sequence diagram shows how a request initiated from a helper travels through the system.
CLI Architecture
The CLI is built using citty and resides in src/commands/. Commands are designed as thin orchestration layers that interpret user input and invoke the appropriate core or helper functions.
- Dynamic Ecosystems: The CLI uses a dynamic list of ecosystems for error reporting and command routing.
- Output Modes: Every command supports both human-readable (consola) and machine-readable (
--json) output. - PURL Shorthand: The CLI allows users to omit the
pkg:prefix; theresolvePURLutility inshared.tshandles this normalization before passing the identifier to the core parser.
Sources: src/commands/AGENTS.md:10-25, src/commands/deps.ts:15-35, README.md:110-120
Conclusion
The architecture of regxa is centered on the strict normalization of package metadata through a "Core-First" approach. By enforcing inward dependencies and a plugin-based registry system, it maintains a stable API surface regardless of the underlying registry's complexities. The use of PURLs as the primary keying system ensures interoperability across the six supported ecosystems.