An enterprise-grade Bun + Hono + GraphQL Yoga + Drizzle ORM (PostgreSQL 17) + Redis starter designed for high-performance SaaS backends.
- β‘οΈ Bun Runtime β Instant startup and high throughput.
- π Hono HTTP Framework β Webhook routers (
/webhooks/stripe), CORS, security headers, and health probes (/health). - π GraphQL Yoga 5 β Fast, standards-compliant GraphQL engine with interactive Studio.
- π Drizzle ORM + PostgreSQL 17 β End-to-end type safety with native UUIDs, timestamps, and relational queries.
- π΄ Redis L2 Caching & PubSub β Multi-key DataLoader caching to eliminate N+1 database queries.
- π¦ Feature Module Pattern β Clean co-location of
types,resolvers,services, andloaders. - π JWT Authentication & Guards β Token verification via
josewithrequireAuth()andrequireRole(). - π‘οΈ
GraphQLExceptionv2 β Typed error handling mapped to standard HTTP status codes. - π Dual-Mode Structured Logger β Pretty colored terminal in development, single-line structured JSON in production.
- π³ Docker Compose β 1-command startup for PostgreSQL 17 and Redis 7.
src/
βββ index.ts # Hono HTTP router + Yoga mount + Webhooks + Bun.serve
βββ env.ts # Zod-validated environment variables
β
βββ lib/
β βββ auth/jwt.ts # Fast JWT signing & verification (jose)
β βββ error/exceptions.ts # Typed GraphQLException with HTTP status mapping
β βββ redis/index.ts # Singleton Redis connection client
β βββ utils/logger.ts # Dual-mode structured logger
β
βββ db/
β βββ index.ts # Drizzle PostgreSQL client (postgres-js)
β βββ schema/ # PostgreSQL table definitions & Drizzle-Zod schemas
β βββ migrations/ # Generated SQL migration files
β βββ migrate.ts # Programmatic migration runner
β
βββ graphql/
βββ context.ts # GraphQL Context (db, user, requireAuth, loaders)
βββ schema.ts # Root schema merger
β
βββ modules/
βββ task/ # π¦ Feature Module
βββ task.types.ts # GraphQL TypeDefs & Pagination inputs
βββ task.services.ts # Atomic 1-query business logic (.returning())
βββ task.resolvers.ts # Resolvers with unmasked error handling
βββ task.loader.ts # Batched DataLoader with Redis L2 cache
bun installbun run db:upbun run db:migratebun run dev- β‘ GraphQL Studio: http://localhost:3000/graphql
- π API Status: http://localhost:3000/
- π©Ί Health Check: http://localhost:3000/health
main(Flagship): Full SaaS architecture with PostgreSQL 17, Redis, Docker Compose, and Hono.sqlite: Minimalist zero-Docker version running on embedded SQLite.
| Command | Description |
|---|---|
bun run dev |
Start development server with hot-reloading |
bun run db:up |
Start PostgreSQL 17 and Redis Docker containers |
bun run db:down |
Stop Docker containers safely |
bun run db:logs |
View real-time database and redis logs |
bun run db:generate |
Generate new Drizzle SQL migration files |
bun run db:migrate |
Execute pending database migrations |
bun run db:studio |
Open interactive Drizzle Studio in browser |
bun run typecheck |
Run TypeScript compiler type check |
bun run format |
Format codebase with Biome |
bun run lint |
Check and fix lint issues with Biome |
PORT=3000
NODE_ENV=development
DEBUG=1
# Database & Redis
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/breeze_db
REDIS_URL=redis://localhost:6379
# Authentication
JWT_SECRET=super-secret-key-change-in-production-min-32-chars-longBreeze uses GraphQLException mapped to standard HTTP status codes:
// In your services or resolvers:
throw GraphQLException.notFound("Task not found");
throw GraphQLException.unauthenticated("Authentication required");
throw GraphQLException.forbidden("Admin access only");
throw GraphQLException.badInput("Invalid task name");MIT Β© Mohamed