Skyframe Documentation

Modules

Modules

Introduction

Skyframe modules are containers for functionalities scoped to a specific entity in the domain. They can contain components, service providers, controllers and other code files whose scope is defined by the Entity. We want to emphasize that modules are strongly recommended as an effective way to organize your components. For most applications, the optimal architecture will employ multiple modules, each encapsulating a closely related set of capabilities.

Metadata

A module is a class annotated with a @SkfModule() decorator. The @SkfModule() decorator provides metadata that Skyframe makes use of to organize the application structure.

Skyframe works with many Javascript frameworks so there are a few differences in the metadata needed in each implementation. Let's see an example for each Framework

Angular modules

When using Angular there is already a lot of useful metadata declared in the NgModule, so Skyframe only needs one more attribute:

  • entities: The set of Domain Entities that should be visible and usable in the scope of this module. This contributes to the global collection of entities; they become accessible in all parts of the app.

Here's a simple Skyframe Module definition for Angular.

import { NgModule } from '@angular/core';
import { SkfModule } from '@skyframe/angular';
import { BrowserModule } from '@angular/platform-browser';
@NgModule({
imports: [BrowserModule],
providers: [Logger],
declarations: [AppComponent],
exports: [AppComponent],
bootstrap: [AppComponent]
})
@SkfModule({
entities: [User]
})
export class AppModule {}

Nestjs modules

Skyframe Modules for Nestjs receive the following metadata properties:

  • providers: The providers that will be instantiated by the Nest injector and that may be shared at least across this module
  • controllers: The set of controllers defined in this module which have to be instantiated
  • imports: The list of imported modules that export the providers which are required in this module
  • exports: The subset of providers that are provided by this module and should be available in other modules which import this module
  • models: The set of entities declared for this particular module. This entities will act as providers and will be available as an injectable.

Here's a simple Skyframe Module definition for Nestjs.

import { SkfNestModule } from '@skyframe/nest';
import { ArticleController } from './controller';
import { Article } from './model';
@SkfNestModule({
controllers: [ArticleController],
models: [Article]
})
export class ArticleModule {}