Skip to content
LykosJSLYKOSJS
CreatorDeveloperBenchmarkshomeGet started
v1.0.0
Application & serverREST APIGraphQLRouting & groupsRequest context & repliesValidationError handling
PREVIOUSQuick startNEXT REST API
© 2026 LykosJS · MIT LicenseBun · TypeScript

© 2026 LykosJS. Released under the MIT License.
Built by Zen Allaham.

DocsGitHubX
DOCS/V1.0.0/CORE CONCEPTS
CORE CONCEPTS

Application & server

The Lykos class is the application entry point. It manages route registration, middleware, dependency injection, Socket.IO integration and HTTP server startup.

Application instance

Every Lykos application starts with a new instance of the Lykos class. The instance owns its router, middleware registry, dependency injection container and module loader.

ts
1import { Lykos } from 'lykosjs'2 3const app = new Lykos()

Create the application once and use the same instance to register routes, configure middleware, load modules and start the HTTP server.

Register global middleware

Use app.use() to register middleware that should run for application routes. Global middleware is added to the middleware pipeline when a route is registered.

ts
1app.use(async (ctx, reply, next) => {2  console.log(`[Request] ${ctx.method} ${ctx.path}`)3  return next()4})
Middleware registration order
Register global middleware before defining routes. Middleware registered afterward is not automatically added to routes that have already been registered.

Register routes

The application exposes methods for registering HTTP routes. Each method accepts a path, a handler and optional route-specific middleware.

ts
1app.GET('/', async (ctx, reply) => {2  return reply.OK({3    message: 'Welcome to LykosJS'4  })5})6 7app.POST('/users', createUserHandler)8app.PUT('/users/:id', updateUserHandler)9app.PATCH('/users/:id', patchUserHandler)10app.DELETE('/users/:id', deleteUserHandler)

Route handlers receive the request context and reply object. They must return a standard Response object. Returning undefined or another value results in an HTTP 500 response.

Organize routes with groups

Use app.group() to organize related routes under a shared URL prefix. You can also provide middleware that applies to the routes registered inside the group.

ts
1app.group('/api/users', (group) => {2  group.GET('/', getUsersHandler)3  group.GET('/:id', getUserHandler)4}, authMiddleware)

The group prefix is combined with each route path, while group middleware is included in the registered routes' middleware pipeline.

Load application modules

The modules() method loads dependency injection modules and their registered providers, controllers and routers. It also makes the application instance available through the dependency injection container.

ts
1app.modules([2  UsersModule,3  AuthModule,4])

Load your modules before starting the server so their registered routes and dependencies are available to the application.

Initialize Socket.IO

Lykos provides a Socket.IO integration through app.socketIO(). It initializes the Socket.IO server using the Bun Socket.IO engine and returns the Socket.IO server instance.

ts
1const io = app.socketIO({2  cors: {3    origin: 'https://app.example.com'4  }5})

Calling socketIO() again returns the existing Socket.IO instance rather than creating another one. You can also pass the instance through the module context when loading modules.

Inspect registered routes

Use readRoutes() to retrieve the application's registered route metadata. It returns a read-only array of registered routes.

ts
1const routes = app.readRoutes()2 3console.log(routes)

Start the HTTP server

Once your application is configured, call listen() to start the HTTP server. Lykos uses Bun.serve() internally.

ts
1const server = app.listen(4000, () => {2  console.log('Server ready at http://localhost:4000')3})

The default port is 4000. The callback is optional and runs after the server has been created. The method returns the Bun server instance.

Application API reference

The following methods are available on a Lykos application instance:

  • GET(path, handler, ...middlewares) — register a GET route.
  • POST(path, handler, ...middlewares) — register a POST route.
  • PUT(path, handler, ...middlewares) — register a PUT route.
  • PATCH(path, handler, ...middlewares) — register a PATCH route.
  • DELETE(path, handler, ...middlewares) — register a DELETE route.
  • HEAD(path, handler, ...middlewares) and OPTIONS(path, handler, ...middlewares) — register HEAD and OPTIONS routes.
  • use(middleware) — register global middleware.
  • group(prefix, callback, ...middlewares) — register routes under a shared prefix.
  • modules(classes, context?) — load dependency injection modules.
  • resolve(moduleClass, token) — resolve a dependency from a loaded module.
  • socketIO(options?) — initialize or retrieve the Socket.IO integration.
  • readRoutes() — inspect registered route metadata.
  • listen(port?, callback?) — start the HTTP server.
Configure first, listen last
Register global middleware, routes, groups, modules and Socket.IO integration before calling listen(). This ensures the application is configured before it starts accepting requests.