Core Concepts / Overview

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

ConceptDescription
ControllersHandle incoming HTTP requests and return responses
RoutingHow URLs are matched - static, dynamic, wildcard routes
ProvidersServices, repositories, and other injectable classes
ModulesOrganize the application into cohesive blocks
ConfigurationManage environment variables and app settings
MiddlewareTransform requests and responses in the pipeline
GuardsDetermine whether a request should be handled
ExceptionsHandle errors with structured HTTP responses
ResponseBuild HTTP responses with a fluent API
CookiesRead incoming cookies and set response cookies
TestingTest your application with the built-in TestApp
DecoratorsThe built-in decorators, how they store metadata, and how to write your own
Discovery ServiceFind every class and method that carries a decorator at startup
Application LifecycleInit, active and shutdown phases, and graceful shutdown on signals
LoggerThe 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().

Edit this page on GitHub