Skip to content

theogravity/bun-elysiajs-starter-turbo-monorepo

Repository files navigation

Bun ElysiaJS Turbo Monorepo Starter

A starter project for building a full-stack application using Bun, TypeScript, ElysiaJS, Kysely with Postgres, and React.

This project uses Bun as its runtime and package manager. Bun provides faster installs, native TypeScript execution, and improved performance over Node.js.

Requirements

  • Bun >= 1.0.0
  • Docker (for local Postgres and testing)

Features

  • Bun-powered - Uses Bun for package management, script execution, and runtime.
  • ElysiaJS API server with TypeScript.
  • React frontend with TanStack Router and TanStack Query.
  • Monorepo setup using turbo and Bun workspaces.
  • OpenAPI docs via Scalar UI at /docs.
  • Type-safe client SDK via Eden Treaty.
  • Sample REST tests using Vitest.
  • Sample database migrations and repositories using Kysely.
  • Shared error handler package for consistent API error responses.
  • Code generators using turbo gen to scaffold new API endpoints and database tables.

Packages

Package Description
apps/backend ElysiaJS API server
apps/frontend React frontend (Vite, TanStack Router, TanStack Query, Tailwind CSS)
packages/backend-client Type-safe Eden Treaty client generated from the backend
packages/backend-errors Shared error types and handler for the backend
packages/tsconfig Shared TypeScript configuration

Libraries and tools used

Setup

  1. Install Bun (if not already installed):

    curl -fsSL https://bun.sh/install | bash
  2. Install dependencies:

    bun install
  3. Copy the example env file:

    cp apps/backend/.env.example apps/backend/.env
  4. Start the local Postgres server:

    docker compose up -d
  5. Run database migrations:

    bun run db:migrate:latest

Development

turbo watch dev
Service URL
API server http://localhost:3080
OpenAPI docs http://localhost:3080/docs
Frontend http://localhost:5173
PGAdmin http://localhost:5050

Testing

Requires Docker — uses Testcontainers to spin up a temporary Postgres instance per test run.

turbo test

Build

turbo build

Generate scaffolding

Generators for new API endpoints + tests and database tables + repositories:

turbo gen

Using the API Client

The @internal/backend-client package provides a type-safe Eden Treaty client:

import { createBackendClient } from '@internal/backend-client'

const api = createBackendClient('http://localhost:3080')

const { data, error, status } = await api.users.email.post({
  givenName: 'John',
  familyName: 'Doe',
  email: 'john@example.com',
  password: 'securepass123',
})

Database migrations

bun run db:migrate:create   # Create a new migration
bun run db:migrate:latest   # Apply all pending migrations
bun run db:migrate:undo     # Roll back the last migration

Update all dependencies

bun run syncpack:update

Troubleshooting

turbo watch dev — daemon connection errors

× failed to connect to daemon
╰─▶ server is unavailable: channel closed

or

× discovery failed: bad grpc status code: The operation was cancelled

Run turbo daemon clean and try again. If the second error persists, wait a minute and retry.

Related: vercel/turborepo#8491

About

A starter monorepo for building APIs with Bun, ElysiaJS, Kysely, and Turborepo — includes Eden Treaty client SDK, OpenAPI docs, code generators, and Testcontainers-based testing.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors