Skip to content

compile-time-first · serverless · typed end to end

ϟ smite

Describe your API once, as plain values. Smite compiles that description into a validated server, a typed client and an OpenAPI document, then ships only the runtime.

Zod schemas drive validation, handler types and every generated artifact. The build-time registry folds out of production bundles, so what you deploy is small and fast.

pets-api — smite
▸ routes, zod inputs and handlers as plain values
import { http } from "@smitejs/http";
import { z } from "zod";

export const app = http.app("pets");

const pets = http.router().input({
  params: z.object({ id: z.coerce.number() }),
});

pets.accept("GET", "/pets/:id").handler((ctx) => ({
  status: 200,
  body: { id: ctx.params.id, name: "Rex" },
}));

app.use(pets);
[ ] switch file • tab next • src/app.ts

One description, many artifacts ​

Routes, inputs and handlers are plain values. Smite collects them at build time into a typed graph, and every artifact you need is generated from that one graph, so they can never drift apart.

Write the API, not the plumbing ​

A route declares its zod inputs once. The handler receives validated, typed values; bad input is answered with a 400 before your code runs.

ts
const app = http.app("wiki");
const routes = http.router().input({
  query: z.object({ language: z.string() }).partial(),
  params: z.object({ slug: z.string() }),
});
app.use(routes);
ts
1

Built at compile time, shipped as a runtime ​

Compile time and runtime

Collection runs only while the compile-time flag is true. Production bundles fold it to false, and esbuild drops the registry, the collectors and the generators. Read How it works for the full picture.

Every package, one dependency direction ​

packagewhat it gives you
@smitejs/httpapps, routers, zod-validated endpoints, aspects, serve and serveNode
@smitejs/clientbuild-time typed client generation and its tiny fetch runtime
@smitejs/openapiOpenAPI 3.1 generator plugin and Swagger UI router
@smitejs/envdeclared, validated environment variables
@smitejs/domainvalue objects, entities, specifications, ports and usecases
@smitejs/fpOption, Result, Either, Task, Matcher, flow
@smitejs/clismite dev, smite build, smite generate and the plugin host
@smitejs/corethe registrar: descriptors, edges and the compile-time flag

See them all in the API reference.

Two minutes to a running API ​

bash
yarn create smite-app hello-api
cd hello-api
yarn smite dev          # generators + node:http server with auto-reload
curl "http://127.0.0.1:3000/hello?name=Ada"

Then follow First steps.

Released under the MIT License.

/ search•[ ] prev/next•j/k scroll•h home•t theme•home