Giter Club home page Giter Club logo

navalia-api's Introduction

Backend Challenge API

Tech Stack: Node.js, Typescript, Nest.js, PostgreSQL, TypeORM

Requirements

  • Node v16.13.2 or higher
  • Docker compose (optional)

Run Application Locally

$ 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

API Docs

[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

Tests: unit and integration

# 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.

Linter and formatting

# find problems
$ npm run lint

# find and fix problems automatically
$ npm run lint:fix

# format code
$ npm run format

Architecture design

  1. 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).

  2. The src/core folder contains shareable resources that are used throughout the application and are not related to a specific functional requirement.

Error handling and logging

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.

Input validation

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.

Caching

Currently the cart is stored in nest.js cache and has a TTL of 24 hours.

Migrations

When starting the application for the first time, migrations to create and populate products will execute automatically.

navalia-api's People

Contributors

hpsmatheus avatar hps-matheus avatar

Watchers

James Cloos avatar  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.