11) Cloudflare Runtime Boundary
Section titled “11) Cloudflare Runtime Boundary”Keep Cloudflare runtime concerns (D1, KV, Queue, R2, Durable Object bindings) in runtime entry layers and dedicated adapters, not in domain/business modules.
Boundary Model
Section titled “Boundary Model”- Runtime entry points:
apps/dashboardserver functions and server adaptersworkers/*src/index.tsand infra/runtime modules
- Runtime adapter package:
packages/platform-cloudflare- Owns Cloudflare-specific helper logic for shard binding selection and runtime utility access
- Domain/business modules:
- Should accept plain values and interfaces
- Should not depend on Cloudflare binding selection details
Canonical D1 Adapter Helpers
Section titled “Canonical D1 Adapter Helpers”Use these from @legaciti/platform-cloudflare:
getD1DatabaseForOrcid(orcid, bindings)getD1DatabaseForDoi(doi, bindings)getAllD1Databases(bindings)
This keeps shard-routing ownership in one runtime-specific package.
Dashboard Runtime Adapter Layer
Section titled “Dashboard Runtime Adapter Layer”Notification queue access is localized via:
apps/dashboard/src/server/adapters/notifications-runtime.ts
Notification services call this adapter instead of reading cloudflare:workers directly.
Current Transitional Exceptions
Section titled “Current Transitional Exceptions”@platform/utilsstill exports legacy D1 helpers:getDatabaseForOrcidgetDatabaseForDoigetAllDatabases
- These exports are temporary for compatibility and should be removed after all runtime consumers migrate.
Migration Rule
Section titled “Migration Rule”When touching runtime data-access code:
- Prefer
@legaciti/platform-cloudflarefor Cloudflare-specific binding helpers. - Keep
@platform/utilsfor runtime-agnostic utilities only (normalizeDoi, patch helpers, parsing helpers, etc.). - If a module needs
getBindings()or queue/db handles, route it through a local adapter inapps/*/src/server/adaptersor worker infra runtime module.