Busflow Docs

Internal documentation portal

Skip to content

Domain Schemas (@busflow/types/schemas)

This directory contains domain validation schemas using Valibot. We use a defense-in-depth strategy:

  1. PostgreSQL enforces structural integrity at the database layer.
  2. GraphQL Codegen enforces compile-time structural type correctness across the application.
  3. Valibot enforces runtime validation rules (string lengths, regex patterns, number ranges) when data crosses boundaries (e.g., forms, APIs).

The Drift Guard Pattern

When you write a Valibot schema for a database entity, it must be locked to the corresponding GraphQL type generated from Hasura.

We accomplish this using a satisfies type assertion:

typescript
import * as v from 'valibot';
import type { Backoffice_Vehicles } from '../generated/graphql.js';

export const VehicleSchema = v.object({
  // ... rules ...
});
export type Vehicle = v.InferOutput<typeof VehicleSchema>;

// Compile-time drift guard
const _driftCheck: Vehicle satisfies Pick<
  Backoffice_Vehicles,
  'id' | 'tenant_id' | 'license_plate' 
  // etc...
> = undefined as never;

If the database column is modified from license_plate to licence_plate, the codegen will update Backoffice_Vehicles, and the satisfies guard will instantly break the build. This guarantees that your Valibot schemas never drift from your actual database structure!

Internal documentation — Busflow