Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding nestjs-bullmq-postgres kit to main site #1087

Merged
merged 17 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/website/src/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
ZustandIcon,
PrismaIcon,
ContentfulIcon,
NestJsIcon,
VuetifyIcon,
Nuxt3Icon,
XstateIcon,
Expand Down Expand Up @@ -109,6 +110,12 @@ export const FOOTER_NAV_ITEMS = HEADER_NAV_ITEMS.filter(
);

export const TECHNOLOGIES = [
{
key: 'nest',
name: 'NestJS',
tags: ['Framework'],
Icon: (props) => <NestJsIcon {...props} />,
},
{
key: 'express',
name: 'Express.js',
Expand Down
18 changes: 18 additions & 0 deletions packages/website/src/icons/NestJsIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Props } from './types';

export function NestJsIcon({ size = 48, className }: Props) {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
width={size}
height={size}
className={className}
viewBox="0 0 256 255"
>
<path
fill="#E0234E"
d="M150.736 0c-1.851 0-3.57.397-5.157.926c3.372 2.247 5.223 5.222 6.148 8.594c.067.463.199.794.265 1.256c.066.397.132.794.132 1.19c.265 5.818-1.52 6.545-2.777 9.983c-1.917 4.43-1.388 9.19.926 13.024c.198.463.463.992.793 1.455c-2.512-16.727 11.438-19.239 14.016-24.462c.198-4.561-3.57-7.603-6.545-9.718C155.694.528 153.116 0 150.736 0Zm21.023 3.768c-.264 1.521-.066 1.124-.132 1.918c-.066.529-.066 1.19-.132 1.719c-.132.528-.264 1.057-.463 1.586c-.132.53-.33 1.058-.528 1.587c-.265.529-.463.992-.728 1.52c-.198.265-.33.53-.529.794l-.396.595c-.33.463-.661.926-.992 1.322c-.397.397-.727.86-1.19 1.19v.066c-.397.331-.793.728-1.256 1.058c-1.388 1.058-2.975 1.851-4.43 2.843c-.462.33-.925.595-1.322.992c-.463.33-.86.66-1.256 1.058c-.463.396-.793.793-1.19 1.256c-.33.396-.727.86-.992 1.322c-.33.463-.66.925-.925 1.388c-.265.53-.463.992-.728 1.52c-.198.53-.396.993-.528 1.521c-.199.595-.331 1.124-.463 1.653c-.066.265-.066.595-.132.86c-.067.264-.067.529-.132.793c0 .529-.067 1.124-.067 1.653c0 .397 0 .793.067 1.19c0 .529.066 1.058.198 1.653c.066.529.198 1.057.33 1.586c.199.53.331 1.058.53 1.587c.131.33.33.661.462.926L139.63 35.04a163.425 163.425 0 0 0-7.669-1.984l-4.165-.991c-3.967-.794-8-1.389-12.032-1.785c-.132 0-.199-.067-.33-.067a118.206 118.206 0 0 0-11.835-.595c-2.909 0-5.818.132-8.66.33c-4.034.265-8.066.794-12.1 1.455c-.991.133-1.983.331-2.974.53c-2.05.396-4.033.859-5.95 1.322l-2.976.793c-.991.397-1.917.86-2.842 1.256l-2.182.992c-.132.066-.265.066-.33.132c-.662.33-1.257.595-1.852.925a3.22 3.22 0 0 0-.463.199c-.727.33-1.454.727-2.049 1.058c-.463.198-.926.462-1.322.66a5.96 5.96 0 0 1-.595.331c-.595.33-1.19.661-1.72.992a16.57 16.57 0 0 0-1.586.992c-.463.33-.925.595-1.322.925c-.066.066-.132.066-.199.132c-.396.265-.859.595-1.256.926l-.132.132l-.991.793c-.133.067-.265.199-.397.265c-.33.264-.661.595-.992.86c-.066.131-.198.198-.264.264c-.397.397-.794.727-1.19 1.124c-.067 0-.067.066-.132.132c-.397.33-.794.727-1.19 1.124c-.067.066-.067.132-.133.132c-.33.33-.66.661-.991 1.058c-.132.132-.33.264-.463.396c-.33.397-.727.794-1.124 1.19c-.066.133-.198.199-.265.331c-.528.529-.991 1.058-1.52 1.587l-.198.198c-1.058 1.124-2.182 2.248-3.372 3.24a37.581 37.581 0 0 1-3.703 2.909a49.985 49.985 0 0 1-3.966 2.512a40.292 40.292 0 0 1-4.165 1.983a47.626 47.626 0 0 1-4.298 1.587c-2.776.595-5.62 1.719-8.065 1.917c-.53 0-1.124.132-1.653.198a66.66 66.66 0 0 0-1.653.397l-1.587.595c-.529.198-1.057.463-1.586.727c-.463.33-.992.595-1.455.926c-.463.33-.925.727-1.322 1.124c-.463.33-.926.793-1.322 1.19c-.397.463-.794.86-1.124 1.322c-.33.529-.727.992-.992 1.52c-.33.464-.661.992-.926 1.521c-.264.595-.528 1.124-.727 1.72a50.953 50.953 0 0 0-.595 1.718c-.132.529-.264 1.058-.33 1.587c0 .066-.067.132-.067.198c-.132.595-.132 1.389-.198 1.785c-.066.463-.132.86-.132 1.322c0 .265 0 .595.066.86c.066.463.132.86.265 1.256c.132.397.264.793.463 1.19v.066c.198.397.462.794.727 1.19c.264.397.529.794.86 1.19c.33.33.726.728 1.123 1.058c.397.397.794.727 1.256 1.058c1.587 1.388 1.984 1.851 4.033 2.909c.33.198.661.33 1.058.529c.066 0 .132.066.198.066c0 .132 0 .198.067.33c.066.53.198 1.058.33 1.587c.132.595.33 1.124.529 1.587c.198.397.33.793.529 1.19c.066.132.132.265.198.33c.265.53.53.992.794 1.455l.991 1.388c.33.397.727.86 1.124 1.257c.397.396.794.727 1.256 1.123c0 0 .067.067.132.067c.397.33.794.66 1.19.925c.463.33.926.595 1.455.86c.463.264.992.529 1.52.727c.397.198.86.33 1.323.463c.066.066.132.066.264.132c.265.066.595.132.86.198c-.199 3.57-.265 6.942.264 8.132c.595 1.322 3.504-2.71 6.413-7.338c-.396 4.561-.66 9.916 0 11.503c.727 1.653 4.694-3.504 8.132-9.19c46.874-10.842 89.648 21.553 94.144 67.303c-.86-7.14-9.652-11.107-13.685-10.115c-1.984 4.892-5.355 11.173-10.776 15.073c.462-4.363.264-8.859-.662-13.222c-1.454 6.082-4.297 11.768-8.198 16.66c-6.28.463-12.56-2.578-15.867-7.14c-.264-.198-.33-.595-.528-.86c-.199-.462-.397-.925-.53-1.388a5.488 5.488 0 0 1-.396-1.388c-.066-.463-.066-.926-.066-1.455v-.991c.066-.463.198-.926.33-1.389c.132-.462.265-.925.463-1.388c.265-.463.463-.926.793-1.388c1.124-3.174 1.124-5.752-.925-7.273a7.53 7.53 0 0 0-1.256-.66c-.265-.067-.595-.2-.86-.265c-.198-.067-.33-.133-.529-.199c-.462-.132-.925-.264-1.388-.33a5.037 5.037 0 0 0-1.388-.199c-.463-.066-.992-.132-1.455-.132c-.33 0-.66.066-.992.066c-.528 0-.991.067-1.454.199c-.463.066-.926.132-1.388.264c-.463.132-.926.265-1.389.463c-.462.198-.86.397-1.322.595c-.397.198-.793.463-1.256.661c-15.404 10.05-6.215 33.585 4.297 40.395c-3.967.727-8 1.587-9.123 2.446l-.132.132c2.842 1.72 5.817 3.174 8.925 4.43c4.231 1.388 8.727 2.644 10.71 3.173v.066a63.96 63.96 0 0 0 16.66 1.19c29.288-2.05 53.287-24.329 57.65-53.683c.132.595.265 1.124.397 1.719c.198 1.19.463 2.446.595 3.702v.067c.132.595.198 1.19.265 1.719v.264c.066.595.132 1.19.132 1.719c.066.727.132 1.454.132 2.182v1.057c0 .331.066.728.066 1.058c0 .397-.066.794-.066 1.19v.926c0 .463-.066.86-.066 1.322c0 .265 0 .529-.067.86c0 .462-.066.925-.066 1.454c-.066.198-.066.397-.066.595c-.066.529-.132.992-.199 1.52c0 .199 0 .397-.066.596c-.066.66-.198 1.256-.264 1.917v.132c-.132.595-.265 1.257-.397 1.852v.198l-.397 1.785c0 .066-.066.198-.066.264c-.132.595-.264 1.19-.463 1.786v.198c-.198.661-.396 1.256-.528 1.851c-.067.066-.067.132-.067.132l-.595 1.983c-.264.662-.462 1.257-.727 1.918c-.264.66-.463 1.322-.727 1.917c-.265.661-.53 1.256-.793 1.917h-.067c-.264.595-.529 1.256-.86 1.851a3.22 3.22 0 0 1-.198.463c-.066.067-.066.132-.132.199c-4.297 8.66-10.644 16.263-18.577 22.213c-.53.33-1.058.728-1.587 1.124c-.132.132-.33.199-.463.33c-.463.331-.925.662-1.454.992l.198.397h.066l2.777-.397h.066c1.72-.264 3.438-.595 5.157-.925c.463-.066.992-.198 1.454-.33c.331-.067.595-.133.926-.199c.463-.066.926-.198 1.388-.265c.397-.132.794-.198 1.19-.33c6.612-1.587 13.025-3.769 19.173-6.347c-10.512 14.346-24.594 25.916-41.056 33.519c7.603-.529 15.206-1.785 22.545-3.9c26.643-7.868 49.055-25.784 62.476-49.915a105.527 105.527 0 0 1-17.785 42.51a104.082 104.082 0 0 0 17.652-14.677c14.81-15.47 24.528-35.106 27.834-56.196a105.277 105.277 0 0 1 1.917 31.867c47.733-66.576 3.967-135.597-14.346-153.778c-.067-.132-.132-.198-.132-.33c-.067.066-.067.066-.067.132c0-.067 0-.067-.066-.132c0 .793-.066 1.586-.132 2.38c-.198 1.52-.397 2.975-.661 4.43c-.33 1.454-.727 2.908-1.124 4.363a54.989 54.989 0 0 1-1.587 4.23a56.872 56.872 0 0 1-1.983 4.034c-.727 1.256-1.52 2.578-2.38 3.768a50.509 50.509 0 0 1-2.71 3.57c-.993 1.19-2.05 2.248-3.108 3.306a42.608 42.608 0 0 1-1.917 1.652c-.53.463-.992.86-1.521 1.323c-1.19.925-2.38 1.785-3.702 2.578c-1.256.793-2.579 1.587-3.9 2.248c-1.39.661-2.778 1.256-4.166 1.851a46.553 46.553 0 0 1-4.297 1.388a53.252 53.252 0 0 1-4.43.992c-1.52.265-3.04.397-4.495.529c-1.058.066-2.116.132-3.174.132c-1.52 0-3.041-.132-4.495-.264c-1.521-.133-3.042-.331-4.496-.662c-1.52-.264-2.975-.66-4.43-1.123h-.066c1.455-.133 2.91-.265 4.364-.53a47.921 47.921 0 0 0 4.43-.991a46.546 46.546 0 0 0 4.296-1.388c1.455-.53 2.843-1.19 4.166-1.852c1.388-.66 2.644-1.388 3.966-2.181c1.256-.86 2.513-1.72 3.703-2.645a36.15 36.15 0 0 0 3.371-2.975c1.124-.992 2.116-2.115 3.108-3.24a65.335 65.335 0 0 0 2.776-3.57c.132-.198.265-.462.397-.66c.661-1.058 1.322-2.116 1.917-3.174a45.566 45.566 0 0 0 1.984-4.033a46.326 46.326 0 0 0 1.586-4.23c.463-1.39.794-2.844 1.124-4.298c.265-1.52.53-2.975.661-4.43c.132-1.52.265-3.04.265-4.495c0-1.058-.066-2.116-.132-3.174c-.132-1.52-.33-2.975-.53-4.43a47.926 47.926 0 0 0-.99-4.429c-.464-1.388-.926-2.843-1.455-4.231c-.53-1.388-1.19-2.777-1.851-4.099c-.728-1.322-1.455-2.645-2.248-3.9a72.995 72.995 0 0 0-2.645-3.637a139.879 139.879 0 0 0-3.041-3.372a41.356 41.356 0 0 0-1.719-1.652a121.727 121.727 0 0 0-9.19-6.48a12.31 12.31 0 0 0-1.322-.66c-2.181-1.389-4.23-2.116-6.28-2.777Z"
/>
</svg>
);
}
1 change: 1 addition & 0 deletions packages/website/src/icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export { ExpoIcon } from './ExpoIcon';
export { ZustandIcon } from './ZustandIcon';
export { PrismaIcon } from './PrismaIcon';
export { ContentfulIcon } from './Contentful';
export { NestJsIcon } from './NestJsIcon';
export { VuetifyIcon } from './VuetifyIcon';
export { Nuxt3Icon } from './Nuxt3Icon';
export { XstateIcon } from './XstateIcon';
Expand Down
1 change: 1 addition & 0 deletions starter-kits.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"express-apollo-prisma": "Express.js, Apollo Server, and Prisma",
"express-typeorm-postgres": "Express.js, TypeOrm, and PostgreSQL",
"lit-mobx-vaadin": "Lit, Mobx, and Vaadin",
"nestjs-bullmq-postgresql": "NestJS, BullMQ, and PostgreSQL",
"next-chakra-ui": "NextJS and Chakra UI",
"next-react-query-tailwind": "NextJS, React Query, and TailwindCSS",
"nuxt2-pinia-tailwind": "Nuxt 2, Pinia and TailwindCSS",
Expand Down
7 changes: 7 additions & 0 deletions starters/nestjs-bullmq-postgresql/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.github
.vscode
.idea
.git
node_modules
pg_data
tools
11 changes: 11 additions & 0 deletions starters/nestjs-bullmq-postgresql/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = tab
insert_final_newline = true
trim_trailing_whitespace = true


