Skip to content

6pbuhq/elysia-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

elysia-template

A minimal Elysia template with file-based routing and MongoDB integration, inspired by frameworks like Next.js and Nuxt.

Features

  • 📁 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)

Routes structure

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]

Naming conventions

  • *.get.js, *.post.js, etc.
  • Or get.js, post.js, index.get.js
  • index files map automatically to the parent path

Route handler

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' })
  })
}

Error handling

Global error handling is configured for common cases:

  • VALIDATION → 400 Bad Request
  • NOT_FOUND → 404 Not Found
  • Other errors → 500 Internal Server Error

Errors are automatically logged.

MongoDB

The template is designed to work with MongoDB. Database connection is initialized once and shared across routes.

Usage

  • The router scans the routes directory at startup
  • Routes are registered automatically
  • Schemas are applied when present

Goal

Provide a clean, simple, and extensible starting point for building Elysia APIs with MongoDB and a maintainable routing structure.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors