Socket
Book a DemoInstallSign in
Socket

@e-square/nx-ddd

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@e-square/nx-ddd

Enforces domain-driven design development

1.2.0
latest
Source
npmnpm
Version published
Maintainers
2
Created
Source

@e-square/nx-ddd

npm GitHub

Enforces domain-driven design development.

✅ Support Angular and React

Table of Contents

Prerequisites

Overview

Applications grow in size and complexity and in a large organization there are many ways to reuse code to maintain consistency and to lower the development effort.

Developing in a modular way can be done using libraries, which are simply a collection of related files that perform a certain task. These are composed together to make up an application.

Libraries require classifiers to describe their contents and intended purpose. These classifiers help to organize the libraries and to provide a way to locate them.

Scope

Scope relates to a logical grouping, business use-case, or domain contain libraries that manage a sub-domain of application logic.

Type

Type relates to the contents of the library and indicates its purpose and usage. Examples of types are data-access, feature, ui, and util.

Types of Libraries

Feature Libraries

Developers should consider feature libraries as libraries that implement smart UI (with access to data sources) for specific business use cases or pages in an application.

UI Libraries

A UI library contains only presentational components (also called "dumb" components).

Data-Access Libraries

A data-access library contains code for interacting with a back-end system. It also includes all the code related to state management.

  • state - for state files
  • application - for facades
  • entities - for interfaces, enums
  • infrastructure - for services

Utility Libraries

A utility library contains low-level utilities used by many libraries and applications.

Installation

npm i -D @e-square/nx-ddd

nx g @e-square/nx-ddd:init

OR

ng add @e-square/nx-ddd

Usage

Create a DDD Library

nx g @e-square/nx-ddd:library

Create an Angular ddd feature library example.

nx g @e-square/nx-ddd:library posts --framework angular --type feature --domain blog

Create a React ddd feature library example.

nx g @e-square/nx-ddd:library posts --framework react --type feature --domain blog

API

@e-square/nx-ddd:init

ArgumentAliasTypeDefaultDescription
sharedDomainstring'shared'The shared domain
domainTagNamestring'scope'The domain tag name

@e-square/nx-ddd:library

ArgumentAliasTypeDefaultDescription
frameworkf'angular' | 'react'''The framework to be used for library generation
typet'feature' | 'ui' | 'data-access' | 'util''data-access'The library type
namestring''The name of the library
domaindstring''The domain the library belongs to
directorystring''A directory where the library is placed inside the domain directory
withoutTypePrefixbooleanfalseCreate the library inside library type directory <domainName>/<libraryType>-<libraryName> to <domainName>/<libraryType>/<libraryName>
standaloneConfigbooleanfalseSplit the project configuration into <projectRoot>/project.json rather than including it inside workspace.json

How To Customize the Library Generator

There are situations you need to customize the generated files more than what exists today.

It's very easy to customize existing generators with nx workspace generators.

This library exposed the generators to allow customization.

Create Nx Workspace Generator

nx g workspace-generator shared-ui

Update The Generator Implementation

import { formatFiles, readProjectConfiguration, Tree } from '@nrwl/devkit';

import {
  DDDLibraryFramework,
  dddLibraryGenerator,
  DDDLibraryType,
} from '@e-square/nx-ddd';

import { SharedUIScheme } from './scheme';

export default async (tree: Tree, { name }: SharedUIScheme): Promise<void> => {
  // Creates the library and return dddLibraryStructure object.
  const dddLibraryStructure = await dddLibraryGenerator(tree, {
    name,
    framework: DDDLibraryFramework.Angular,
    type: DDDLibraryType.UI,
    domain: 'shared',
    withoutTypePrefix: true,
    standaloneConfig: true,
  });

  // Let's read the project which was created.
  const projectConfiguration = readProjectConfiguration(
    tree,
    dddLibraryStructure.project
  );

  /**
   * Here you can use the projectConfiguration
   * For adding, deleting and updating files.
   */

  await formatFiles(tree);
};

Run The Generator

nx workspace-generator shared-ui --name button

License

MIT

Keywords

nx

FAQs

Package last updated on 05 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.