Overview
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 |
| Configuration | Manage environment variables and app settings |
| Middleware | Transform requests and responses in the pipeline |
| Guards | Determine whether a request should be handled |
| Exceptions | Handle errors with structured HTTP responses |
| Response | Build HTTP responses with a fluent API |
| Cookies | Read incoming cookies and set response cookies |
| Testing | Test your application with the built-in TestApp |
| Decorators | The built-in decorators, how they store metadata, and how to write your own |
| Discovery Service | Find every class and method that carries a decorator at startup |
| Application Lifecycle | Init, active and shutdown phases, and graceful shutdown on signals |
| Logger | The built-in console logger, its options, and plugging in your own |
Request lifecycle
Every HTTP request in MiiaJS flows through a well-defined pipeline:
Request
-> Global middleware
-> Global guards
-> Controller 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().