Skip to content

API developed using NestJS, GraphQL, TypeORM, TDD, PgMem and concepts of Clean Architecture

Notifications You must be signed in to change notification settings

matheusalxds/clean-architecture-graphql-nestjs

Repository files navigation

The Powerful NestJS

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications.

NPM Version Package License

Clean Architecture

alt text

The project has been developed thinking about concepts of Clean Architecture, in a nutshell, I spread the functionalities in layers to better meet the responsibilities.

Our Domain is responsible to keep entities and use-cases. Application layer is responsible for introducing controllers. Infra layer has the responsibility to become a gateway between our application and third packages, and last but not least, there's the Main layer, better known as a "dirty layer", because the Main will connect each part of the project.

GraphQL

GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools.

TypeORM

TypeORM is an ORM that can run in NodeJS, Browser, Cordova, PhoneGap, Ionic, React Native, NativeScript, Expo, and Electron platforms and can be used with TypeScript and JavaScript (ES5, ES6, ES7, ES8). Its goal is to always support the latest JavaScript features and provide additional features that help you to develop any kind of application that uses databases - from small applications with a few tables to large scale enterprise applications with multiple databases.


Getting Started

Installation

$ npm install

Creating the database

Before we start the application, it's necessary to create our database.

It's very simple to create our migration files, as simple as you can think, you just need to run the following command:

$ npm gen:migration <migration_name>

If you want to execute the migration file, you need to run the following command:

$ npm run:migration

Sometimes, we need to revert the migration, so we need to run the following command:

$ npm rev:migration

If you prefer to use the documentation for this, you can find it here.

Running the app

After you create the database, it is possible to start the application with the following command:

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Docker

The simplest way to run the project is basically run by Docker.

# docker-compose
$ docker-compose up

I also added a script to make it easy:

# up all the containers
$ yarn up

# down all the containers
$ yarn down

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.

License

Nest is MIT licensed.