Skip to content

Repository files navigation

Ratchet

Ratchet

Model driven application framework: TypeScript models -> Postgres schema, codegen, and composable pipelines.

Ratchet turns a directory of TypeScript model files into a Postgres schema, a REST API, a console, and auth — with composable pipelines wherever you need custom logic.

Install

bun add @egig/ratchet

Prerequisites

  • Bun 1.3+
  • A Postgres database, reachable via a DATABASE_URL connection string

Scaffold a project

bunx @egig/ratchet init

This writes package.json, tsconfig.json, ratchet.config.ts, models/example.model.ts, migrations, and a .gitignore into the current directory. It never overwrites a file that's already there, so it's safe to re-run in a partially set-up directory.

Define a model

import { defineModel, field } from '@egig/ratchet/core';

export const Example = defineModel('examples', {
  fields: {
    name: field.string({ required: true, maxLength: 255 }),
  },
});

Generate, migrate, serve

bun run generate   # regenerate .ratchet/*, then drizzle-kit generate -> SQL migration files
bun run migrate    # drizzle-kit migrate — apply the pending SQL migration files
bun run serve       # boot the API + console

ratchet serve reads ratchet.config.ts and the generated registry and boots a listening server. It mounts, in order:

  • /api/auth/* — register/login/logout/me
  • /api/:model — the generic REST router, one route family for every model (filtering, sorting, cursor and offset pagination, ?include= relations)
  • /console — the generated console SPA

Documentation

Full guides (models & fields, pipelines, the REST API, CLI reference) are in docs/.

License

MIT

About

RATher an arCHEType, you can build something out of.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages