Architecture
ZeroStarter’s backend is built with Hono, a lightweight and ultrafast web framework for the Edge. The API runs on Bun runtime and follows a modular architecture with routers, middleware, and validation layers.Project Structure
Server Setup
The main application is configured inindex.ts:14-31:
Global Middleware
Three middleware functions are applied to all routes:- CORS: Configured for trusted origins with credentials support
- Logger: Request/response logging in development
- Rate Limiter: IP-based request throttling (see Middleware)
Error Handling
Global error handler processes unhandled errors and Zod validation failures (lib/error.ts:6-18):
Runtime Configuration
The server exports a Bun-compatible configuration (index.ts:122-125):
Environment Variables
Key configuration variables:HONO_PORT: Server port (default: 3001)HONO_TRUSTED_ORIGINS: Comma-separated list of allowed originsHONO_RATE_LIMIT: Maximum requests per windowHONO_RATE_LIMIT_WINDOW_MS: Rate limit time window in millisecondsNODE_ENV: Environment (local, development, test, staging, production)
Type-Safe Client Export
The application exports its type signature for the frontend client (index.ts:120):
hono/client.
Next Steps
- Routing - Learn about route definition and API structure
- Middleware - Implement custom middleware
- Validation - Define request/response schemas