Type-safe Bun API template built with Elysia, Better Auth, Drizzle, Postgres, and Redis.
- Bun
- Elysia
- Better Auth
- Drizzle ORM
- PostgreSQL
- Redis
- OpenAPI via
@elysia/openapi - OpenTelemetry
- Oxlint + TypeScript strict mode
- Typed environment loading in
src/start/env.ts - Session-based auth with Better Auth
- Todo CRUD module
- OpenAPI docs at
/docs - Redis-backed Drizzle cache integration
- Strict TypeScript and lint rules
- Bun
- PostgreSQL
- Redis
Create a .env file with:
DATABASE_URL=postgres://user:password@localhost:5432/app
REDIS_URL=redis://localhost:6379These are validated on startup by src/start/env.ts.
bun installbun run devThe app listens on http://localhost:3000.
Build the image:
docker build -t elysia-template .Run the container:
docker run --rm -p 3000:3000 \
-e DATABASE_URL="postgres://user:password@host.docker.internal:5432/app" \
-e REDIS_URL="redis://host.docker.internal:6379" \
elysia-templateThe container includes a healthcheck against GET /.
bun run dev- start the app in watch modebun run build- build the server binarybun run lint- run oxlintbun run lint:fix- run oxlint with fixesbun run format- format the repobun run format:check- check formattingbun run check- format, lint, and build
GET /- health check
- Better Auth routes are mounted under
/auth - OpenAPI auth paths are exposed under
/auth/api
All todo routes require authentication.
GET /todos- list current user todosPOST /todos- create a todoPUT /todos/:id- replace a todoPATCH /todos/:id- partially update a todoDELETE /todos/:id- delete a todo
- UI:
http://localhost:3000/docs - JSON:
http://localhost:3000/docs/json
src/
contracts/ Shared abstractions and errors
adapters/ External integrations like Redis and Drizzle cache
modules/ Feature modules such as todo and healthcheck
start/ App bootstrap, auth, db, cache, env
utils/ Shared helpers
- Todo not-found cases return
404 - The app uses a typed
envobject instead of readingprocess.envthroughout the codebase - Better Auth OpenAPI output is merged into the main Elysia OpenAPI document