Components
Reusable, pluggable modules that group together related features. A component can encapsulate various resources such as providers, services, controllers, repositories, or even an entire mini-application, providing a clean way to modularize and share complex logic across Ignis applications.
Built-in Components
| Component | Purpose | Key Features |
|---|---|---|
| Authentication | JWT-based auth | Token generation, protected routes, user payload |
| Health Check | Monitoring endpoint | /health endpoint, ping/pong functionality |
| Email sending system | Multiple transports, templating, queue-based processing | |
| Request Tracker | Request logging | Request ID generation, timing, structured logging |
| Socket.IO | Real-time communication | WebSocket support, Redis adapter, event-based |
| Static Asset | File management | Upload/download files, MinIO & local filesystem support |
| Swagger | API documentation | OpenAPI generation, Swagger UI, Scalar UI |
Creating a Component
To create a new component, you need to create a class that extends BaseComponent.
import { BaseApplication, BaseComponent, inject, CoreBindings, ValueOrPromise } from '@venizia/ignis';
export class MyCustomComponent extends BaseComponent {
constructor(
@inject({ key: CoreBindings.APPLICATION_INSTANCE }) private application: BaseApplication,
) {
super({ scope: MyCustomComponent.name });
}
override binding(): ValueOrPromise<void> {
// This is where you bind your component's resources.
this.application.service(MyCustomService);
this.application.controller(MyCustomController);
}
}Component Lifecycle
| Phase | When | Purpose |
|---|---|---|
constructor() | Component instantiation | Receive dependencies, define default bindings |
binding() | Application startup | Register controllers, services, repositories with DI container |
Registering a Component
To use a component, you need to register it with the application instance, usually in the preConfigure method of your Application class.
// in src/application.ts
import { MyCustomComponent } from './components/my-custom.component';
// ... inside your Application class
preConfigure(): ValueOrPromise<void> {
// ...
this.component(MyCustomComponent);
}When the application starts, it will automatically call the binding() method of the registered component, setting up all the resources it provides.
Using components is a great way to organize your application's features into modular, reusable pieces of code, keeping your main application class clean and focused on high-level configuration.
See Also
Component Guides:
- Components Overview - What components are
- Creating Components - Build your own components
Built-in Components:
- Authentication - JWT authentication
- Health Check - Health check endpoints
- Swagger - API documentation
- Socket.IO - WebSocket support
- Mail - Email functionality
- Request Tracker - Request tracking
- Static Asset - Static file serving
References:
- BaseComponent API - Component base class
- Application - Registering components
Best Practices:
- Architectural Patterns - Component design patterns