Skip to content

API Surfaces

A catalog of the exported interfaces across the monorepo.

Use this to find function signatures, type definitions, and understand what each package exposes. For the deeper "why" behind each surface, follow the links to the relevant system docs.

API Client (clients/api)

Local development proxy built on Hono. Not a production service — it models the shape of upstream data.

RouteMethodPurpose
/mockGETMock data with simulated 2s latency
/discoverGET → POST proxyCurated content feed from external discover service
/weather/weather-reportGET → GET proxyWeather conditions from external weather service

Environment variables: DISCOVER_ENDPOINT, WEATHER_ENDPOINT (configured in clients/api/.env).

See Architecture overview for why this isn't a production service.

Coordinator (clients/coordinator)

Reference implementation of the coordinator role. In production, this behavior moves to browser core.

Boot flow (main.ts)

FunctionPurpose
boot()Entry point — resolves renderer + data, mounts renderer

Renderer cache (renderer-cache.ts)

FunctionPurpose
resolveRenderers()Returns { cached?, bundled } — best available renderer and bundled fallback
mountRendererFromUrl(url, options)Loads renderer JS and mounts into DOM
fetchRemoteManifest()Fetches latest manifest from remote (no-store)
validateRendererModule(url)Loads renderer without mounting — structural validation
cacheRenderer(manifest, assetsBase)Writes manifest + JS + CSS to Cache API
getCachedRenderer()Reads and validates cached renderer from Cache API

Data cache (data-cache.ts)

FunctionPurpose
getDataPayload()Reads cached CoordinatedPayload from Cache API
refreshDataForNextSession(payload)Background SWR refresh — updates cache for future loads
isDataStale(payload)Returns true if age > DATA_STALE_MS (blocking refresh threshold)
shouldDataUpdate(payload)Returns true if age > DATA_TTL_MS (background refresh threshold)

See Coordinator deep-dive for the full SWR lifecycle.

Renderer (clients/renderer)

The production artifact. Registers itself on globalThis.AppRenderer as an IIFE bundle.

RendererModule contract

typescript
type RendererModule = {
  init?: (args: RendererInitArgs) => void | Promise<void>
  mount: (container: HTMLElement, props: AppProps) => void
  update?: (data: AppProps) => void
  unmount?: (container: HTMLElement) => void
  version?: string
}

Not yet in code

init() and RendererInitArgs are typed in @common/types and defined in the lifecycle contract, but not yet implemented in the renderer entry or coordinator boot sequence.

MethodRequiredPurpose
initnoRuntime bootstrap: receives gating payload, message loading, error/metric reporting
mountyesInitial render into a DOM container
updatenoRe-render with new props (safe no-op if not mounted)
unmountnoTeardown and cleanup
versionnoBuild hash, replaced at build time

RendererInitArgs (planned)

typescript
type RendererInitArgs = {
  gatingPayload: GatingPayload
} & CoordinatorInterface

Two concerns in one flat type: data in (gatingPayload) and callbacks out (everything from CoordinatorInterface). The gating payload has two facets: locale (translation context) and flags (resolved feature flag state). See Gating and Feature flags.

CoordinatorInterface includes all coordinator-bound functions: l10n (getMessages), reporting (reportError, reportMetric), content actions, top sites, search, and message lifecycle. See Lifecycle contract: coordinator interface for the full shape.

The renderer is loaded via classic <script> (IIFE). After evaluation, globalThis.AppRenderer must exist. Loading a newer renderer intentionally overwrites the previous one.

Common Types (@common/types)

Shared type definitions used across all packages. Defined in common/types/index.ts.

System types

TypePurpose
AppRenderManifestRenderer build metadata: version, buildTime, file, hash, dataSchemaVersion, cssFile, assetsBase, isCached
AppPropsData passed to renderer mount/update: manifest, renderUpdate, isCached, isStaleData, nextHash, timeToStaleData, initialState
RendererModuleRenderer API contract: mount, update?, unmount?, version?
BaselineRendererResolved renderer reference: manifest + jsUrl
RendererMetaCache metadata: active/latest with hash, version, savedAt
CoordinatedDataPer-source data struct: topSites, discovery, sponsored, weather, wallpapers, messages, widgets (all optional)
CoordinatedPayloadEnvelope: schemaVersion, updatedAt, data?
GatingPayloadTwo facets: locale (translation context) + flags (feature flag state)
LocaleFacetLocale, availability (full/partial/none), completeness, l10nHash
FlagsFacet / FlagStateResolved feature flag state with experiment metadata
CoordinatorInterfaceTyped coordinator action interface: content, top sites, search, message lifecycle
LinkTargetLink open target: current, new-tab, new-window, private
ErrorReportStructured error: source, context, reason, severity, detail
MetricReportStructured metric: source, name, value, unit, dimensions
ReportSourceShared source union for error/metric reporting
ValidationFailureBuild gate failure: layer, rule, message, artifact, detail
Message / MessageSurfaceMessaging data shape: id, surface, content

Content types

TypePurpose
DiscoverFeedFeed response: data, feeds, recommendedAt, surfaceId
DiscoveryItemIndividual content item: url, title, excerpt, publisher, imageUrl, topic
FeedMetaFeed metadata: layout, recommendations, follow state
Layout / ResponsiveLayout / TileGrid layout definitions
SponsoredData / SponsoredItemSponsored content: domain, title, url, image, ranking, caps

Enum-style constants

ConstantValues
GridTypeFLUID
TileSizeSMALL, MEDIUM, LARGE
PriorityTypeLOW, MEDIUM, HIGH
TemperatureViewSimple, Detailed, Extreme
TemperatureUnitCelsius, Fahrenheit, Kelvin

Weather types

TypePurpose
WeatherDataWeather response: cityName, currentConditions, forecast, provider
ConditionsCurrent weather: summary, iconId, temperature
ForecastFuture weather: summary, high/low temperatures
Temperature{ c: number, f: number }

Common Utilities (@common/utilities)

Small, focused, framework-agnostic helpers. Each lives in its own subdirectory.

Logger (logger/)

typescript
createBufferedLogger(opts): Logger
OptionTypePurpose
prefixstringLog line prefix
groupLabelstringConsole group label
shouldBufferbooleanBuffer output until display() is called
colorsobjectPer-level console colors
exposeGlobalAsstringOptional global reference for debugging

Methods: log(), info(), warn(), error(), display()

Values (values/)

FunctionPurpose
safeJsonParse(raw)Returns parsed JSON or null — never throws
isJsModulePath(path)Weak regex check for .js module paths

Versions (versions/)

FunctionPurpose
compareVersions(a, b)Semver comparison: returns -1, 0, or 1
inRange(version, target)Checks major.minor compatibility

Time (time/)

FunctionPurpose
getElapsedFromBaselines(...)Timer elapsed calculation from baseline timestamps
formatMMSS(ms)Formats milliseconds as MM:SS
safeRatio(a, b)Division with isFinite guard
toISOCalendarDate(date)Formats as YYYY-MM-DD

Arrays (arrays/)

FunctionPurpose
arrayToObject(arr, keyFn)Transforms array to keyed object

Coords (coords/)

FunctionPurpose
polarToCartesian(cx, cy, r, angle)Polar to cartesian conversion (for ring rendering)

State System (@data/state)

ExportModulePurpose
createSyncedStore_system/Cross-tab synced store factory
useTimertimer/Public hook for timer domain
useDiscoverdiscover/Zustand hook for discover feed
useSponsoredsponsored/Zustand hook for sponsored content

See State management for the full pattern documentation.