Coder Social home page Coder Social logo

jungleminds / jm_api-boilerplate Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 1.0 2.43 MB

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

License: MIT License

JavaScript 98.45% Dockerfile 1.55%
boilerplate nodejs javascript server api eslint prettier es6 ecmascript dependency-injection wbso

jm_api-boilerplate's Introduction

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

jm_api-boilerplate's People

Contributors

grumpyoldman-io avatar ahmadkabakibi avatar

Stargazers

Taras Ivaniuk avatar Rilliano Mertodikromo avatar  avatar  avatar

Watchers

James Cloos avatar  avatar Jan Guichelaar avatar Tijmen Overman avatar

Forkers

ahmadkabakibi

jm_api-boilerplate's Issues

heroku support

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.