Architecture
ZeroStarter is built on a modern, type-safe architecture that prioritizes developer experience, performance, and maintainability. This guide explains the technical decisions, technology choices, and how everything fits together.Tech Stack
Runtime & Build System
Bun
Ultra-fast JavaScript runtime that serves as both the runtime and package manager.
- 3x faster than Node.js for most operations
- Built-in TypeScript support
- Native test runner and bundler
- Drop-in replacement for npm/yarn/pnpm
Turborepo
High-performance monorepo build system that orchestrates the entire workspace.
- Intelligent caching and parallelization
- Incremental builds
- Beautiful TUI for development
- Remote caching support
Frontend Stack
Next.js 16
React framework with App Router for building the frontend.Key Features:
- Server Components for optimal performance
- React 19 with concurrent rendering
- File-based routing
- Built-in optimizations (images, fonts, scripts)
web/next/package.json:34Tailwind CSS
Utility-first CSS framework for styling.
- Tailwind v4 with new PostCSS architecture
- Custom design tokens
- JIT (Just-In-Time) compilation
tw-animate-css for additional animationsShadcn UI
Beautiful, accessible component library built on Radix UI.
- Copy-paste components (not a dependency)
- Full TypeScript support
- Customizable with Tailwind
- WAI-ARIA compliant
Backend Stack
Hono
Ultra-lightweight web framework designed for edge runtimes.Why Hono?
- Extremely fast (3-4x faster than Express)
- First-class TypeScript support
- Works on any runtime (Bun, Node, Deno, Workers)
- Built-in RPC for type-safe client-server communication
api/hono/src/index.ts:14:Database & ORM
PostgreSQL
Production-grade relational database
- ACID compliance
- Advanced features (JSONB, full-text search)
- Excellent performance and scalability
- Wide hosting support
Drizzle ORM
TypeScript-first ORM with zero overhead
- Type-safe queries
- SQL-like syntax
- Automatic migrations
- Studio UI for database management
packages/db/src/index.ts:1):
Authentication
Better Auth provides enterprise-grade authentication with minimal setup. Features:- Multiple OAuth providers (GitHub, Google, etc.)
- Email/password authentication
- Magic link support
- Session management
- CSRF protection
- Rate limiting
packages/auth/ contains shared authentication logic used by both frontend and backend.
Data Validation
Zod provides runtime type validation and schema definition.- Define schemas once, use everywhere
- Automatic TypeScript type inference
- Parse and validate API requests/responses
- Error messages with detailed feedback
API Documentation
Scalar provides beautiful, interactive API documentation. Features (api/hono/src/index.ts:107):
- Auto-generated from OpenAPI spec
- Live API testing
- Code samples in multiple languages
- Hono/client examples for type-safe usage
http://localhost:4000/api/docs
Monorepo Structure
ZeroStarter uses a monorepo architecture organized with Turborepo workspaces:Workspace Dependencies
Packages reference each other using workspace protocol: Example (web/next/package.json:12):
Type Safety Architecture
End-to-End Type Safety with Hono RPC
One of ZeroStarter’s most powerful features is complete type safety from database to frontend.Define API Routes
Routes are defined in
api/hono/src/routers/ with full type annotations:api/hono/src/routers/v1.ts
Create Type-Safe Client
The frontend imports
AppType and creates a typed client (web/next/src/lib/api/client.ts:1):Type-Safe Environment Variables
Environment variables are validated and typed using Zod and@t3-oss/env-core.
Benefits:
- Runtime validation of environment variables
- TypeScript autocomplete
- Separate client/server variable validation
- Prevents accidental exposure of secrets
packages/env/):
Build Pipeline
Turborepo orchestrates the build process defined inturbo.json:3:
@packages/env- Environment validation (required by all)@packages/db- Database client and schema@packages/auth- Authentication logic@api/hono- Backend API server@web/next- Frontend application
- Builds packages in dependency order
- Starts dev servers with hot reload
- Shows unified logs in TUI
Key Architectural Decisions
Why Monorepo?
Shared Code
Common logic (auth, db, env) is centralized and reused across frontend and backend.
Coordinated Changes
Update API and client together in a single commit with guaranteed type safety.
Simplified Dependencies
One
node_modules, one lockfile, one version of each dependency.Unified Tooling
Single configuration for TypeScript, linting, formatting, and testing.
Why Bun?
- Speed: 3-4x faster than Node.js for most operations
- Simplicity: One tool for runtime, package management, and bundling
- Native TypeScript: No need for ts-node or separate compilation
- Modern APIs: Built-in support for Web APIs, fetch, etc.
Why Hono?
- Performance: Minimal overhead, designed for speed
- Type Safety: First-class TypeScript with RPC support
- Runtime Agnostic: Works on Bun, Node, Deno, Cloudflare Workers
- Developer Experience: Clean API, excellent documentation
Why Drizzle ORM?
- Type Safety: Queries are fully typed with TypeScript inference
- Performance: Generates optimal SQL with minimal overhead
- Developer Experience: SQL-like syntax that’s familiar and intuitive
- Tooling: Drizzle Studio provides a great database UI
Performance Optimizations
Build Performance
- Turborepo caching: Only rebuilds changed packages
- tsdown: Fast TypeScript bundler for packages
- Parallel builds: Independent packages build simultaneously
Runtime Performance
- Bun runtime: Native speed improvements
- React Server Components: Reduced JavaScript sent to client
- Hono middleware: Minimal overhead request handling
- PostgreSQL connection pooling: Efficient database connections
Development Experience
- Hot Module Replacement: Instant updates in dev mode
- Type checking: Real-time TypeScript validation
- Drizzle Studio: Visual database exploration
- API documentation: Always up-to-date with Scalar
Security Considerations
Environment Variables
Environment Variables
- Validated at runtime with Zod
- Separate client/server variables
- Never expose server secrets to client
.envexcluded from version control
Authentication
Authentication
- CSRF protection via Better Auth
- Secure session management
- HTTP-only cookies
- Rate limiting on auth endpoints
API Security
API Security
- CORS configured for trusted origins
- Rate limiting middleware
- Input validation with Zod
- Authenticated routes with middleware
Database Security
Database Security
- Connection pooling with timeouts
- TLS/SSL in production
- Prepared statements (SQL injection prevention)
- No raw SQL queries
Next Steps
Project Structure
Explore the detailed file and folder organization.
Type-Safe API
Learn how to use Hono RPC for building APIs.
Database Schema
Understand the database structure and how to extend it.
Deployment
Deploy your application to production.