Coder Social home page Coder Social logo

naderbhrr / node.js-clean-architecture Goto Github PK

View Code? Open in Web Editor NEW

This project forked from panagiop/node.js-clean-architecture

0.0 0.0 0.0 189 KB

A use case of Clean Architecture in Node.js comprising of Express.js, MongoDB and Redis as the main (but replaceable) infrastructure.

JavaScript 96.66% Dockerfile 3.34%

node.js-clean-architecture's Introduction

node.js-clean-architecture

A use case of Clean Architecture in Node.js comprising of Express.js, MongoDB and Redis as the main (but replaceable) infrastructure.

Overview

This example is a simple RESTful API application in which a user can create / update / delete / find a post, by using the Clean Architecture.

The objective of Clean Architecture by Robert C. Martin is the separation of concerns in software. This separation is achieved by dividing the software into layers. Each layer is encapsulated by a higher level layer and the way to communicate between the layers is with the Dependency Rule.

Dependency Rule

This rule says that nothing in an inner circle can know anything at all about something in an outer circle. The dependency direction is from the outside in. Meaning that the Entities layer is independent and the Frameworks & Drivers layer (Web, UI, DB etc.) depends on all the other layers.

Entities

Contains all the business entities an application consists of. In our example the User and the Post.

Use Cases

Contains application specific business rules. These use cases orchestrate the flow of data to and from the entities. In our example some of the use cases are: AddPost, AddUser, DeleteById etc.

Interface Adapters

This layer is a set of adapters (controllers, presenters, and gateways) that convert data from the format most convenient for the use cases and entities, to the format most convenient for some external agency such as the DB or the Web. In other words, is an entry and exit points to the Use Cases layer. In our example we implemented controllers and presenters together and these are the PostController and the UserController.

Frameworks and Drivers

The outermost layer is generally composed of frameworks and tools such as the Database, the Web Framework, etc.

How to run it

  • Make sure you have mongoDB installed. At the terminal run the following command:
mongod --dbpath <path_to_data/db_folder>
  • Make sure Redis is also installed and running.

  • Run the server in development mode by typing the following command:
npm run dev
  • Run the server in production mode by typing the following command:
npm run start

How to run it (using Docker)

  • Make sure you have docker installed. At the root folder run the following command:
docker-compose up -d

API documentation

https://documenter.getpostman.com/view/1551953/TzCJgpnb

Further reading

node.js-clean-architecture's People

Contributors

panagiop avatar

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.