15 changes: 15 additions & 0 deletions starters/nestjs-bullmq-postgresql/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
username=test
password=ettpg
database=pgdatabase
database_port=5432
cache_port=6379
queue_port=6479

# has to be either "mysql" | "postgres" | "sqlite" | "mariadb" | "mssql" | "db2" | "snowflake" | "oracle"
dialect=postgres
host=localhost

localhost_port=3000

# comma seperated list of allowed origins for CORS
origins_urls=http://localhost:3000/
25 changes: 25 additions & 0 deletions starters/nestjs-bullmq-postgresql/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
40 changes: 40 additions & 0 deletions starters/nestjs-bullmq-postgresql/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# compiled output
/dist
/node_modules

# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# misc
.env
misc
postgres.db.env
1 change: 1 addition & 0 deletions starters/nestjs-bullmq-postgresql/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16.14.2
8 changes: 8 additions & 0 deletions starters/nestjs-bullmq-postgresql/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"singleQuote": true,
"trailingComma": "es5",
"endOfLine": "lf",
"printWidth": 100,
"tabWidth": 2,
"useTabs": true
}
151 changes: 151 additions & 0 deletions starters/nestjs-bullmq-postgresql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# nestjs-bullmq-postgresql starter kit

This starter kit features NestJS, BullMQ and PostgreSQL.

## Tech Stack

- [NestJS](https://nestjs.com/)
- [PostgreSQL](https://www.postgresql.org/)
- [BullMQ](https://docs.bullmq.io/)

## Included Tooling

- [Jest](https://jestjs.io/)
- [TypeScript](https://www.typescriptlang.org/)
- [Sequelize](https://sequelize.org/)
- [Swagger](https://swagger.io/)
- [ESLint](https://eslint.org/)
- [Prettier](https://prettier.io/)

## CLI Installation

You can choose from either `npm`, `yarn` or `pnpm` to install the kit.

```bash
npm create @this-dot/starter -- --name my-project-name --kit nestjs-bullmq-postgresql
```

```bash
yarn create @this-dot/starter --name my-project --kit nestjs-bullmq-postgresql
```

```bash
pnpm create @this-dot/starter --name my-project-name --kit nestjs-bullmq-postgresql
```

Follow these set of directions to finish setting up your kit.

- `cd` into your project directory and run `npm install`(or `yarn`, `pnpm`).
- Make sure you have [docker](https://docs.docker.com/engine/install/) installed on your machine.
- Create a `.env` file and copy the contents of the `.env.example` into it.
- Create a `.postgres.db.env` file and copy the contents of the `.postgres.db.env.example` into it.
- Run `npm run infrastructure:start` (or `yarn`, `pnpm`) to start the database.
- Run `npm run start` (or `yarn`, `pnpm`) to start the development server.

### Manual installation

```bash
git clone https://github.com/thisdot/starter.dev.git
```

- Copy and rename the `starters/nestjs-bullmq-postgresql` directory to the name of your new project.
- Make sure you have [docker](https://docs.docker.com/engine/install/) installed on your machine.
- `cd` into your project directory and run `npm install`(or `yarn`, `pnpm`).
- Create a `.env` file and copy the contents of the `.env.example` into it.
- Create a `.postgres.db.env` file and copy the contents of the `.postgres.db.env.example` into it.
- Run `npm run infrastructure:start` (or `yarn`, `pnpm`) to start the database.
- Run `npm run start` (or `yarn`, `pnpm`) to start the development server.

## Built-in Scripts

- `npm run infrastructure:start` - Creates and starts all the Docker containers for services from the Docker Compose configuration.
- `npm run infrastructure:stop` - Stops all of the Docker containers for services from the Docker Compose configuration.
- `npm run start` - Starts the Nest application on a local server
- `npm run build` - Builds the Nest application
- `npm run format` - Formats the entire codebase using Prettier
- `npm run lint` - Checks the entire project with ESLint
- `npm run test` - Runs the Jest test suite
- `npm run test:e2e` - Runs the e2e test suite

## Kit Organization / Architecture

Inside the `src` directory, you will find the code for the health check, queue and technology example CRUD implementations.

```
.
├── health
│ ├── health.controller.ts
│ └── health.module.ts
├── queue
│ ├── queue.controller.ts
│ ├── queue.module.ts
│ └── queue.processor.ts
├── technology
│ ├── dto
│ │ └── create-technology.dto.ts
│ ├── technology.controller.spec.ts
│ ├── technology.controller.ts
│ ├── technology.model.ts
│ ├── technology.module.ts
│ └── technology.service.ts
├── app.module.ts
└── main.ts
```

### Health check

Inside the `src/health/health.controller.ts` file, you will find the `HealthController` which uses the `@nestjs/terminus` package to check on the health of your application.

```js
@Controller('health')
export class HealthController {
constructor(private health: HealthCheckService, private db: SequelizeHealthIndicator) {}

@Get()
@HealthCheck()
checkHealth() {
return this.health.check([() => this.db.pingCheck('sequelize')]);
}
}
```

You can check on the health of your app by starting the local server and going to the `http://localhost:3000/health` endpoint.

### Queue

Inside the `src/queue/queue.processor.ts` file, you will find an example `QueueProcessor` class that uses BullMQ.

```js
@Processor('queue')
class QueueProcessor extends WorkerHost {
async process(job: Job<any, any, string>): Promise<any> {
console.log(`Processing job ${job}`);
}

@OnWorkerEvent('completed')
onCompleted() {
console.log('Job Completed');
}
}
```

### Technology example

Inside the `src/technology` directory, you will find an example of a technology CRUD implementation with tests.

```ts
create(createTechnologyDto: CreateTechnologyDto): Promise<Technology> {
return this.technologyModel.create({
displayName: createTechnologyDto.displayName,
description: createTechnologyDto.description,
url: createTechnologyDto.url,
});
}
```
## Swagger UI

This starter kit uses [Swagger UI](https://swagger.io/tools/swagger-ui/) to show the REST API documentation for the technology and health API's.

You can view the documenation at http://localhost:3000/api

![swagger ui example](./swagger-ui-example.png)
32 changes: 32 additions & 0 deletions starters/nestjs-bullmq-postgresql/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: '3'
services:
postgres:
image: 'postgres'
ports:
- '${database_port}:${database_port}'
volumes:
- ./misc/pg_data:/var/lib/postgresql/data
env_file:
- ./postgres.db.env

redis_cache:
image: 'redis:alpine'
command: redis-server
ports:
- '${cache_port}:${cache_port}'
volumes:
- ./misc/cache_data:/var/lib/redis
- ./misc/cache_conf:/usr/local/etc/redis/redis.conf
environment:
- REDIS_REPLICATION_MODE=master

redis_queue:
image: 'redis:alpine'
command: redis-server
ports:
- '${queue_port}:${cache_port}'
volumes:
- ./misc/queue_data:/var/lib/redis
- ./misc/queue_conf:/usr/local/etc/redis/redis.conf
environment:
- REDIS_REPLICATION_MODE=master
9 changes: 9 additions & 0 deletions starters/nestjs-bullmq-postgresql/nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true,
"plugins": ["@nestjs/swagger"]
}
}
Loading
Loading