/template-clean-architecture

This is a project inspired by hexagonal clean architecture to begin to understand little by little this way of creating our Rest Apis with Nodejs and Typescript

Primary LanguageTypeScript

Trueq-In REST API

This API is built with Clean Architecture. It is a way to separate business logic from application logic.

This in order to be more scalable in the future if it is necessary to change infrastructure or technologies.

Technologies

Project is created with:

  • Typescript
  • Yarn
  • Jest
  • Prisma ORM
  • Bcrypt
  • JWT
  • Husky

Minimum Requirements

  • Yarn V1.22.19
  • NodeJS V14.20.1
  • Docker

Variables Enviroment

  • Add in the root a folder called env and inside a file .env.dev
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres
PORT=5000

Setup

Initially you have to run Docker so that the database is created and filled with information with users

$ yarn docker:compose

This step is not necessary if you are going to use the url of your cloud database or if you do not need a list of users.

Generate the prism schema to be able to interact with the database.

$ yarn prisma:pull

This script allows us to use the schema of our database if we already have one. If you are using the init.sql file found in /src/infrastructure/database or if you are using a cloud-based database, this command is recommended.

If you are going to work with a blank project, it is recommended to read the prism documentation if you want to use said ORM. Prisma Docs

Generate the prism client to work with your database

$ yarn prisma:generate

Start the application

  • Install the dependencies
$ yarn install
  • Run the project
$ yarn dev

Husky & Jest

The project is designed to work with version control alone or as a team. So you have Husky set up, which is a hook to avoid pushing to a Git branch if it contains Eslint errors or fails tests.

Before committing, the project tests are run, but in order to run the tests before committing, we can run the following command:

$ yarn test