Modular architecture
Organize your application into independent feature modules with explicit dependencies, scoped providers, and centralized route registration.

Feature-based architecture
LykosJS uses a module-based architecture to organize application features into independent, maintainable units. Each module extendsDIModule and defines its own providers, controllers, routers, imports, exports, and optional authentication configuration.
The module loader creates an isolated dependency scope for each module, resolves its dependencies, and registers its routers. This keeps feature boundaries explicit and reduces coupling between application components.
Define a feature module
A feature module groups the components responsible for a specific application capability. For example, a users module can own its service, controller, and router.
1import { DIModule, bind } from 'lykosjs'2 3import { UsersService } from './users.service'4import { UsersController } from './users.controller'5import { UsersRouter } from './users.router'6 7export class UsersModule extends DIModule {8 override providers = [UsersService]9 10 override controllers = [bind(UsersController, UsersService)]11 12 override routers = [bind(UsersRouter, Lykos, UsersController)]13}Compose modules
Modules can import other modules to access their exported providers. A module only exposes dependencies explicitly listed in its exports property.
1// database.module.ts2export class DatabaseModule extends DIModule {3 override providers = [DatabaseService]4 override exports = [DatabaseService]5}6 7// users.module.ts8export class UsersModule extends DIModule {9 override imports = [DatabaseModule]10 11 override providers = [bind(UsersService, DatabaseService)]12}This allows modules to reuse shared capabilities without directly depending on the internal implementation of other features.
Register application modules
Collect your root feature modules in a single array and pass them to app.modules(). LykosJS loads their module definitions, resolves their dependencies, and registers their routers.
1import { Lykos } from 'lykosjs'2 3import { UsersModule } from './modules/users/users.module'4import { BillingModule } from './modules/billing/billing.module'5 6const app = new Lykos()7 8const Modules = [9 UsersModule,10 BillingModule,11]12 13app.modules(Modules)14 15app.listen(4000)Module boundaries
Keep each module responsible for its own feature and expose only the dependencies that other modules need.
- Feature ownership: Group related controllers, routers, and providers around a business capability.
- Explicit dependencies: Use
importsandexportsto define module relationships. - Scoped providers: Keep implementation details inside their owning module whenever possible.
- Separation of concerns: Keep routing and request handling separate from business logic and data access.
Recommended project structure
A feature-oriented directory structure keeps related components together as the application grows.
1src/2├── modules/3│ ├── users/4│ │ ├── users.module.ts5│ │ ├── users.service.ts6│ │ ├── users.controller.ts7│ │ └── users.router.ts8│ │9│ ├── billing/10│ │ ├── billing.module.ts11│ │ ├── billing.service.ts12│ │ ├── billing.controller.ts13│ │ └── billing.router.ts14│ │15│ └── database/16│ ├── database.module.ts17│ └── database.service.ts18│19├── app.ts20└── main.ts