AponiaJSDocs
Essentials

Application bootstrap

Follow AponiaFactory from a root module to a managed or native Elysia application.

AponiaFactory is exported by @aponiajs/platform-elysia. Both bootstrap methods accept a decorated module class, dynamic module, or low-level module definition.

import { AponiaFactory } from "@aponiajs/platform-elysia";
import { AppModule } from "./app.module.ts";

const application = await AponiaFactory.create(AppModule);

During creation, AponiaJS:

  1. creates the configured system logger;
  2. compiles decorated and dynamic modules into immutable definitions;
  3. validates module identity, imports, exports, and provider dependencies;
  4. creates the singleton dependency container;
  5. creates one Elysia application with the requested aot and precompile policy;
  6. applies configureNative, when supplied;
  7. initializes providers and mounts imported Elysia plugins in dependency order;
  8. instantiates controllers, registers compiled decorated routes directly, and mounts low-level controller plugins when required;
  9. waits for Elysia modules;
  10. returns either the managed wrapper or the native Elysia instance.

Creation is asynchronous because Elysia module composition is awaited. Provider factories themselves are currently synchronous.

Decorated routes are lowered into immutable plans during module compilation. The platform generates and caches fixed-arity invokers during bootstrap, so parameter metadata is not interpreted and argument arrays are not allocated on every request.

Root module

import { Module } from "@aponiajs/common";
import { GreetingModule } from "./greeting/greeting.module.ts";

@Module({
  imports: [GreetingModule],
})
export class AppModule {}

Application wrapper

The returned AponiaElysiaApplication exposes:

MethodPurpose
getNativeApplication()Access the configured Elysia instance.
handle(request)Execute an in-process request without opening a port.
listen(port)Start Bun's HTTP server.
getUrl()Read the server origin after listen().
close()Stop the server when it is running.

Calling getUrl() before listen() throws APPLICATION_NOT_LISTENING.

Native application

createNative() runs the same bootstrap pipeline and returns the composed Elysia instance directly:

export const app = await AponiaFactory.createNative(AppModule);
export type App = typeof app;

Statically visible defineModule(), defineElysiaPlugin(), and typed defineElysiaController() declarations contribute to the returned Elysia type. Decorated controller metadata remains a runtime-only contract.

See Application lifecycle and Native Elysia access. Compilation options and exact return types are in the Application API.

On this page