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

https://github.com/dustinsgoodman/serverless-microservices-graphql-template

A Serverless Framework getting started template for building microservice architectures with a public GraphQL API using nx for monorepo support.
https://github.com/dustinsgoodman/serverless-microservices-graphql-template

apollo-server graphql graphql-server hacktoberfest microservices-architecture nodejs nx serverless serverless-framework

Last synced: 11 months ago
JSON representation

A Serverless Framework getting started template for building microservice architectures with a public GraphQL API using nx for monorepo support.

Awesome Lists containing this project

README

          

# Serverless Micoservices w/ GraphQL Template

[![serverless](http://public.serverless.com/badges/v3.svg)](http://www.serverless.com)
[![Nx monorepo](https://img.shields.io/badge/monorepo-Nx-blue)](https://nx.dev/)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/dustinsgoodman/serverless-microservices-graphql-template/blob/main/LICENSE.md)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/dustinsgodman/serverless-template)
[![codecov](https://codecov.io/gh/dustinsgoodman/serverless-microservices-graphql-template/branch/main/graph/badge.svg?token=HZCVZ0DPWD)](https://codecov.io/gh/dustinsgoodman/serverless-microservices-graphql-template)

A template for a Serverless Framework microservices architecture based on the [nx-serverless-template by sudokar](https://github.com/sudokar/nx-serverless).

## Table of contents

- [Whats Included](#whats-included)
- [Template Layout](#template-layout)
- [Prerequisites](#prerequisites)
- [Usage](#usage)
- [Further help](#further-help)
- [Contribution](#contribution)
- [Support](#support)
- [Maintainer](#maintainer)
- [License](#license)

## Whats Included

- A template project layout using latest version of Nx and Servrless Framework
- An easy to use workspace generator to generate a template/service with Serverless Framework files and related Nx configuration
- Configured with a basic AWS provider that can be easily adopted to any cloud provider
- Serverless Offline microservices architecture support

### How does this differ from the original template?

The original template is phenomenal, but I was aiming for some additional customizations and different core libraries. Specifically:

- This version uses esbuild instead of webpack
- This version provides some common utility functions for a microservices architecture
- Upstream used Nx Cloud and some other 3rd party tools where this version uses just GitHub Actions
- This version provides opinionated public-api and background-jobs services for consumption.

## Template Layout

```shell
.
├── services/ # each serverless configuration/template and its associated files
├── libs/ # shared libraries
├── tools/
├── README.md
├── jest.config.ts
├── jest.preset.ts
├── nx.json
├── package.json
├── serverless.common.yml # shared serverless configuration
├── tsconfig.base.json
├── workspace.json
├── .editorconfig
├── .eslintrc.json
├── .gitignore
├── .husky # git hooks
├── .nvmrc
├── .prettierignore
├── .prettierrc
├── docker-compose.yml
```

## Prerequisites

- [Node.js 16](https://nodejs.org/) - [nvm](https://github.com/nvm-sh/nvm) recommended
- [Yarn](https://yarnpkg.com)
- [Serverless Framework v3](https://serverless.com/)
- 💅 Code format plugins
- [Eslint](https://eslint.org/)
- [Prettier](https://prettier.io/)
- [EditorConfig](https://editorconfig.org/)
- [Jest](https://jestjs.io/) for testing

## Usage

**Install project dependencies**

```shell
yarn
```

**Setup and run infrastructure**

All needed services, such as databases, are managed via Docker. When working in this project, it is
recommended that you start all the infrastructure. When you're not working on the project, you should
stop all the infrastructure.

```shell
# Creates the docker container and starts it.
yarn infrastructure:setup

# Stops the docker container and deletes it.
yarn infrastructure:teardown

# Starts the docker container. Requires the container to exist.
yarn infrastructure:start

# Stops the docker container. Requires the container to exist.
yarn infrastructure:stop
```

**Generate a new service**

```shell
yarn workspace-generator service
```

**Generate a new library**

```shell
yarn workspace-generator lib
```

**Packaging services**

```shell
# Package a single service
yarn build

# Package all services afffected by a change
yarn affected:build

# Package all services
yarn all:build
```

Pass the `--stage=` flag if you're creating a build for a specific environment.

**Deploying services**

```shell
# Deploy a single service to a stage
yarn deploy --stage=

# Deploy all services to a stage
yarn deploy:all --stage=
```

**Removing deployed service**

```shell
# Remove a single service from a stage
yarn remove --stage=

# Remove all services for a stage
yarn remove:all --stage=
```

**Run tests**

```shell
# Run tests for a single service or library
yarn test

# Run tests for all services or libraries affected by a change
yarn test:affected

# Run all tests
yarn test:all
```

**Analyze function bundles**

When building serverless applications, it's important to understand your memory footprint due to Lambda's memory settings as you can experience unexpected errors. As such, the following script can be used to understand the memory footprint of your individual functions:

```shell
yarn analyze --function=
```

This will open the results in a new tab in your browser with the results using [esbuild visualizer](https://www.npmjs.com/package/esbuild-visualizer).

**Run offline / locally**

- To run a single service

```shell
yarn serve
```

**Understand your workspace**

```
yarn dep-graph
```

## Further help

- Visit [Serverless Documentation](https://www.serverless.com/framework/docs/) to learn more about Serverless framework
- Visit [Nx Documentation](https://nx.dev) to learn more about Nx dev toolkit

## Contribution

Found an issue? Feel free to raise an issue with information to reproduce. Pull requests are welcome to improve.

## Support

If you like this template, please go support [sudokar](https://github.com/sudokar) as this template would not have been possible without their original work. However, you can always leave this version a star ⭐. 😄

## Maintainer

This version of the template is authored and maintained by [dustinsgoodman](https://github.com/dustinsgoodman)

## License

MIT