A minimal Elysia template with file-based routing and MongoDB integration, inspired by frameworks like Next.js and Nuxt.
- 📁 File & folder based routing
- 🔀 Automatic HTTP method detection from filenames
- 🧩 Nested routes support
- ✅ Optional request validation using
schema(Elysia + TypeBox) ⚠️ Global error handling (400 / 404 / 500)- 🪵 Built-in logger
- 🍃 MongoDB ready (connection handled at app level)
All routes live inside the routes/ directory.
Example:
routes/
├─ index.get.js → GET /
├─ users/
│ ├─ index.get.js → GET /users
│ ├─ index.post.js → POST /users
│ └─ [id].get.js → GET /users/[id]
*.get.js,*.post.js, etc.- Or
get.js,post.js,index.get.js indexfiles map automatically to the parent path
Each route file must export a default handler.
You can optionally export a schema for validation.
export const schema = {
body: t.Object({
email: t.String({ format: 'email' })
})
}
Global error handling is configured for common cases:
VALIDATION→ 400 Bad RequestNOT_FOUND→ 404 Not Found- Other errors → 500 Internal Server Error
Errors are automatically logged.
The template is designed to work with MongoDB. Database connection is initialized once and shared across routes.
- The router scans the
routesdirectory at startup - Routes are registered automatically
- Schemas are applied when present
Provide a clean, simple, and extensible starting point for building Elysia APIs with MongoDB and a maintainable routing structure.