One contract. Every boundary.

Inferred types connect the app and API; validation protects the wire.

Author the schema once

Canonical contracts live in Foundation src/contracts. TypeBox schemas define requests, responses, configuration and deployment boundaries. Infer TypeScript types from those schemas rather than maintaining parallel wire interfaces.

Call routes through the typed client

The shared client validates input and response payloads using the route’s canonical schema. Authentication tokens remain in the mounted application’s memory. Never substitute a raw fetch call for an existing typed route.

TypeScript
import { createApiClient } from '$lib/foundation/client/api';
import { CoreRoutes } from '$lib/foundation/contracts/routes';

const api = createApiClient(CoreRoutes, runtime.transport);
const challenge = await api('auth.start')({ email });

Pin both consumers

The app and API consume pinned local Foundation snapshots. Change canonical generic behavior first, then synchronize snapshots with the maintained tool. Static browser clients and overlapping API slots may use different release versions; compatible contract evolution is part of release acceptance.