Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/fer8a/nestjs-grpc-scaffold

GRPC boilerplate to build microservices using the NestJS framework
https://github.com/fer8a/nestjs-grpc-scaffold

grpc microservice nestjs nestjs-boilerplate nestjs-starter typescript

Last synced: 4 days ago
JSON representation

GRPC boilerplate to build microservices using the NestJS framework

Awesome Lists containing this project

README

        




NestJS GRPC Scaffold


An awesome template to jumpstart your projects!


Explore the NestJS docs »





Table of Contents



  1. About The Project


  2. Features

  3. Folder Structure


  4. Getting Started


  5. Roadmap

  6. Contributing

  7. License

## About The Project

[NestJS](https://nestjs.com/) is a great Framework to start building very robust server-side applications. There are many great templates available on GitHub; however, I didn't find one that really suited my needs so I created this ~~very opinionated~~ one. I wanted a boilerplate that would integrate many of the great features Nest has to offer, _out-of-the-box_, with the minimun configuration effort to start bootstraping an application right away.

Here's why:
* Your time should be focused on creating something amazing. A project that solves a problem and helps others
* You shouldn't be doing the same tasks over and over; like integrating a DB layer, a microservice layer, etc.
* You should implement DRY principles to the rest of your life as well :)

Of course, no one template will serve all projects since your needs may be different, but here's for everyone who find it helpful.

(back to top)

### Built With

* [NestJS](https://nestjs.com/)
* [Prisma](https://www.prisma.io/)
* [Mongoose](https://mongoosejs.com/)
* [Pino](https://getpino.io/)
* [Open Telemetry](https://opentelemetry.io/)

(back to top)

## Features

Every time I start building an API, a microservice, a server-side app; there's always a set of features that I end up reusing over and over given the utility they provide. That's the main reason I have decided to create this project to bootstrap as much of this _core_ functionality as possible.

Let's list a few of the features provided on this project:
- Open Telemetry to instrument, generate, collect, and export telemetry data.
- Terminus module for the healthcheck of your application exposed at `/health` route.
- Global exception middleware so you can catch and customize any target exception to your likings.
- Global request-logger middleware so all the incoming and outgoing calls are logged by default with their metadata.
- Global Cache middleware to enhance the response time of all the `GET` calls.
- A programmatic way to access `environment` variables through DI.
- A database ORM to interact with multiple DB drivers using the great [Prisma](https://www.prisma.io/) package.
- A programmatic way to generate logs using DI upon the right context of your application.
- Husky package with _lint-staged_ bundled with _pre-commit and pre-push_ hooks that running linter, formatter and tests

(back to top)

## Folder Structure

Following the _Nest way_ of things, I ended up up with a module-based approach when it came to structuring the code.
That being said, the project comes with a series of folders and modules that you can reuse and extend to fit your needs, let's talk a bit about it.
- `config` Like its name implies is a folder to place all sort of configurations for your app. `cache` and `env` configurations live here. You can also and include more modules in it, like your `db` for instance, or any other module that relies on environment variables or externals configurations.
- `config/tracer` Open Telemetry SDK and configuration file.
- `config/db` Quite self explanatory, this is your DB module, the folder to place all your configs and ORM layer.
- `config/logger` Module where you can place the log driver used by your app. Comes with Pino and Winston out of the box.
- `core` This is it, the source of ~~evil~~ the base code. It's a module wrapping the minimun functionality that the app should have, again this is very opinionated of me, so you may choose to adjust it to fit your needs.
- `providers` Folder to place external third-party SDKs or libraries (AWS, Sendgrid, etc).
- `resources` Interfaces and endpoints with the bussiness logic of your app should be placed here. Modules, Controllers, Services and entities related to the solution you're building.
- `resources/healthcheck` This exposes the healthcheck functionality of your app.

(back to top)

## Getting Started

To get a local copy up and running follow these simple example steps.

### Prerequisites

* npm
```sh
npm install npm@latest -g
```
* Nest
```sh
npm i -g @nestjs/cli
```

### Installation and Usage

1. Clone the repo
```sh
git clone https://github.com/your_username_/Project-Name.git
```
2. Install NPM packages
```sh
npm install
```
3. Run the application
```sh
npm run start
```

(back to top)

## Roadmap

- [] Add unit tests

(back to top)

## Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
Don't forget to give the project a star! Thanks again!

1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

(back to top)

## License

Distributed under the MIT License. See `LICENSE.md` for more information.

(back to top)

[contributors-shield]: https://img.shields.io/github/contributors/othneildrew/Best-README-Template.svg?style=for-the-badge
[contributors-url]: https://github.com/othneildrew/Best-README-Template/graphs/contributors
[forks-shield]: https://img.shields.io/github/forks/othneildrew/Best-README-Template.svg?style=for-the-badge
[forks-url]: https://github.com/othneildrew/Best-README-Template/network/members
[stars-shield]: https://img.shields.io/github/stars/othneildrew/Best-README-Template.svg?style=for-the-badge
[stars-url]: https://github.com/othneildrew/Best-README-Template/stargazers
[issues-shield]: https://img.shields.io/github/issues/othneildrew/Best-README-Template.svg?style=for-the-badge
[issues-url]: https://github.com/othneildrew/Best-README-Template/issues
[license-shield]: https://img.shields.io/github/license/othneildrew/Best-README-Template.svg?style=for-the-badge
[license-url]: https://github.com/othneildrew/Best-README-Template/blob/master/LICENSE.txt