Skip to main content

Module System

The Archibald framework is built around a modular architecture, particularly on the server-side. Modules are self-contained units of functionality that can be registered with the main CoreServer to extend its capabilities.


Key Characteristics of a Module

  • Encapsulation: Modules encapsulate a specific feature or domain, such as Content Management (CMSModule), Authentication (AuthModule), or Product data (ProductModule). They contain all the necessary components for that feature, including controllers, services, and providers.
  • Registration: Modules are registered in the initModules method of your server-side Server class. The registerModules method accepts an array of module instances.
  • Configuration: When instantiating a module, you can pass a configuration object to customize its behavior. This is often where you provide specific providers or adapters.

Example: Registering Modules

Here is an example of how you might register several modules in your application's Server class:

// templates/shop/src/shop/server/module/server.tsx
import { AuthModule } from '@archibald/auth';
import { CMSModule } from '@archibald/cms';
import { ProductModule } from '@archibald/product';
import { SearchModule } from '@archibald/search';
import { CommerceCMSProvider } from '@archibald/commerce/cms';
import { CommerceProductProvider } from '@archibald/commerce/product';
import { CommerceSearchProvider } from '@archibald/commerce/search';
import { CommerceUserAuthProvider, CommerceStaticAuthProvider } from '@archibald/commerce/auth';
import { CoreServer } from '@archibald/server';
import { ProjectCommerceProductMapper } from 'shop/server/classes/project-commerce-product-mapper';

export class Server extends CoreServer {
public async initModules() {
await this.registerModules([
new AuthModule({
providers: [
new CommerceUserAuthProvider({ /* ... */ }),
new CommerceStaticAuthProvider({ /* ... */ })
],
options: () => ({ /* ... */ })
}),
new SearchModule({
provider: new CommerceSearchProvider({ config: () => this.configService.get('hybris.api'), mappers: [ProjectCommerceProductMapper] })
}),
new CMSModule({
provider: new CommerceCMSProvider({
config: () => this.configService.get('hybris.api')
})
}),
new ProductModule({
provider: new CommerceProductProvider({ config: () => this.configService.get('hybris.api'), mappers: [ProjectCommerceProductMapper] })
}),
// ... other modules
]);
}
}

In this example:

  • The AuthModule, SearchModule, CMSModule, and ProductModule are all registered with the CoreServer.
  • The CMSModule is configured to use the CommerceCMSProvider, which in turn is configured with API details.

This modular approach allows for a clean separation of concerns and makes it easy to add or remove features from your application. Each module can be developed and maintained independently.