Architecture Boundaries
This is the Cloud package and storage map. The normative product and
local-runtime contract is the Runx system architecture, published with the
runx source as docs/architecture/runx-system.md.
Runx Platform Boundary
Runx is a governed execution platform, not a payment system. Its architectural center is the payment-neutral contract, authority, policy, runtime, and receipt model. Marketplace, catalog, billing, payments, purchase, hosted connectors, and product APIs are peer capabilities outside that center. They may consume platform contracts and runtime services; no platform-core package imports one of those feature packages.
A feature package can own a cohesive domain and application boundary without becoming "core." Shared store bases, generic repositories, or payment-specific types are not promoted into the platform center merely because multiple adapters need them.
Package boundaries stay human-shaped. One package represents a cohesive capability or aggregate lifecycle, not one endpoint, table, command, or adapter. Quote, get, cancel, execute, outcome, and refund transitions for a purchase evolve in the same feature module; rail settlement remains a separate billing capability. Split a package only for a real ownership, trust, deployment, or acyclic-dependency boundary. Do not create a framework package for ordinary TypeScript interfaces or a database package per store.
Local And OSS
The open local runtime owns portable execution, CLI workflows, local policy admission, local receipt sealing, and bring-your-own credentials supplied per run. Local runs may use personal tokens and API keys directly, or explicitly opt into Hosted Connect for one registered provider operation. The local runtime owns the surrounding skill and state in either case; it never brokers OAuth or receives the managed provider credential.
Hosted Connect And Auth
The hosted auth layer owns OAuth, hosted connect tickets, provider-reference custody, grant lifecycle, service principals, provider credentials, and revocation. Provider implementation details stay inside private provider-gateway code. Other hosted packages consume provider references and grants through auth-level types and services.
Hosted API
The hosted API owns HTTP policy, request validation, auth checks, route
composition, and hosted control-plane transitions such as grant lifecycle,
registry publication, and explicitly submitted hosted runs. It does not choose
a domain action or the operator's next step. HostedApiOptions is a
composition root type only. Route modules receive route-specific option
interfaces, and persistence helpers receive narrow store ports rather than the
whole platform store.
Feature owners and dependencies
| Owner | Responsibility | Permitted dependency direction |
|---|---|---|
@runx/protocol | Shared utility primitives and inert artifact contract bindings | OSS contracts and low-level libraries; no Cloud feature |
@runx/hosted-runs | Hosted-run models, ports, state rules, summaries, governance and continuation DTOs | Contracts and protocol utilities; no DB, worker, API or I/O |
@runx/registry | Registry validation, trust, publication, indexing and concrete registry stores | Contracts and protocol utilities; no API or worker |
@runx/purchases | Purchase aggregate, application service and atomic operation ports | Portable contracts and feature-neutral utilities; no billing or DB package |
@runx/db | Connection/migration infrastructure and concrete hosted platform adapters | Domain ports, including hosted-runs; domains never import DB back |
@runx/receipts-store | Verified immutable archive and compact tenant projections | Contracts and infrastructure; no operator triage |
@runx/worker | Explicit hosted execution, queue leases and hosted ledger storage | Domain ports, @runxhq/client and concrete infrastructure; no API composition |
@runx/api | HTTP composition and feature application operations | Narrow domain/store ports and concrete adapters at composition roots |
API source is grouped by feature: runs, receipts, source-events, registry,
governance, principals, identity, integrations, payments, billing,
and public surfaces. server-persistence.ts owns platform-store composition;
feature modules do not receive HostedPlatformStore or HostedApiOptions.
An HTTP route may use a narrow read port directly. A service exists where it
owns admission, tenant access, a multi-store transition, or presentation. A
one-to-one rename of store methods is not a useful service boundary.
Principal configuration retains a real credential replacement/rollback adapter. Provider references retain auth-binding projection and revocation. Public activity/catalog sources retain live-versus-immutable-snapshot selection. These are distinct transformations, not generic persistence facades. Registry's memoized store retains bounded cached validation and concurrent-load coalescing; the publication path does not wrap the store in a second client.
Persistence and evidence
The consuming domain owns record meaning and its port. Infrastructure owns
SQL, indexes, locking, row mapping and error classification. Hosted-run ports
are implemented in DB; purchase infrastructure is the explicit
@runx/purchases/postgres subpath. Feature-local stores may own their
infrastructure in the same package. There is no universal repository layer.
Ports preserve atomic transitions and typed replay/conflict outcomes where needed. Generic effect state is a lower-level atomic state capability, not a billing model. Synchronous memory transitions commit before their promise returns; asynchronous transitions on the same scope serialize. Postgres uses the existing transaction and advisory-lock boundary.
Private execution bindings and their retained references include both the package digest and execution-closure digest. The closure includes the runtime release, so a runtime upgrade may publish another closure for unchanged package bytes. Older bindings and run references remain immutable; a reference never selects the latest runtime implicitly.
Run and receipt list operations filter, order, and page before hydrating records. Tenant ownership is resolved before an archive body is read. Summary reads never load an unbounded execution history. Maintenance and public snapshot jobs explicitly iterate bounded pages until complete.
Source observation ingress authenticates the provider, normalizes the envelope, applies tenant ingress policy, and records the observation. It does not choose an operator response, start a run, or sign an execution receipt. A verified receipt archive holds genuine immutable execution evidence; a tenant receipt projection is a compact mutable index over that archive, not another signed packet.
Signed evidence is never silently rewritten or host-resigned to fit a projection. Offline migrations quarantine ambiguous rows and rebuild only owner-proven projections. Production migration is an explicit operation; local native Postgres tests do not imply deployment.
Worker
The hosted worker owns durable claiming, heartbeats, reclaim behavior, and governed execution for runs that a user explicitly submits to the hosted service. It consumes published OSS skill packages, issued credentials, and sealed receipts; it does not own the skill, an end-user or domain-operator workflow, a default local queue, OAuth route logic, public page rendering, or provider implementation details. Local execution and local operator state stay the default even when a run uses hosted Connect for one bounded provider call.
Native Client Boundary
@runxhq/client in OSS owns the one bounded Node subprocess transport, finite
native commands, execution-binding decoding and digest-bound compact artifacts.
Cloud worker and API consumers use this package; no private spawn or JSON parser
implements the same native boundary.
Worker composition remains native-runtime-service-client.ts: it selects the
hosted environment and workspace and invokes the client. Provider and artifact
credentials stay behind hosted-runtime-gateway.ts; hosted-runtime-outcome.ts
projects native results into the hosted domain. Gateway cleanup covers setup,
invocation and decoding failure. Inspection caching requires an explicitly
immutable source tree. Editable local paths use fresh inspection.
Registry materialization keeps publication validation and persistence in Cloud, harness composition selects its hosted signer, and the receipt notary owns HTTP and trust policy. Their native process calls use the corresponding client operations. Fieldwork does not inherit hosted paths, custody, queue leases or outcome projections: it owns its local service and SQLite state separately.
This extraction addresses duplicated transport and mixed hosted composition. Hosted claiming, billing, receipt custody, registry moderation and explicitly submitted hosted schedules remain service responsibilities. They are not a reason to add default operator state, memory or assistant loops here.
Contracts And Docs
Contracts define wire schemas and generated OpenAPI shape. Docs describe the current shipped boundary: local is self-sufficient with BYO credentials, hosted managed connect is opt-in, and private provider details are not public API.
Internal contract changes use explicit cutovers with every direct consumer updated and the displaced implementation/export deleted. Stored data requires an explicit migration or quarantine; runtime defaults, dual readers, alias exports, and read-time backfills are not substitutes for that operation.
Enforced Rules
- Route modules must not import or mention
HostedApiOptions. - Hosted API modules below bootstrapping must not depend on
HostedPlatformStore; they use narrow ports from the owning feature orpersistence-ports.ts. - Auth package internals import their owning modules, not the auth root barrel.
- Database postgres internals import postgres modules directly, not the db root barrel.
- Pure domain modules do not import infrastructure. Composition constructs concrete adapters and injects feature ports. Feature implementations import package exports, never sibling package source paths.
- UI cannot depend on API; its catalog generators consume the neutral registry integration data. Registry and protocol never import higher Cloud features.
- The shared workspace check parses imports and package manifests, checks production dependency cycles and declared exports, and fails if a current owner disappears. Its negative fixtures exercise the same implementation used by the CLI; line counts are not architecture.
- Private provider implementation names stay out of public hosted application code, scripts, docs, and OSS.
- Cloud must not contain runx-maintained skill packages or the provider-neutral operator inbox. Reusable procedures and local operator state belong in OSS or the owning product; Cloud may only execute their registered, grant-bound provider operations.
The API process and standalone worker assemble hosted execution through
packages/api/src/hosted-execution-composition.ts. Provider transport wiring
lives in connect/runtime-service.ts; paid maintenance lives in
payments/purchases/maintenance.ts. Workers admit native execution receipts
without rewriting them. The purchase feature seals a visibly hosted
commercial attestation referencing the original native evidence.