FORM FOLLOWS DOMAIN. DOMAIN COMES FIRST.NODE.JS / REACT
OPENAPI → CLIENT → HOOKS

FROM API
TO HOOKS.

@domain-first/project-structure

Configure a typed TanStack Query client from your OpenAPI document, with a shared fetch boundary and a React query provider.

01OpenAPI-driven hooks
02A shared fetch mutator
03A generated QueryProvider
01 / ENABLE

Connect the document to React.

Enable React and include @domain-first/handlers-rest in Project Structure configuration. Run the CLI and select Add integration → Orval (React Query client). Both settings are required for this menu item.

Terminal
npx df-ps

Choose the OpenAPI document path. When the OpenAPI integration has created a generation script, its document location supplies the default.

02 / OUTPUT

A client boundary you own.

Generated filesExample with rootFolder: src
src/presentation/react/data-layer/
  orval.config.ts
  api-client/mutator.ts
  query-provider.tsx
  orval/  # hooks and models after client generation

The config generates TanStack Query v5 hooks using fetch, grouped by API tags, with schemas in the generated model folder. With Next declared, request URLs start with NEXT_PUBLIC_API_BASE_URL.

customInstance in the mutator handles every request and throws an ApiError containing the status and parsed response body on non-2xx responses. Add authentication, token refresh and shared request behavior here. QueryProvider supplies one QueryClient per browser session; wrap your app in it.

The mutator and provider are starting points and are preserved on repeated setup. The generated orval directory is added to .gitignore.

03 / GENERATE

Refresh the API, then the client.

Install missing dependencies using the commands printed by the CLI: TanStack React Query for runtime and Orval as a development dependency. Then run:

Terminal
npm run openapi
Terminal
npm run client:orval

Import generated hooks and models from your data-layer/orval directory. Customize the mutator and application components, and regenerate the client when endpoint contracts change.

GENERATED VS OWNED

Orval produces the hooks and models when client:orval runs. Project Structure prepares the config, mutator, provider and script; it does not execute those commands for you.