Skip to content

iMbGenom/test-mapp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Test-MileApp

Install manually in local (make sure you already installed mongo in local)

$ cd test-mileapp
$ cp .env.example .env
$ cat .env (Please make sure your local environment)
$ npm install

Run the coverage (testing)

$ npm run coverage

Run the server as development

$ npm run dev

Run the server as production

$ npm run start

Import postman collection in test-mileapp/doc/postman/collection

GET /package
GET /package/{id}
POST /package
PUT /package/{id}
PATCH /package/{id}
DELETE /package/{id}

Project Description

This project's architecture is focused on separation of concerns and scalability with Uncle Bob Clean Architecture implementation.


## Installation Node App

This is a [Node.js](https://nodejs.org/en/) module available through the
[npm registry](https://www.npmjs.com/).

Before installing, [download and install Node.js](https://nodejs.org/en/download/).
Node.js 0.10 or higher is required.

Installation is done using the
[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):

```bash
$ npm install express

alt text

Project Anatomy

app 
 └ lib                              → Application sources 
    └ application_business_rules    → Application services layer
       └ repositories               → Data access objects interfaces (Request data from services)
       └ use_cases                  → Application business rules 
    └ constant                      → Constant value or static value
    └ domain                        → Enterprise core business layer or Entities
       └ entities                   → Domain model objects such as Entities, Aggregates, Value Objects, Business Events, Serializers, etc.
    └ infrastructure                → Frameworks, drivers and tools such as Database, the Web Framework, mailing/logging/glue code etc.
       └ database                   → database connection objects
       └ cache                      → cache data objects
       └ component                  → Drivers, Third parties sucs as like AWS, Payment Gateway
       └ webserver                  → Express.js Web server configuration (server, routes, plugins, etc.)
          └ routes                  → Express.js routes definition
       └ server.js                  → Express.js server definition
    └ interface                     → Adapters and formatters for use cases and entities to external agency such as Database or the Web
       └ controllers                → Express.js route handlers
       └ utils                      → Security tools implementations (ex: JwtAccessTokenManager)
 └ node_modules (generated)         → NPM dependencies
 └ test                             → Source folder for unit, integration or functional tests
 └ app.js                           → Main application entry point

Server, Routes and Plugins

Server, routes and plugins can be considered as "plumbery-code" that exposes the API to the external world, via an instance of Express.js server.

The role of the server is to intercept the HTTP request and match the corresponding route.

Routes are configuration objects whose responsibilities are to check the request format and params, and then to call the good controller (with the received request). They are registered as Plugins.

Plugins are configuration object that package an assembly of features (ex: authentication & security concerns, routes, pre-handlers, etc.) and are registered at the server startup.

Controllers (a.k.a Route Handlers)

Controllers are the entry points to the application context.

They have 3 main responsibilities :

  1. Extract the parameters (query or body) from the request
  2. Call the good Use Case (application layer)
  3. Return an HTTP response (with status code and serialized data)

Use Cases

A use case is a business logic unit.

It is a class that must have an execute method which will be called by controllers.

It may have a constructor to define its dependencies (concrete implementations - a.k.a. adapters - of the port objects) or its execution context.

Be careful! A use case must have only one precise business responsibility!

A use case can call objects in the same layer (such as data repositories) or in the domain layer.

About

Clean Architecture in Node.js with Express and Mongoose, tested using Mocha and Istanbul

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published