Skip to content
inixiativePublic

About

Stateless infrastructure drivers (Railway, Render, Fly.io Machines, Firecracker) and workload lifecycle engine

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

@inixiative/infra

Hosting and infrastructure for Railway, Render, Fly.io Machines and Firecracker, and the project setup APIs of Vercel, PlanetScale, Cloudflare Pages, Infisical and Resend, built on @inixiative/api-client: each provider's API as atomic operations, the services composed from them, and a pure lifecycle engine for wind-down, staggered wake and cost projection. MIT.

The shape

  • An operation is one request to a provider, made with api-client's makeApiOperation and called (client, input, options?). Each provider declares its operations with defineApiOperations and exports them as <provider>Operations, keyed by catalog key (machines.read, services.create, serviceInstances.deploy).
  • A service runs several operations in order (Fly suspend reads the Machine for its memory, suspends it and waits for the state). Services live in each provider's services/ folder, take the same (client, input, options?), and are never operations.
  • The client is api-client's { baseUrl, auth?, send? }. makeBearerClient({ baseUrl, token, send? }) builds one with bearer auth over an async token source the caller may cache; pass the provider's base URL (FLY_MACHINES_API_URL, RENDER_API_URL, RAILWAY_API_URL, VERCEL_API_URL, CLOUDFLARE_API_URL, INFISICAL_API_URL, RESEND_API_URL). PlanetScale's client is makePlanetScaleClient(token, { serviceTokenId? }) for its <id>:<token> service tokens. Where the only credential on a developer machine is a logged-in CLI, fetchVercelCliToken, fetchPlanetScaleCliToken, fetchInfisicalCliToken and fetchRailwayCliToken are token sources. A Firecracker client is { baseUrl: FIRECRACKER_DEFAULT_BASE_URL, send: makeUnixSocketSend(socketPath) }, or a plain HTTP base URL. Recording, metering and rate limiting are the caller's send.
  • Options are api-client's per call: auth (replaces the client's), logger, retry, signal, timeoutMs. Services pass them to every operation they run.
  • Errors are api-client's ApiError (provider_not_found, provider_rate_limited, invalid_request, …). There is no infra error class. A failure is retryable when it is provider_unreachable, provider_rate_limited, provider_temporarily_unavailable, or provider_failed with a providerStatus of 500 or more; a deploy the provider reports as failed is provider_deploy_failed with the provider's status in detail. The table is in docs/VERBS.md.
import { makeBearerClient } from '@inixiative/infra';
import { FLY_MACHINES_API_URL, flyInfrastructureResourceServices, flyOperations } from '@inixiative/infra/fly';

const fly = makeBearerClient({ baseUrl: FLY_MACHINES_API_URL, token: async () => flyToken });

const handle = await flyInfrastructureResourceServices.provisionInfrastructureResource(fly, {
  appName: 'workers',
  spec: { name: 'worker-1', image: 'ghcr.io/example/worker:1', memoryMb: 1024, vcpus: 1 },
});
await flyInfrastructureResourceServices.suspendInfrastructureResource(fly, handle, { logger });
const machine = await flyOperations['machines.read'](fly, {
  appName: 'workers',
  machineId: handle.externalId,
});

What lives here

  • Core (src/core/): the contracts (InfrastructureResourceServices, ArchiveHostingServices, specs, handles, statuses), the provider capability registry (INFRA_PROVIDERS), makeUnixSocketSend, ignoreNotFound, and the Archive deployment constants.
  • Provider lists (src/providers/, import @inixiative/infra/providers): the provider ids, ARCHIVE_HOSTING_PROVIDERS and their narrowing helpers, with no operations or schemas, so a browser bundle can import them. isRetryableInfraError (root) answers the retry table in VERBS.
  • Registries (src/): infrastructureResourceServicesByProvider holds every implemented provider's seven infrastructure resource services and archiveHostingServicesByProvider every archive host's services, each checked with satisfies so a provider missing one does not compile.
  • Railway (src/railway/): GraphQL operations (response: 'graphql', Railway's error codes read by railwayGraphqlErrorCode), the compositions template's init/ uses (ensureRailwayProject, ensureRailwayService, ensureRailwayVolume, ensureRailwayDatabase, ensureRailwayBucketInstance, fetchRailwayServiceVolume, connectRailwayServiceToGitHub, …), and the infrastructure resource and archive hosting services.
  • Render (src/render/): REST operations, the plan-tier table, and the infrastructure resource and archive hosting services.
  • Fly.io Machines (src/fly/): REST operations and the infrastructure resource services (suspend refuses a Machine over FLY_SUSPEND_MAX_MEMORY_MB, waits for each state, and reads usage from the Machine's event timeline).
  • Firecracker (src/firecracker/): the VMM control API (boot config, drives, network interfaces, track_dirty_pages snapshots, pause and resume) and the infrastructure resource services.
  • Lifecycle (src/lifecycle/): deterministic, no-I/O state evaluation for generic profiles (warm-interactive, warm-pool, batch-worker, ephemeral-session, always-on), staggered wakes (planStaggeredWakes), and raw cost plus managed markup (projectHostingMonthlyCost).

Naming & vocabulary

Every exported symbol across every entry point is listed in docs/VERBS.md, with every operation's key, and tests/verbs.test.ts holds the list to the code.

  • One named export per file, the file named after it; barrels and contract files are the exception.
  • fetch* for I/O reads, noun phrases for in-memory reads, make* for what hands back a client or a send, ensure* for find-or-create.
  • Error codes are api-client's snake_case codes; functions are camelCase.

Development

bun run check   # typecheck, lint, build, test

About

Stateless infrastructure drivers (Railway, Render, Fly.io Machines, Firecracker) and workload lifecycle engine

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages