1.0.4 • Published 4 months ago

nx-nest-ddd v1.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

Nx Nest DDD

This Nx plugin aims to streamline the development process by generating code for a NestJS application adhering to Domain-Driven Design (DDD) principles and Clean Architecture. It assists in setting up the foundational layers of a robust application, including:

  • Domain Layer: Defining the core business logic and entities.
  • Application Layer: Implementing use cases, application services, and orchestrating domain entities.
  • Infrastructure Layer: Managing external dependencies, databases, and other infrastructure-related concerns.
  • GraphQL UI Layer: Providing a GraphQL-based user interface for interacting with the application.

npm.io

Features

  • Code Generation: Automatically generates boilerplate code for various layers based on DDD and Clean Architecture principles.
  • Layered Structure: Ensures a clear separation of concerns and promotes maintainability and scalability.
  • Customizable Templates: Tailor the generated code templates to fit specific project requirements.
  • Integrated Nx Dev Tools: Seamlessly integrates with Nx Dev Tools for efficient development, testing, and building.

Installation

To use this plugin in your Nx workspace, follow these steps:

  npm install -D nx-nest-ddd

Usage

Use can use nx console as an UI for generate code or use CLI commands below to generate code.

Microservice application generator

This command will generate an application with all the necessary layers.

nx g nx-nest-ddd:sub-domain <name> <options>
OptionTypeAccepted valuesDefaultDescription
namestringWhat name would you like to use?
prefixImportstringThe library name used to import it, like @myorg. use?
templatePathstringA directory where you place the custom template
directorystringA directory where the application is placed.
projectNameAndRootFormatstringas-provided, derivedWhether to generate the project name and root directory as provided (as-provided) or generate them composing their values and taking the configured layout into account (derived).
tagsstringAdd tags to the application (used for linting).
skipFormatbooleantrueSkip formatting files.
strictbooleantrueWhether to enable tsconfig strict mode or not.
setParserOptionsProjectbooleanfalseWhether or not to configure the ESLint "parserOptions.project" option. We do not do this by default for lint performance reasons.
skipPackageJsonbooleantrueDo not add dependencies to package.json.

Domain generator

Generate a domain with subdomain name. The options are the base options

nx g nx-nest-ddd:domain <sub-domain name> <options>

You can generate smaller components by following commands:

nx g nx-nest-ddd:domain-aggregate <name> <sub-domain name> <options>

nx g nx-nest-ddd:domain-entity <name> <sub-domain name> <options>

nx g nx-nest-ddd:domain-event <name> <sub-domain name> <options>

nx g nx-nest-ddd:domain-exception <name> <sub-domain name> <options>

nx g nx-nest-ddd:domain-repository <name> <sub-domain name> <options>

nx g nx-nest-ddd:domain-service <name> <sub-domain name> <options>

nx g nx-nest-ddd:domain-value-object <name> <sub-domain name> <options>

Application generator

Generate an application / use cases layer code using CQRS with subdomain name. The options are the base options

nx g nx-nest-ddd:application <sub-domain name> <options>

For smaller component generators:

nx g nx-nest-ddd:application-query <name> <sub-domain name> <options>

nx g nx-nest-ddd:application-command <name> <sub-domain name> <options>

nx g nx-nest-ddd:application-event <name> <sub-domain name> <options>

Infrastructure generator

Generate an infrastructure layer code with subdomain name. The options are the base options

nx g nx-nest-ddd:infrastructure <sub-domain name> <options>

For smaller component generators:

nx g nx-nest-ddd:infrastructure-orm-entity <name> <sub-domain name> <options>

nx g nx-nest-ddd:infrastructure-orm-mapper <name> <sub-domain name> <options>

nx g nx-nest-ddd:infrastructure-repository <name> <sub-domain name> <options>

Graphql generator

Generate a grapqh ui with subdomain name. The options are the base options

nx g nx-nest-ddd:graphql-ui <sub-domain name> <options>

For smaller component generators:

nx g nx-nest-ddd:graphql-query <name> <sub-domain name> <options>

nx g nx-nest-ddd:graphql-mutation <name> <sub-domain name> <options>

Base options

Layer base options

This base options use for these generators:

  • Domain
  • Application
  • Infrastructure
  • Graphql ui
OptionTypeAccepted ValuesDefaultDescription
namestringSubdomain name. Required.
templatePathstringA directory where you place the custom template
directorystringA directory where the domain is placed. Alias: dir
projectNameAndRootFormatstringas-provided, derivedWhether to generate the project name and root directory as provided (as-provided) or generate them composing their values and taking the configured layout into account (derived).
tagsstringAdd tags to the domain (used for linting). Alias: t
skipFormatbooleantrueSkip formatting files.
skipTsConfigbooleanfalseDo not update tsconfig.base.json for development experience.
publishablebooleanCreate a publishable library.
importPathstringThe library name used to import it, like @myorg/my-awesome-lib. Must be a valid npm name.
testEnvironmentstringjsdom, nodenodeThe test environment for jest, for node applications this should stay as node unless doing DOM testing.
targetstringes5, es6, esnext, es2015, es2016, es2017, es2018, es2019, es2020, es2021es2021The ES target, Nest suggest using es2021 or higher.
strictbooleantrueWhether to enable tsconfig strict mode or not.
setParserOptionsProjectbooleanfalseWhether or not to configure the ESLint "parserOptions.project" option. We do not do this by default for lint performance reasons.
skipPackageJsonbooleantrueDo not add dependencies to package.json.
simpleNamebooleanfalseDon't include the directory in the name of the module of the library.

Component base options

These options for smaller components in a layer such as aggregate, entity, query, etc.

OptionTypeAccepted valuesDefaultDescription
namestringWhat name would you like to use?
subDomainstringSub domain contains this aggregate
sourceRootstringThe directory where the new aggregate will be created. This option will override 'subDomain' argument
templatePathstringA directory where you place the custom template

Template usage

As mention, you can customize the generation by providing your template. You can refer the template folder in the source code to know the file structure and use the --template-path option to provide the template path when generate

Acknowledgements

Roadmap

  • Add serverless generators
  • Add more ui generators like RESTful UI, socket, etc

Contributing

We welcome contributions to the Nx NestJS DDD project! Here are the steps to get started:

  1. Fork the project repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes.
  4. Submit a pull request with your changes.

Contact

If you have any questions, issues, or want to contribute, please feel free to reach out to us:

1.0.2

4 months ago

1.0.1

4 months ago

1.0.4

4 months ago

1.0.3

4 months ago

1.0.0

4 months ago

0.0.10

4 months ago

0.0.11

4 months ago

0.0.9

4 months ago

0.0.8

4 months ago

0.0.7

4 months ago

0.0.4

5 months ago

0.0.6

5 months ago

0.0.3

5 months ago

0.0.1

5 months ago