$ cd test-mileapp
$ cp .env.example .env
$ cat .env (Please make sure your local environment)
$ npm install
$ npm run coverage
$ npm run dev
$ npm run start
GET /package
GET /package/{id}
POST /package
PUT /package/{id}
PATCH /package/{id}
DELETE /package/{id}
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
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 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 are the entry points to the application context.
They have 3 main responsibilities :
- Extract the parameters (query or body) from the request
- Call the good Use Case (application layer)
- Return an HTTP response (with status code and serialized data)
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.
