Tech Stack: Node.js, Typescript, Nest.js, PostgreSQL, TypeORM
- Node v16.13.2 or higher
- Docker compose (optional)
$ git clone
$ npm install
$ docker compose up
this will start postgres and adminer on local containers
adminer is lighwheight DBMS that runs on browser
alternatively you can set up your own local postgres database
-> access adminer on your localhost:8080
* system: PostgreSQL
* server: db
* username: pgsql
* password: pgsql
* leave the database field empty
(you may change these values on docker-compose.yml following your preferences)
-> create a database with the name of your preference and leave it empty
-> create a .env file on project root following .env.example model and fill
the placeholders with the same values above
$ npm run start:dev
this will execute all pending migrations in the database
[Swagger] http://localhost:3000/api-docs
Typings with suffix .dto.ts
, .entity.ts
or .response.ts
are automatically set to be read by swagger. This config is in nest-cli.json
file following
Nest.js standards
# run all tests
$ npm run test
# test coverage
$ npm run test:cov
Integration tests validate comunication between layers, error handling and input validation mocking external calls.
# find problems
$ npm run lint
# find and fix problems automatically
$ npm run lint:fix
# format code
$ npm run format
-
The endpoints are organized following Nest.js standard structure of Modules, Controllers and Services. The entry point module is the
app.module
that imports the other needed modules to make the endpoints available. This structure wraps all the endpoint dependencies inside a module and applies the singleton design pattern when creating objects (done by nest.js in the background). -
The
src/core
folder contains shareable resources that are used throughout the application and are not related to a specific functional requirement.
Errors are handled by a global nest interceptor created in src/core/request-interceptor/request.interceptor.ts
and configured in src/main.ts
. This interceptor catches any error thrown in the application and makes sure that is going to be returned in a standard format.
This same interceptor is also responsible for logging operation start, end and error with relevant data.
All the input typings carry its own validations using class-validator decorators. The validations are triggered by a global nest.js validation pipe created in src/core/api-validation-pipe.ts
and configured in src/main
.
Currently the cart is stored in nest.js cache and has a TTL of 24 hours.
When starting the application for the first time, migrations to create and populate products will execute automatically.