LCMD db logoLCMD[db]

API integration

Guide to backend API integration and usage

Overview

The API integration uses:

  • OpenAPI schema generation with drf-spectacular
  • Generated TypeScript clients in @lcmd/api via @hey-api/openapi-ts
  • Shared client setup, request helpers, and TanStack Query hooks in @lcmd/logic
  • Scalar for interactive API documentation

API versioning

The API follows a versioned URL structure:

EndpointDescription
/api/v1/API v1 endpoints
/api/v1/schema/OpenAPI schema for v1
/api/v1/docs/Interactive API documentation (Scalar)

Legacy URLs (/api/schema/, /reference/) redirect to the v1 equivalents for backward compatibility.

API documentation

Access the interactive API documentation at:

The documentation is powered by Scalar and provides:

  • Interactive request builder
  • Code examples in multiple languages
  • Schema exploration

API clients

packages/api contains generated clients for both backend surfaces:

  • @lcmd/api: DRF API client, SDK functions, types, Zod schemas, and TanStack Query options
  • @lcmd/api/allauth: django-allauth headless browser API client, SDK functions, types, Zod schemas, and TanStack Query options

Application code should usually consume the higher-level helpers in @lcmd/logic instead of configuring generated clients per call site. @lcmd/logic/clients centralizes base URL, cookie credentials, CSRF headers, and unauthorized handling.

Schema management

Updating OpenAPI schemas

After backend changes, regenerate the committed schemas and TypeScript clients:

pnpm turbo run codegen --filter=@lcmd/api

This runs the backend schema generator, writes packages/api/schema.yaml and packages/api/allauth-schema.yaml, then regenerates packages/api/src/.

Client-side requests

For web app API requests:

  • Use TanStack Query through @lcmd/logic query hooks and request helpers
  • Keep generated API calls inside reusable domain modules
  • Let the configured clients handle same-origin cookies and CSRF headers

On this page