Skip to content
ContractSpec
Start here
AI index

Contract-first API

Design APIs by writing contracts first, then generate consistent implementations across frameworks.

Problems Solved

  • API drift between frontend and backend

  • Inconsistent error handling across endpoints

  • Documentation becomes outdated quickly

  • Manual OpenAPI maintenance is error-prone

Solutions

  • Single source of truth for API contracts

  • Generate OpenAPI and SDKs from contracts

  • Type-safe request/response validation

  • Always-in-sync documentation

Quick Start

Define your first API contract and generate consistent implementations.

typescript
import { defineOperation } from '@lssm-tech/lib.contracts-spec/operations';
import { SchemaModel, ScalarTypeEnum } from '@lssm-tech/lib.schema';

export const CreateUserOperation = defineOperation({
  goal: 'Create a new user account with validation',
  context: 'Used by frontend registration forms and internal admin tools',
  input: new SchemaModel({
    type: 'object',
    properties: {
      email: {
        type: 'string',
        format: 'email',
        required: true,
      },
      password: {
        type: 'string',
        minLength: 8,
        required: true,
      },
    },
  }),
  output: new SchemaModel({
    type: 'object',
    properties: {
      id: { type: 'string', required: true },
      email: { type: 'string', required: true },
      createdAt: { type: 'string', format: 'date-time', required: true },
    },
  }),
  metadata: {
    name: 'createUser',
    tags: ['users', 'auth'],
    description: 'Create a new user account with email and password',
  },
});

Generate OpenAPI

Export OpenAPI documentation directly from your contracts.

bash
contractspec openapi export \
  --registry ./src/contracts/registry.ts \
  --out ./openapi.json