A starter project for building an API server using Bun, Typescript, Fastify v5, and Kysely with Postgres.
This project uses Bun as its runtime and package manager. Bun provides faster installs, native TypeScript execution, and improved performance over Node.js.
- Bun-powered - Uses Bun for package management, script execution, and runtime.
- Fastify v5 with Typescript.
- Monorepo setup using
turboand Bun workspaces. - Outputs OpenAPI schema for the API and has a web UI for viewing it.
- A sample REST test is included using Vitest.
- Sample database migrations / repositories are included using Kysely.
- An client SDK package is included to generate typescript client code from the API schema.
- An error handler package is included to handle errors and return a consistent response.
- Code generators using
turbo gento create new API endpoints and database tables.
typescriptbunfor package management and runtimecommitlintfor commit message lintingturbofor monorepo managementfastifyfor the API server frameworkhash-runnerfor caching buildskyselyfor the database query builderpostgres+ pgAdmin for the databasetestcontainersfor testing with a sandboxed postgres instancevitestfor endpoint testingloglayerfor formatted loggingbiomefor linting and formattingsyncpackfor keeping package versions in syncHey APIfor generating the backend SDK using the generated OpenAPI schema from the backend
-
Install Bun (if not already installed):
curl -fsSL https://bun.sh/install | bash -
Install dependencies:
bun install
-
Copy
apps/backend/.env.exampletoapps/backend/.env
Start local postgres server:
docker compose up -d
Perform database migrations:
bun run db:migrate:latest
turbo watch dev
- API server: http://localhost:3080
- OpenAPI docs: http://localhost:3080/docs
- PGAdmin: http://localhost:5050
Make sure docker is running as it uses testcontainers to spin up a
temporary postgres database.
turbo test
turbo build
Generators for the following:
- New API endpoints + tests
- Database tables and repositories
turbo gen
- Create a migration:
bun run db:migrate:create - Run migrations:
bun run db:migrate:latest - Rollback migrations:
bun run db:migrate:undo
bun run syncpack:update
• Packages in scope: @internal/backend, @internal/backend-client, @internal/backend-errors, @internal/tsconfig
• Running dev in 4 packages
• Remote caching disabled
× failed to connect to daemon
╰─▶ server is unavailable: channel closed
Try:
turbo daemon clean
Then try running turbo watch dev again.
If you get:
• Packages in scope: @internal/backend, @internal/backend-client, @internal/backend-errors, @internal/tsconfig
• Running dev in 4 packages
• Remote caching disabled
× discovery failed: bad grpc status code: The operation was cancelled
Wait a few minutes and try again.
Related: