Skip to content

πŸš€ An API starter with Elysia, OXC, Bun, Drizzle ORM, Neon, and built-in auth, email support, environment validation, and testing.

Notifications You must be signed in to change notification settings

jimmy-guzman/elysiajs-starter

Repository files navigation

ElysiaJS Starter

πŸš€ A production-ready API starter with Elysia, Bun, OXC, Drizzle ORM, Neon, and built-in auth, email support, environment validation, and testing.

🐣 Features

  • 🍞 bun for a blazing‑fast runtime & package manager.
  • ⚑️ Elysia for an ultra‑light, type‑safe HTTP framework.
  • 🏷️ TypeScript for end‑to‑end type safety.
  • πŸ” Better Auth for drop‑in session management.
  • πŸ“¬ Resend for sending transactional emails with ease.
  • πŸ—„οΈ Drizzle ORM for type‑safe SQL queries and schema management.
  • πŸ›’οΈ Neon for scalable, serverless Postgres with branching and edge support.
  • πŸ“¦ env-schema for runtime-safe environment variable validation.
  • πŸ§ͺ vitest for fast unit testing.
  • 🩺 OXC for linting + formatting in one tool.
  • 🩺 lefthook for lightning‑fast Git hooks.

πŸ› οΈ Installation

You can either use this template or use tiged:

bunx tiged jimmy-guzman/ts-rest-api-starter my-api
cd my-api

🏁 Getting Started

1. Install Bun

First install bun:

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

Or if you already have bun installed, upgrade to the latest stable version:

bun upgrade --stable

2. Install Dependencies

bun install

3. Set Up Neon Database

Install the Neon CLI:

bun add -g neonctl

Or with homebrew:

brew install neonctl

Login to your Neon account:

neonctl auth

Create a new project:

neonctl projects create --name "my-elysia-api"

Get your connection string:

neonctl connection-string --project-id YOUR_PROJECT_ID

4. Environment Variables

Copy the example environment file:

cp .env.example .env

The .env.example file contains:

# Database
DATABASE_URL=postgresql://username:password@host/database?sslmode=require

# Auth
BETTER_AUTH_SECRET=your-secret-key-here
GITHUB_CLIENT_ID=your-github-client-id
GITHUB_CLIENT_SECRET=your-github-client-secret

# Email
RESEND_API_KEY=your-resend-api-key
RESEND_FROM_EMAIL=noreply@yourdomain.com

Required Environment Variables

DATABASE_URL: Your Neon database connection string

  • Format: postgresql://username:password@host/database?sslmode=require
  • Get this from your Neon project dashboard

BETTER_AUTH_SECRET: A secure random string for session encryption

openssl rand -base64 33

GitHub OAuth:

  • GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET
  • Create a GitHub OAuth app at GitHub Developer Settings
  • Set callback URL to: http://localhost:3000/api/auth/callback/github

Resend Email:

  • RESEND_API_KEY: Get from Resend Dashboard
  • RESEND_FROM_EMAIL: Verified sending domain email

5. Database Setup

Run database migrations:

bun run db:migrate

Seed the database (optional):

bun run db:seed

6. Start Development Server

bun run dev

Your application will be available at:

🧞 Available Scripts

Script Description
bun run dev Start development server with hot reload
bun run test Run all tests
bun run test:coverage Run tests with coverage report
bun run test:ui Run tests with UI interface
bun run db:generate Generate Drizzle schema
bun run db:migrate Run database migrations
bun run db:push Push schema changes to database
bun run db:studio Open Drizzle Studio
bun run lint Lint code with OXC
bun run lint:fix Lint and fix code with OXC
bun run fmt Format code with OXC
bun run fmt:fix Format and fix code with OXC
bun run typecheck Check TypeScript types

πŸ“ Project Structure

β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ config/            #
β”‚   β”œβ”€β”€ db/                # Database schemas and connection
β”‚   β”œβ”€β”€ lib/               # Shared utilities (auth, email, env)
β”‚   β”œβ”€β”€ routes/            # API endpoints with tests
β”‚   β”œβ”€β”€ plugins/           # Elysia plugins
β”‚   └── index.ts           # Application entry point
β”œβ”€β”€ docs/                  # Project documentation
β”œβ”€β”€ drizzle.config.ts      # Database configuration
β”œβ”€β”€ .oxcfmtrc.json         # Format config
β”œβ”€β”€ .oxclintrc.json        # Linting config
β”œβ”€β”€ .lefthook.json         # Git hooks
└── package.json

About

πŸš€ An API starter with Elysia, OXC, Bun, Drizzle ORM, Neon, and built-in auth, email support, environment validation, and testing.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors