Deployment
Build TypeScript before productionhile start. In development, hile start --dev imports src/**/*.boot.ts; in production it imports dist/**/*.boot.js.
Runtime And Lifecycle Notes
defineService(key, fn)registers a service factory and does not execute it.loadService(service)executes the factory on first call and returns the cached value afterwards.- The
shutdowncallback registers teardown functions; they run in LIFO order. - The container tracks dependencies when service factories call
loadService(). container.shutdown()triggers registered teardowns.@hile/bootstraploads env files first, setsNODE_ENV, imports auto-load packages, scans boot files, and installs exit hooks.@hile/logger.createLogger()returns{ logger, teardown }.@hile/ioredis.createRedis()waits forconnect.@hile/typeorm.createDataSource()initializes a TypeORMDataSource.
Runtime And Lifecycle Notes
HttpNextkeeps its internalHttpinstance private and exposes onlyuse(),load(), andstart().- Hile middleware and controllers run first; unmatched requests are passed to Next.js with the original Node request and response.
- Development mode is determined by
process.env.NODE_ENV === 'development'. - Controllers use
{cwd}/src/controllersin development and{cwd}/dist/controllersin production with prefix/-. load(directory)explicitly loads an additional controller directory with the same fixed conventions.- Call
use()andload()beforestart(); configuration is frozen once startup begins. - Next.js exclusively owns
public/,distDir,/_next/static, RSC, Server Functions, andnext.config. start(onReady)calls readiness only after Next is prepared and the shared HTTP server is listening.- The returned async stop function first asks the shared HTTP server to stop accepting new connections, then waits for HTTP drain and Next runtime cleanup concurrently. It tracks and terminates upgraded connections, including development HMR WebSockets, because Node’s HTTP drain does not own their protocol lifecycle. Development shutdown also closes disposable HTTP/compiler connections, matching Next’s own development-server policy; production HTTP requests retain graceful drain behavior.
- Stop and startup rollback attempt both HTTP and Next cleanup even when either side fails. One failure is rethrown directly; multiple failures are reported together.
Production Checklist
- Register every server/client close function with
shutdown. - Load controllers before
listen()in new code. - Size Redis lock TTLs for the actual job duration.
- Monitor queue DLQs and idempotency release failures.
- Keep DB constraints or provider idempotency keys for irreversible side effects.