ADR-0004: OpenAPI-first client and TanStack Query
Status: Accepted
Date: 2026-06-24
Context
Frontend applications need typed API contracts, JWT refresh behaviour, caching, mutations, and a single place for transport concerns.
Decision
- NestJS Swagger at
/swagger/jsonis the contract source. @bitrate/contractsgenerates TypeScript paths from the running API.apps/web-player/src/shared/api/client/fetchClient.tsownsopenapi-fetchtransport and JWT refresh middleware.reactQueryClient.tswraps it withopenapi-react-query.- Server state belongs in TanStack Query; components do not fetch through ad-hoc effects.
- Raw
fetch/Axios calls are permitted only in explicit infrastructure adapters where the shared client cannot represent the requirement.
Consequences
Contract changes require regeneration. Consumers receive endpoint-derived types and shared auth behaviour rather than hand-maintained response interfaces.
Alternatives considered
- Axios with generated resource modules — rejected because this repository already has an OpenAPI Fetch pipeline.
- Hand-written request hooks — rejected where generated endpoint typing is available.