Architecture
Backend Runtime Core (`dsarInstance`)
Alpha
DSAR is currently in alpha. APIs, package surfaces, configuration, and documentation may change as the project evolves.
This document captures T05 runtime boundaries, route surface, and error contract for integrators.
Runtime usage
- Factory:
dsarInstance(options) - Primary boundary:
handler(request) => Promise<Response> - Mounting: any fetch-compatible runtime (Workers, Bun, Node adapters)
- Runtime internals:
@effect/platformweb handler boundary viaHttpApp.toWebHandler - Runtime repo integration:
runtimeReposFromPersistence()bridges@dsar/persistenceintoRuntimeServicesTag
Route module map and ownership
packages/backend/src/routes/init.ts- runtime initialization surfacepackages/backend/src/routes/requests.ts- request lifecycle and capability-upgrade route categories (stubbed in T05)packages/backend/src/routes/subjects.ts- subject lookup placeholder surfacepackages/backend/src/routes/policies.ts- policy upgrade placeholder surfacepackages/backend/src/routes/status.ts- health/status surface
Representative capability-upgrade paths mounted in T05:
/requests/:id/clock/explain/requests/:id/verification/*/requests/:id/fulfilment/callback/requests/:id/appeals*/tenants/:tenantId/retention/requests/:id/audit/export
Error envelope contract
All errors follow:
ok: falseerror.id: string(stable backend identifier,DSAR-BE-xxxx)error.code: string(deterministic boundary code, e.g.AUTH_ACTOR_CONTEXT_MISSING,REQUEST_VALIDATION_FAILED,REQUEST_ROUTE_NOT_FOUND)error.docsUrl: string(canonical link to error catalog entry)error.message: stringerror.status: numbererror.trace?: object(safe metadata only)
Canonical catalog: docs/architecture/error-codes.md
Base path behavior
options.basePathnormalizes trailing slashes.- Incoming request paths are stripped against
basePathbefore route matching. - Non-matching base path requests return normalized
REQUEST_ROUTE_NOT_FOUND. - Matching requests continue through shared auth/context handling and normalized envelope conversion.
Contract and docs endpoints (T06)
- Runtime exposes generated OpenAPI at
/spec.json. - Runtime exposes interactive docs at
/docs. - Both endpoints honor
basePathmounting, e.g./api/v1/spec.jsonand/api/v1/docs. - Spec generation is driven from
packages/backend/src/http-api/api.tsHttpApi contracts.