Route Organization
Routes are organized into modular routers mounted at different base paths:/api/auth/*- Authentication endpoints (Better Auth)/api/v1/*- Protected API endpoints (require authentication)/api/health- Health check endpoint/api/docs- API documentation (Scalar)/api/openapi.json- OpenAPI specification
System Routes
Root-level routes for system information (index.ts:34-44):
Health Check Endpoint
Documented health check with OpenAPI metadata (index.ts:46-88):
Authentication Router
The auth router delegates all routes to Better Auth (routers/auth.ts:4-6):
GET /api/auth/get-session- Retrieve current sessionPOST /api/auth/sign-in/email- Email sign-inPOST /api/auth/sign-up/email- Email sign-up- And all other Better Auth endpoints
Protected API Router (v1)
The v1 router requires authentication for all routes (routers/v1.ts:29-32):
Session Endpoint
Returns the current authenticated session (routers/v1.ts:33-65):
User Endpoint
Returns the current authenticated user (routers/v1.ts:66-98):
OpenAPI Documentation
The API automatically generates OpenAPI specification (index.ts:91-105):
Scalar API Reference
Interactive API documentation using Scalar (index.ts:106-118):
http://localhost:3001/api/docs.
Code Samples in Documentation
Routes include TypeScript code samples usinghono/client (index.ts:52-61):
Type-Safe RPC Export
The routes object is exported as a type for frontend consumption (index.ts:120):
hono/client in your frontend:
Adding New Routes
To add a new route:- Create a new router file in
routers/ - Define routes with
describeRoutefor documentation - Export the router from
routers/index.ts - Mount it in
index.tsusing.route()
Next Steps
- Middleware - Add authentication and rate limiting
- Validation - Define request/response schemas