Skip to content

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:

bash
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:

  1. 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.

  2. 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.

  3. Route Naming (route.luau): An endpoint is only recognized if the file is named exactly route.luau.

  4. 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(...)).

For app-wide configurations, like database connection pools, rate limiters, or CORS settings, we recommend creating a src/config/ directory:

bash
src/
├── main.luau
├── config/
│   ├── db.luau                   <-- Database connection setup
│   └── cors.luau                 <-- Global CORS middleware

IMPORTANT

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:

lua
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)

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:

bash
users/
├── users.module.ts
├── users.service.ts
└── users.controller.ts

Mayari 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:

bash
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 definitions

Why Do This? ​

  • Everything in One Place: If you need to tweak how users are fetched, you don't have to jump between distant services/ and routes/ directories.

  • Router Safe: Mayari strictly ignores users.service.luau and users.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 ​

PathRequirement LevelPurpose
src/main.luauRequiredEntry point executed by Mayari to launch your app.
src/app/RequiredThe directory Mayari scans for API endpoints.
route.luauRequiredThe 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.luauRecommendedCo-located business logic placed alongside route.luau.
*.types.luauRecommendedCo-located Luau type declarations for that feature.
src/config/RecommendedHolds global configs (DB, CORS). Must be required in src/main.luau.