Development & Contribution Guide
Relevant source files
The following files were used as context for generating this wiki page:
This guide provides a comprehensive overview of the development standards, architectural patterns, and contribution workflows for regxa, a universal package registry client. The project is designed as an ESM-only TypeScript library and CLI that normalizes package metadata across various ecosystems including npm, PyPI, crates.io, RubyGems, Packagist, and Arch Linux (ALPM).
The architecture prioritizes PURL (Package URL) as the primary identifier and enforces a strict inward dependency direction where higher-level modules like commands and registry adapters depend on the core contract layer.
Sources: AGENTS.md:3-8, README.md:10-18
Project Architecture & Structure
The codebase is organized into functional boundaries to separate concerns between core logic, registry-specific adapters, and user interfaces (CLI/AI tools).
Codebase Map
| Directory | Responsibility |
|---|---|
src/core/ | Primitives, shared contracts, PURL parser, base client, and normalization logic. |
src/registries/ | Per-ecosystem adapters (npm, pypi, cargo, gem, composer, alpm). |
src/cache/ | Optional decorator providing storage, lockfile TTL, and integrity checks. |
src/commands/ | CLI subcommand definitions using citty. |
src/helpers.ts | High-level convenience wrappers for PURL operations. |
src/ai.ts | Vercel AI SDK tool integration. |
test/unit/ | Deterministic tests utilizing mocks and spies. |
test/e2e/ | Live HTTP smoke tests against real-world registries. |
Sources: AGENTS.md:27-37, src/AGENTS.md:7-16
Dependency Flow
The project enforces a strict inward dependency direction. commands/ and registries/ depend on core/, and cache/ decorates core/. Reversing this dependency (e.g., core depending on a specific registry) is strictly prohibited.
The diagram shows the hierarchical structure where interfaces and adapters converge on the stable core contract layer.
Sources: AGENTS.md:41, src/AGENTS.md:25
Development Workflow
Quick Commands
Contributors should use the following pnpm commands for local development:
| Command | Action |
|---|---|
pnpm install | Install project dependencies. |
pnpm dev:prepare | Stub the build for active development. |
pnpm build | Production build via obuild into the dist/ directory. |
pnpm typecheck | Run tsc --noEmit to verify type safety. |
pnpm lint | Run oxlint and check formatting with oxfmt. |
pnpm fmt | Fix linting issues and format code. |
pnpm test | Run Vitest in watch mode. |
pnpm test:run | Run Vitest once (CI-style). |
Sources: AGENTS.md:10-19
Technical Constraints
- ESM Only: The project uses
"type": "module". No CommonJS output orrequirepaths are permitted. - Import Suffixes: All source imports must include the
.tsextension, enforced byverbatimModuleSyntax. - Type Safety:
strict: trueis enabled. Use ofas any,@ts-ignore, or@ts-expect-erroris banned. - Node Version: Requires Node.js
>=22.6.0.
Sources: AGENTS.md:47-58, AGENTS.md:129
Core Logic & Contracts
The src/core directory contains the stable contract layer that all other modules must adhere to.
Centralized Components
- PURL Parser (
src/core/purl.ts): The single source of truth for parsing and building Package URLs. Parsing logic must not be duplicated elsewhere. - Registry Factory (
src/core/registry.ts): A plugin-based factory usingregister()andcreate()to instantiate adapters without hardcoded switch logic. - HTTP Client (
src/core/client.ts): All network calls must go through the centralClient. It handles retries, timeouts, and rate limiting. - Error Hierarchy (
src/core/errors.ts): Provides typed errors such asPkioError,HTTPError,NotFoundError, andInvalidPURLError.
Sources: AGENTS.md:62-67, AGENTS.md:89-91, src/core/AGENTS.md:7-16
The sequence shows how the Core Client and Factory abstract registry-specific complexities from the consumer.
Sources: src/core/AGENTS.md:18-23
Testing Standards
Testing is split between deterministic unit coverage and live-network end-to-end (e2e) checks.
Testing Guidelines
- Location: Unit tests reside in
test/unit/*.test.ts. E2E smoke tests reside intest/e2e/. - Environment: Vitest with globals enabled (
describe,it,expect). - Mocking: Unit tests must use
vi.hoisted()orvi.fn()for module mocks and spies rather than making network calls. - Naming: All test files must use the
.test.tsextension.
Sources: AGENTS.md:81-86, test/AGENTS.md:7-14
Contribution Rules & Banned Patterns
To maintain codebase integrity, contributors must avoid the following patterns:
- Direct Fetch: Do not use
fetchorofetchdirectly in registries; always use the coreClient. - Duplicate Parsing: Never parse PURLs manually outside of
src/core/purl.ts. - Hardcoded Constants: Do not duplicate retry, backoff, or TTL constants; these live in
client.tsorlockfile.ts. - Dead Code:
noUnusedLocalsis enabled; do not comment out dead code, remove it. - Side-Effect Imports: Registry registration is intentional via side-effects (e.g.,
import 'regxa/registries').
Sources: AGENTS.md:95-101, src/AGENTS.md:31-33
Adding New Features
| Feature Type | Implementation Path |
|---|---|
| New Ecosystem | src/registries/<name>.ts + register in src/registries/index.ts. |
| New CLI Command | src/commands/<name>.ts + wire into src/cli.ts. |
| Public API | Export from the root src/index.ts barrel. |
| Shared Contract | Update src/core/types.ts. |
Sources: AGENTS.md:40-45, src/AGENTS.md:18-23
Summary
The regxa project is built on a "PURL-first" philosophy, requiring all contributions to respect the normalized data models and centralized core utilities. By strictly adhering to the inward dependency rule and utilizing the provided build and test tooling, developers ensure that the library remains a reliable, lightweight, and ecosystem-agnostic tool for package metadata retrieval.