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

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
MiddlewareTransform requests and responses in the pipeline
GuardsDetermine whether a request should be handled
ConfigurationManage environment variables and app settings
ExceptionsHandle errors with structured HTTP responses
ResponseBuild HTTP responses with a fluent API
Static FilesServe static assets from disk
TestingTest 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().