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:
- creates the configured system logger;
- compiles decorated and dynamic modules into immutable definitions;
- validates module identity, imports, exports, and provider dependencies;
- creates the singleton dependency container;
- creates one Elysia application with the requested
aotandprecompilepolicy; - applies
configureNative, when supplied; - initializes providers and mounts imported Elysia plugins in dependency order;
- instantiates controllers, registers compiled decorated routes directly, and mounts low-level controller plugins when required;
- waits for Elysia modules;
- 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:
| Method | Purpose |
|---|---|
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.