Skip to content

Origin Backend - @energyweb/origin-backend

Source code on GitHub


The Origin Backend is a NestJS application that provides services for user and organization authorization and management. The Backend application can be used in conjunction with one, several or all of the Origin SDKs to provide integrated user management and authorization.

The below gives an overview the of the package architecture, however the NestJS documentation provides further detail into the fundamentals of NestJS Architecture that may help to understand the elements of this application:

Origin Backend Architecture

The Origin Backend package is broken down into seven NestJS modules:

Each module contains code relevant for a specific feature. In general, each NestJS module has:

  • A controller that manages requests and responses to the client
  • A .entity file that maps an entity to the database repository
  • A .service file that provides methods to fetch and transform data
  • Data Transfer Object (DTO) file(s) that provide Data Transfer Objects, which are representations of the data that are exposed to the endpoint consumer
  • A module class that is used by NestJS to structure the application


The Origin Backend uses PostgreSQL for persistence with TypeORM as a database integration library. The application creates a repository for each entity. Entities are defined in the .entity.ts file in each module, and are marked with the @Entity decorator. (You can read more about entities in the TypeORM documentation here).

export class EmailConfirmation extends ExtendedBaseEntity implements IEmailConfirmation {
    id: number;

    @OneToOne(() => User)
    user: User;

    confirmed: boolean;

    token: string;

    expiryTimestamp: number;


Repositories are injected into services or command handlers so they are available to use in methods:

export class EmailConfirmationService {
        private readonly repository: Repository<EmailConfirmation>,
        private readonly eventBus: EventBus
    ) {}




Source code on GitHub

The admin module's controller uses the user service to fetch and update user information.


Source code on GitHub

The configuration module fetches and updates the platform's configuration values. These values are used to populate the platform's market options.


Source code on GitHub

The email-confirmation module provides methods to manage the email confirmation process. When users register to join the platform, they must confirm their email. Confirmations are persisted in the Email Confirmation repository.


Source code on GitHub

The email-confirmation module provides methods to fetch, update and store files. Files are uploaded to the system when registering an organization, a device or requesting certification. Files are persisted in the File repository.


Source code on GitHub

The invitation module provides methods to manage invitations for users to join organizations. Invitations are persisted in the Invitation repository.


Source code on GitHub

The invitation module provides methods to manage fetch, create and update Organization data, including Organization Blockchain Account Addresses. Organizations are persisted in the Organization Repository.


Source code on GitHub

The user module provides methods to manage fetch, create and update users. Users are persisted in the User Repository.

Origin Backend-Core Package - @energyweb/origin-backend-core

Source code on GitHub

The Origin Backend Core package provides the interfaces, types and enums for Origin Backend.