Skip to content

LynAPI, database and auth. One install.

A Bun backend that comes already wired. No ORM to set up, no pool to create, no middleware to glue. Install it and write your routes.

From zero to a database-backed API ​

1. Install

bash
bun add @rouret/lyn

2. Point it at Postgres

bash
# .env
DATABASE_URL=postgres://localhost:5432/app

3. Write your routes

ts
import { Lyn, z } from "@rouret/lyn";
import * as schema from "./db/schema";

await new Lyn({ database: { schema } })
  .get("/users", ({ db }) => db.query.users.findMany())
  .post(
    "/users",
    async ({ db, body }) => {
      const [user] = await db.insert(schema.users).values(body).returning();
      return user;
    },
    { body: z.object({ email: z.email(), name: z.string() }) }
  )
  .listen(3000);

That's the whole app. The connection is checked at startup, db is typed from your tables, invalid bodies get a 400.

What you don't have to do ​

UsuallyWith Lyn
Install an ORM, a driver, and create a connection poolPass your schema
Make db available in every handlerIt's in the context
Check the database is reachable before servingDone by listen()
Validate env variables, and find a missing one in productionChecked and typed at startup
Write a validation middleware and type the request by handZod schemas, types inferred
Write an error handler, and avoid leaking stack tracesOne JSON error format, nothing leaks
Set up request logging and request idsOne line per request, built in
Pick, install and wire an auth libraryBuilt in, coming next

Authentication coming next ​

Sign-up, sign-in and sessions, stored in the same Postgres database, with nothing to install or configure. It is the next feature on the roadmap.

Ready when you are ​

Released under the MIT License.