AhmadKabakibi / JM_API-Boilerplate

A boilerplate for web APIs using Nodejs - based on Domain Driven Design and Clean Architecture principles

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JM API Node

CircleCI code style: prettier js-standard-style Nodejs: version Blazing Fast dependencies Status devDependencies Status Maintainability Test Coverage

A boilerplate for web APIs using NodeJS

the boilerplate follows an architecture inspired by Domain Driven Design and Clean Architecture. It implies in some patterns and methodologies having to be followed to ensure separation of concerns and make the codebase more maintainable.

Features


Folder structure

This boilerplate uses a folder structure and logical architecture focused on separation of concerns based in Domain-driven design and Clean architecture. Instead of the classical controllers/models/services folders, we now have layers inside the src folder. Each of the folder layers is scoped by a namespace regarding the concern it is about (like user, errors, logging and so on):

Application layer (app folder)

The application layer defines the actual behaviour of our application, thus being responsible for performing interactions among units of the domain layer.

Domain layer (domain folder)

In this layer, we may define units which play the role of entities and business rules and have a direct relationship to our domain This is the most isolated and important layer of our software, and it may be used by the application layer to define use cases.

Infrastructure layer (infrastructure folder)

This is the lowest layer of all, and it’s the boundary to whatever is external to our application: the database, email services, etc.

Input interfaces layer (interfaces folder)

This layer holds all the entry points of our application, such as controllers, websockets, etc. It should not have any knowledge about business rules, use cases, persistence technologies, and not even about other kinds of logic! It should only receive user input (like URL parameters), pass it on to the use case and finally return a response to the user.

├── app
├── config
│   └── environments
├── domain
├── infrastructure
│   └── logging
└── interfaces
    └── http
        ├── controllers
        ├── errors
        ├── logging
        └── utils

Prerequisites

Docker

Install Docker on your system.

Environment Variables

The initial (default) environment variables have been set for you in the .env file. If you need to have custom variables in your dev process you can use a .env.local file to override those. The application will use the following files in the following order to create a final set of variables:

  1. .env
  2. .env.local
  3. .env.<environment>
  4. .env.<environment>.local

A server (via docker container) will ONLY read the .env file, so server specific variables should either be passed along in the build command (ENV_VAR=value <build command>) or in the server configuration.

Setup

  1. Run npm i. It will install all dependencies.

  2. Run docker-compose build. It will pull a base images from the Docker registry.

  3. Run docker-compose up. This will bootstrap a new app in your container optionaly add optionaly -d Detached mode: Run containers in the background.

  4. Run docker-compose down It will Stops containers and removes containers, networks, volumes, and images created by up.

The app should then be running on your docker daemon on the port you specified in your .env file (default: 4050) or override (see Prerequisites > Environment Variables)

Scripts

This boilerplate comes with a collection of npm scripts to make your life easier, you'll run them with npm run <script name>

npm run start run the application

npm run start:watch run the application in watch mood on every file change

npm run test run all unit tests for the appliction

npm run test:watch run all unit tests for the appliction in watch mood on every file change

npm run test:coverage Create a coverage report for your code and determine whether your coverage is high enough

npm run lint Run linting on the application codebase

About

A boilerplate for web APIs using Nodejs - based on Domain Driven Design and Clean Architecture principles

License:MIT License


Languages

Language:JavaScript 98.4%Language:Dockerfile 1.6%