Project Structure
Mayari follows strict conventions for routing and project setup. Some parts of the structure are required for Mayari to build and run your app, while others are recommended practices to keep your codebase clean as you scale.
Required Structure
When you create a project using Mayari CLI, these files and folders are set up automatically because Mayari expects them in specific locations:
my-app/
├── ember.toml <-- Project & dependency configuration
└── src/
├── main.luau <-- REQUIRED: Entry point (starts the server)
└── app/ <-- REQUIRED: Routing root directory
└── route.luau <-- REQUIRED: Root endpoint ("/")The Strict Rules:
Entry File (
src/main.luau): Must be located at src/main.luau. This is the entry point Mayari CLI looks for when building your project.Routing Root (
src/app/): All route files must live inside src/app/. Mayari specifically targets src/app and ignores any app/ folder outside of src.Route Naming (
route.luau): An endpoint is only recognized if the file is named exactly route.luau.Attribute Middleware Directories: If you use route attributes, Mayari looks specifically in these exact folders to resolve them:
src/guards/— For authorization & access control rules (--@Guard(...)).src/interceptors/— For response formatting and logging (--@Interceptor(...)).src/validators/— For request body validation schemas (--@Validator(...)).
Recommended: Global Configuration (src/config/)
For app-wide configurations, like database connection pools, rate limiters, or CORS settings, we recommend creating a src/config/ directory:
src/
├── main.luau
├── config/
│ ├── db.luau <-- Database connection setup
│ └── cors.luau <-- Global CORS middlewareIMPORTANT
Files in src/config/ are not automatically loaded. You must manually require them inside src/main.luau so they trigger right when the server starts:
local Mayari = require("mayari") -- This should always be at the top
require("./config/db")
require("./config/cors")
local app = Mayari.new(8080)
app:listen(function()
print("Server running on port 8080")
end)Recommended Structure: Feature-Based Co-location
Now, what about the rest of your app's code, like database calls, business logic, or type definitions?
If you've used frameworks like Spring Boot or NestJS, you're probably familiar with feature modules grouping controllers, services, and schemas together in one place:
users/
├── users.module.ts
├── users.service.ts
└── users.controller.tsMayari makes this feature-based layout effortless. Because Mayari only registers files named route.luau as public endpoints, any other file placed inside a route folder is ignored by the router.
We strongly recommend co-locating your feature-specific logic directly alongside your route.luau:
src/
├── main.luau
└── app/
├── route.luau <-- Handles GET/POST for "/"
└── users/
├── route.luau <-- Public endpoint for "/users"
├── users.service.luau <-- Private: Business & DB logic
└── users.types.luau <-- Private: Type definitionsWhy Do This?
Everything in One Place: If you need to tweak how users are fetched, you don't have to jump between distant
services/androutes/directories.Router Safe: Mayari strictly ignores
users.service.luauandusers.types.luau, so your backend logic is never exposed as an endpoint.Scales Cleanly: As your API grows to dozens of endpoints, each feature stays completely self-contained.
Summary Cheat Sheet
| Path | Requirement Level | Purpose |
|---|---|---|
src/main.luau | Required | Entry point executed by Mayari to launch your app. |
src/app/ | Required | The directory Mayari scans for API endpoints. |
route.luau | Required | The exact filename required to activate a URL route. |
src/guards/ | Required(if used) | Folder holding guard attribute definitions. |
src/interceptors/ | Required(if used) | Folder holding interceptor attribute definitions. |
src/validat/ | Required(if used) | Folder holding validator attribute definitions. |
*.service.luau | Recommended | Co-located business logic placed alongside route.luau. |
*.types.luau | Recommended | Co-located Luau type declarations for that feature. |
src/config/ | Recommended | Holds global configs (DB, CORS). Must be required in src/main.luau. |