π¦ Creating Modules
This guide explains how to create a new module in Loopstack based on NestJSβ module system.
Module Structure
A Loopstack module consists of two main files:
- Module File - The main NestJS module that imports dependencies and exports providers
- Factory Service - A specialized service that handles block instantiation
Creating the Module
1. Module Declaration
Create your main module file (e.g., my-feature.module.ts):
import { Module } from '@nestjs/common';
import { CoreToolsModule, LoopCoreModule } from '@loopstack/core';
import { ModuleFactory } from '@loopstack/shared';
import { MyFeatureModuleFactoryService } from './my-feature-module-factory.service';
@Module({
imports: [
LoopCoreModule,
CoreToolsModule,
// Add other required modules here
],
providers: [
// Add your workspaces, workflows, tools, and documents here
MyFeatureModuleFactoryService,
],
exports: [
MyFeatureModuleFactoryService
]
})
@ModuleFactory(MyFeatureModuleFactoryService)
export class MyFeatureModule {}For all basic functionality of the Loopstack framework, import the LoopCoreModule and CoreToolsModule in your custom module. Add the @ModuleFactory decorator to your module to allow dynamic instantiation of your automation blocks.
2. Factory Service
Create the corresponding factory service (e.g., my-feature-module-factory.service.ts):
import { ModuleRef } from '@nestjs/core';
import { Capability } from '@loopstack/shared';
import { CapabilityFactory } from '@loopstack/core';
@Capability()
export class MyFeatureModuleFactoryService extends CapabilityFactory {
constructor(moduleRef: ModuleRef) {
super(moduleRef);
}
}Key Components
Required Imports
Your module should typically import:
LoopCoreModule- Core Loopstack functionalityCoreToolsModule- Essential tools for automations- Any additional modules your blocks depend on
Providers Array
Add all your blocks to the providers array:
providers: [
// Workspaces
MyWorkspace,
// Workflows
MyWorkflow,
// Tools
MyTool,
// Documents
MyDocument,
// Factory service (required)
MyFeatureModuleFactoryService,
],Module Factory Decorator
The @ModuleFactory() decorator is essential - it registers your factory service and enables block instantiation:
@ModuleFactory(MyFeatureModuleFactoryService)
export class MyFeatureModule {}Adding to App Module
Once your module is created, add it to your main application module:
@Module({
imports: [
// Other imports...
MyFeatureModule,
],
})
export class AppModule {}