Arka architecture
Arka serves 26 native package formats from a Go micro-kernel. PostgreSQL 16 holds authoritative registry state, configurable blob pools hold artifact bytes, and arka-scanner can run as a separate service. Arka replicas share the same state, storage, and credential keys. The format guide index describes native client setup and the capabilities of each driver.
Request boundaries
| Entry point | Implementation and responsibility |
|---|---|
/api/v1/* | internal/httpapi registers the native management API through Huma. The Go DTOs in pkg/api define the OpenAPI 3.1 contract used by the Go client, arkactl, and the generated TypeScript client for the Console. Collections use items and total. Errors carry an RFC 9457 Problem Details envelope with an Arka error code and request ID. |
/repository/{name}/… and /v2/… | internal/protocol resolves the repository and dispatches to its registered format driver. Native package clients keep their own protocol, including the OCI Distribution API at /v2/. |
/service/rest/v1/… | The optional in-process internal/compat/nexus3 adapter reuses Arka authorization and catalog operations. It mounts 12 allowlisted method and path combinations when ARKA_NEXUS3_COMPAT_ENABLED=true and returns HTTP 404 by default. See the Nexus compatibility ADR for the route list. |
cmd/arka wires the HTTP handlers, kernel, stores, event subscribers, and workers. The format-agnostic kernel owns shared catalog, authorization, storage, and proxy behavior. Format drivers in internal/formats implement path parsing, publication, client metadata, and Hosted, Proxy, or Group semantics through spi.FormatDriver and spi.Runtime. Each driver declares its specific capabilities. Format, migration-source, and blob-store registries are composed at startup.
Contract and build versions
api/openapi.json uses the fixed /api/v1 contract version 1.0.0 in info.version. The code-first export and make console-gen produce the same contract and clients for development and release builds with the same source. See the API stability contract.
Release builds inject Version, Commit, and BuildDate using -X on github.com/ccsert/arka/internal/buildinfo. Arka reports the binary version in /api/v1/health, /api/v1/health/live, and /api/v1/ready, and Arka-to-Arka preflight reads the source version from readiness. Arka and Scanner startup logs include build metadata. arkactl version prints the version, arkactl version --json also includes known commit and build-date fields, and Scanner /healthz reports its own binary version. Without injection the version comes from the Go module version when available, with dev as the local fallback. The commit can come from Go VCS metadata, and the build date is supplied by release tooling. github.com/ccsert/arka/internal/cli.Version remains a fallback injection target for existing arkactl builds.
On shutdown (SIGTERM), Arka executes a bounded, phased drain: stopping new HTTP ingress, flushing the transactional webhook outbox and background workers, and closing the shared PostgreSQL pool last. Setting ARKA_METRICS_REQUIRE_AUTH=true enforces fail-closed authentication on /metrics (including dedicated metrics ports).
Shared state and storage
internal/store/postgres uses one application pgxpool.Pool per Arka process. Embedded, sequential migrations run under a PostgreSQL advisory lock. PostgreSQL holds the repository catalog, artifact and asset references, identity and grants, policy, audit records, migration checkpoints, and the durable job queue. The catalog schema is shared across formats. An asset maps a repository path and optional coordinate to blob metadata, and the blob store holds the bytes addressed by SHA-256 within a pool.
Policy mutations advance scoped counters in policy_generations within the write transaction. Each replica has a shared listener connection for PostgreSQL LISTEN/NOTIFY channels arka_invalidation and arka_jobs. Notifications wake consumers to invalidate cached state or claim work. Routing decisions check the authoritative generation in PostgreSQL before reusing a snapshot. Reconnect and periodic reconciliation recover from missed notifications, and workers use PostgreSQL leases for durable jobs.
| Pool driver | Byte storage and delivery |
|---|---|
fs | Stores blobs on a filesystem with generation-isolated keys and device/inode backend_identity. With filesystem offload configured behind a trusted reverse proxy, Arka can authorize the request and return X-Accel-Redirect for Nginx to serve the protected file. |
s3 | Connects to S3-compatible services such as RustFS. Supports explicit keys or the AWS default credential chain (aws_default), cross-replica upload staging, paginated orphan generation sweep, and authorized presigned downloads. |
azure_blob | Stores data in Azure Blob pools, with account-key, SAS, or Azure default credential authentication, cross-replica OCI chunked upload staging, and paginated generation sweep (skipping HNS directory markers). Account-key pools can issue authorized download redirects. |
gcs | Stores data in Google Cloud Storage pools with adc (Workload Identity / ADC), AES-256-GCM encrypted service_account_json, or loopback emulator anonymous auth, cross-replica chunked staging, paginated generation sweep, V4 signed download redirects, and unified GCS/S3-interop backend_identity. |
Object bytes deduplicate by SHA-256 inside a storage pool, while immutable blob generation keys isolate concurrent uploads from deletions. Writers stage large archives and resumable OCI chunks outside PostgreSQL write locks under renewed write-intent leases (0022–0025). Before sweeping orphans, Blob GC checks credential-free storage_pools.backend_identity (0027) under PostgreSQL locks so pools sharing a physical bucket, container, or filesystem mount never reclaim each other's live objects. Every pool exposes explicit capabilities (uploadStaging, generationCleanup, presignedDownload) through /api/v1. Retention policies act on catalog references through the kernel and can use format-specific grouping through the SPI. Replicas must share access to their pools and resumable upload staging. Deployment and pool settings are in the deployment guide.
Publication, reads, hot index cache, and authorization
- The HTTP boundary establishes the principal. Local credentials, sessions, scoped API tokens (
read/write/adminupper-bound ceilings intersected with live grants), OIDC, and LDAP all feed the same authorization checks. Repository grants can scope access by path and Portable CSEL predicates over paths or coordinates. Delegated platform capabilities and repository-admin grants let teams administer only their assigned scope. - A Hosted publication goes through the format driver for validation and metadata, stages bytes outside write locks, and commits catalog updates atomically in PostgreSQL alongside a Transactional Webhook Outbox (
0028, stable event ID + idempotent(event_id, webhook_id)enqueueing + distinct attempt IDs). Publication events also record audit entries and enqueue durable vulnerability scan jobs. - A Proxy applies routing rules, egress policy, cache and offline policy, and format-supported release cooldown before fetching or serving upstream content. Conditional upstream
304 Not Modifiedrefreshes use singleflight waiter decoupling and compare-and-swap against the final upstream URL SHA-256 fingerprint (0026). Group lookup follows configured member order and may traverse bounded nested groups. Authorization remains fail-closed at each repository and path used to resolve the request. - Cross-replica hot index cache & batch policy (
0029–0031): APT, RPM, and PyPI index reads check cross-replica catalog revision fingerprints and evaluate download policy in batch, reducing hot200/304SQL round trips fromO(assets)toO(1)(including multi-leaf nested groups andPackages.gz-only APT upstreams) while re-checking catalog revisions and token status before writing response bodies. - The download guard applies vulnerability quarantine, SBOM license compliance (
off/audit/enforce, pure-Go SPDX 2.3), scan, and signature policy before protected bytes are sent or delivery is offloaded. The authorized delivery path may stream from Arka, redirect to a signed object URL, or use internal reverse-proxy offload where the pool and response support it.
Recoverable credentials use versioned enc:v1:<key-id>:… AES-256-GCM envelopes with random nonces and authenticated field scope. Replicas use the active key for writes and can read envelopes encrypted by configured previous keys during online rotation. Management APIs map typed domain models to response DTOs and expose credential presence flags in place of values. See security and governance and the operations handbook.
Migration and cutover
Migration-source drivers are outbound adapters. They plug into the same kernel orchestration and destination format drivers.
| Source driver | Import path |
|---|---|
nexus3 | Discovers source capabilities and topology, imports with checksum verification and resumable checkpoints, reconciles governance and asset evidence, and syncs increments from a watermark. The cutover gate fails closed on incomplete, stale, unsupported, or mismatched evidence. Review source-wide reconciliation before switching traffic. See the Nexus cutover guide. |
arka | Discovers remote repositories using the native management API and imports artifacts from another Arka registry. Preflight checks remote readiness and reads source format and repository metadata. |
artifactory | Reads repository topology and deep File List inventories. Maps Artifactory package types to Arka formats and imports with the source checksums. |
harbor | Maps Harbor projects to Hosted OCI repositories and imports tags, manifests, referenced manifests, and blobs through OCI Distribution. |
See operations and CLI for source credentials and incremental imports.
Scanner sidecar
Arka stores policies, durable scan jobs, results, and evidence in PostgreSQL. An Arka job worker opens a blob and sends the artifact bytes and expected digest to arka-scanner over an authenticated private HTTP connection. Scanner verifies SHA-256, bounds concurrency, temporary disk, and extraction, and runs Syft to generate CycloneDX and SPDX SBOMs. Grype evaluates the Syft catalog using its installed vulnerability database. Offline deployment uses a verified database directory or a checksum-pinned startup import. Scanner requires only its HTTP credential and local workspace and database access. See the external scanner guide.
With groupScanReuse enabled, a Group can reuse sidecar evidence for the same artifact digest and input profile across accessible members. Reuse checks the scanner engine and vulnerability database version. The source remains subject to its repository and path grants. The Group and selected member each apply their current thresholds and waivers to the stored findings.
Vulnerability database metrics
Scrape Scanner's own /metrics per instance. It returns HTTP 200 even when /readyz returns HTTP 503 because the database is expired, missing, or invalid.
| Prometheus gauge | Value |
|---|---|
arka_scanner_db_ready | 1 if the database is usable, 0 otherwise. Scanner readiness also checks the tools and filesystem. |
arka_scanner_db_built_at_timestamp_seconds | Database build time as Unix seconds for ready and expired, 0 for missing and error. |
arka_scanner_db_age_seconds | Age at scrape time for ready and expired, with a floor of 0 for future build timestamps. Returns -1 for missing and error. |
arka_scanner_db_max_age_seconds | Configured GRYPE_DB_MAX_ALLOWED_BUILT_AGE in seconds. The default is 432000 (120h). Age enforcement is enabled by default and controlled by GRYPE_DB_VALIDATE_AGE. |
arka_scanner_db_status{state="…"} | A fixed set of four series with 1 for the active state and 0 for the others. ready means the database passed validation, expired means its age exceeded the enforced limit, missing means Grype found no installed database, and error covers other validation or probing failures, a failed archive import, or pending initial validation. |
For advance warning, compare a nonnegative age with a threshold below arka_scanner_db_max_age_seconds. An active expired series indicates the age limit was exceeded. The missing and error series distinguish absence from failures that require inspection of Scanner logs.
Architecture checks
make test-arch checks the dependency boundaries across all 26 dynamically discovered formats (Go AST) and Console source code (TypeScript AST), typed API contracts, migration ordering, format-neutral storage schema, and Console design conventions. make verify regenerates the OpenAPI and clients, runs Go tests with the race detector, builds the Console, checks deployment manifests, and builds the binaries. See AGENTS.md for the engineering rules and operations and CLI for management entry points.