Core Concepts
Learn the fundamental building blocks of a MiiaJS application.
MiiaJS is built around a few core concepts that work together to create a clean, modular application architecture.
Building blocks
| Concept | Description |
|---|---|
| Controllers | Handle incoming HTTP requests and return responses |
| Routing | How URLs are matched — static, dynamic, wildcard routes |
| Providers | Services, repositories, and other injectable classes |
| Modules | Organize the application into cohesive blocks |
| Middleware | Transform requests and responses in the pipeline |
| Guards | Determine whether a request should be handled |
| Configuration | Manage environment variables and app settings |
| Exceptions | Handle errors with structured HTTP responses |
| Response | Build HTTP responses with a fluent API |
| Static Files | Serve static assets from disk |
| Testing | Test your application with the built-in TestApp |
Request lifecycle
Every HTTP request in MiiaJS flows through a well-defined pipeline:
Request
-> Global middleware
-> Global guards
-> Controller middleware
-> Route guards
-> Route middleware
-> Validation (body/query/params)
-> Route handler
-> Response
Middleware follows a Koa-style onion model — each middleware can run code before and after the handler by wrapping await next().