Skip to content

Node.js Boilerplate developed with TypeScript, using Clean Architecture, Domain-Driven Design (DDD) and Test Driven Development (TDD)

Notifications You must be signed in to change notification settings

matheuspleal/node-js-boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.js Boilerplate

Node.js Boilerplate

Build Status Coverage Status js-standard-style GPLv3 License

Table of Contents
  1. About The Project
  2. Libraries and Tools
  3. Getting Started
  4. In Production
  5. Contact

About The Project

The Node.js Boilerplate is a project developed in TypeScript that uses concepts of Clean Architecture and Domain-Driven Design (DDD) to maintain a decoupled and domain-centered application structure.

In addition, various other design patterns are applied throughout the project to solve common software design problems encountered during the development process.

Finally, the use of Test-Driven Development (TDD) ensures several benefits for the code, such as better design, quality, greater development agility, and ease of maintenance and refactoring.

Context

The project's goal is to demonstrate how it is possible to develop software in a decoupled manner. Thus, the example used in this boilerplate is extremely simple and can be divided into two main sets of features: Authentication and Persons.

The Authentication functionality allows Sign Up in the system and ensures that the access token is generated (Sign In) so that Persons resources, which are protected, can be accessed.

The Persons functionality allows an authenticated user to Fetch Persons in a paginated way and Get Person By Id.

Interaction with the API can be done in two ways, through the REST API or the GraphQL API.

Libraries And Tools

This section describes the main libraries and tools used in the project, separated between development and production dependencies.

Dependencies

Dev Dependencies

Getting Started

This section describes the main libraries and tools used in the project, separated between development and production dependencies.

Prerequisites

In addition to Node.js, some other tools are required to run this project:

Optionals

You can also install this toolkit for a better experience:

Env Variables

For security reasons, the .env file is not versioned, meaning it is not sent to the GitHub repository.

So you can copy and paste the .env.example file and rename it to .env. Then, you need to configure the environment variables.

You must also setup a .env.test to run the tests.

All variables can be configured according to your preferences.

I recommend that you leave the DATABASE_URL variable as it is in the example, as it refers to the other database configuration environment variables.

The only point of attention is regarding JWT_PRIVATE_KEY and JWT_PUBLIC_KEY. The JWT adapter reads the base64 values of these two environment variables. That is, in this case, there is no reading of the .pem files to obtain the keys.

To generate a pair of keys on MacOS, you can use these commands:

# generate private key
openssl genpkey -algorithm RSA -out private-key.pem -pkeyopt rsa_keygen_bits:2048
# generate public key
openssl rsa -pubout -in private-key.pem -out public-test-key.pem

Now it is necessary to transform the .pem files into base64. To do this on MacOS, you can follow these steps:

# transform private key in base64
openssl base64 -in private-key.pem -out private-key.txt
# transform public key in base64
openssl base64 -in public-key.pem -out public-key.txt

Now, the values obtained in the .txt files are the private and public keys in base64. These are the values that you must set for JWT_PRIVATE_KEY and JWT_PUBLIC_KEY.

Preparing

Install the dependencies with your favorite package manager (npm, yarn, or pnpm). In the example below, the default package manager for Node.js, npm, will be used:

npm install

Wizard

The wizard is a simple CLI contained in the project, developed with Google ZX to assist developers with various tasks. To run it, you can use one of the following scripts:

# Without logs
npm run wizard
# With logs
npm run wizard:logs

Now just choose one of the options below and wait for the magic to happen!

Wizard

Run Tests

To run unit tests (*.spec.ts):

npm run test

To run unit tests (*.spec.ts) in watch mode:

npm run test:watch

To run e2e tests (*.test.ts):

npm run test:e2e

To run e2e tests (*.test.ts) in watch mode:

npm run test:e2e:watch

To run all tests unit and e2e tests (*.spec.ts and *.test.ts)

npm run test:ci

Start Server

If database container is running, you can run:

npm run start:dev

Or you can use wizard:

npm run wizard

And choose option 5!

Contact

About

Node.js Boilerplate developed with TypeScript, using Clean Architecture, Domain-Driven Design (DDD) and Test Driven Development (TDD)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published