Skip to content

Commit

Permalink
feat: upgrade template structure and dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
cyber-eternal committed Aug 10, 2021
1 parent 0c10839 commit 635cfa6
Show file tree
Hide file tree
Showing 63 changed files with 2,684 additions and 2,425 deletions.
10 changes: 5 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
NODE_ENV=
APP_PORT=
SERVICE_PATH=
TYPEORM_SYNCHRONIZE=
TYPEORM_MIGRATIONS_RUN=
TYPEORM_LOGGING=
SWAGGER_HOST=
AMQP_HOST=
AMQP_PORT=
AMQP_QUEUE=
Expand All @@ -20,5 +18,7 @@ TYPEORM_LOGGING=
TYPEORM_AUTO_LOAD_ENTITIES=
TYPEORM_MIGRATIONS_RUN=
TYPEORM_SYNCHRONIZE=
KEYCLOAK_CLIENT_ID=
SWAGGER_HOST=
TYPEORM_SYNCHRONIZE=
TYPEORM_MIGRATIONS_RUN=
TYPEORM_LOGGING=
KEYCLOAK_CLIENT_ID=
24 changes: 24 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
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',
},
};
85 changes: 35 additions & 50 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
Expand All @@ -20,12 +9,11 @@ lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
Expand All @@ -44,21 +32,12 @@ jspm_packages/
# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

Expand All @@ -70,37 +49,43 @@ typings/

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
# next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# compiled output
/dist
/node_modules

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
# Logs
logs
*.log
npm-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

src/tmp/*
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"singleQuote": true,
"trailingComma": "all"
"trailingComma": "all",
"semi": true
}
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

<p align="center">
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo_text.svg" width="320" alt="Nest Logo" /></a>
</p>

# Template for the [Node.js](http://nodejs.org) applications based on the [Nest.js](http://nestjs.org) framework for building efficient and scalable server-side applications.
# Template for the [Node.js](http://nodejs.org) applications based on the [Nest.js](http://nestjs.org) framework for building efficient and scalable server-side applications.

## Description

The template is based on Nest.js and TypeScript. Also has an implementation for the TypeORM to work with the Database, and RabbitMQ for the messaging(the RabbitMQ implementation can be easily removed if you are not using it). The template dockerized as well
The template is based on Nest.js(v 8.0.5) and TypeScript. Also has an implementation for the TypeORM to work with the Database, and RabbitMQ for the messaging(the RabbitMQ implementation can be easily removed if you are not using it). The template dockerized as well

## Configurations

Expand Down Expand Up @@ -72,12 +71,19 @@ $ docker-compose up
$ docker-compose up -d
```

## Adminer

to manage the MariaDB will be available on http://localhost:8081/

## Swagger UI

http://localhost:3001/api/doc

## Stay in touch

- Author - [Cyber-Eternal](https://github.com/cyber-eternal)
- Website - [https://cyber-eternal.github.io/](https://cyber-eternal.github.io/)

## License

Nest is [MIT licensed](https://github.com/cyber-eternal/nestjs-template/blob/master/LICENSE).

Nest is [MIT licensed](https://github.com/cyber-eternal/nestjs-template/blob/master/LICENSE).
1 change: 1 addition & 0 deletions config/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export default {
nodeEnv: process.env.NODE_ENV || 'development',
port: process.env.APP_PORT || 3000,
swaggerHost: process.env.SWAGGER_HOST || '',
swaggerPath: process.env.SWAGGER_PATH || '/api/doc',
};
5 changes: 5 additions & 0 deletions config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default async () => ({
app: (await import('./app')).default,
amqp: (await import('./amqp')).default,
database: (await import('./database')).default,
});
11 changes: 11 additions & 0 deletions config/schema/amqp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { number, string } from 'joi';

export default {
AMQP_HOST: string().required(),
AMQP_PORT: number(),
AMQP_USERNAME: string().required(),
AMQP_PASSWORD: string().required(),
AMQP_VHOST: string().uri(),
AMQP_QUEUE_PREFIX: string(),
AMQP_SEND_EMAIL_QUEUE: string(),
};
8 changes: 8 additions & 0 deletions config/schema/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { string, number } from 'joi';

export default {
NODE_ENV: string()
.valid('development', 'production', 'test', 'provision')
.default('development'),
PORT: number().default(3000),
};
13 changes: 13 additions & 0 deletions config/schema/database.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { string, number } from 'joi';

export default {
TYPEORM_TYPE: string().required().default('mysql'),
TYPEORM_HOST: string().required(),
TYPEORM_USERNAME: string().required(),
TYPEORM_PASSWORD: string().required(),
TYPEORM_DATABASE: string().required().default('docmodule'),
TYPEORM_PORT: number().required().default(3306),
TYPEORM_LOGGING: string().default('false'),
TYPEORM_MIGRATIONS_RUN: string().default('true'),
TYPEORM_SYNCHRONIZE: string().default('false'),
};
10 changes: 10 additions & 0 deletions config/schema/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { object as joiObject } from 'joi';
import app from './app';
import database from './database';
import amqp from './amqp';

export default joiObject({
...app,
...amqp,
...database,
});
69 changes: 49 additions & 20 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,71 @@
version: "3.0"
version: '3.8'

services:
mysql-db:
image: mariadb:10.4
restart: "always"
mariadb:
image: mariadb
restart: 'no'
volumes:
- mysql:/var/lib/mysql
- mariadb-data:/var/lib/mariadb
ports:
- 3306:3306
environment:
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
MYSQL_DATABASE: "core"
MYSQL_USER: "root"
MYSQL_PASSWORD: "password"
MYSQL_RANDOM_ROOT_PASSWORD: yes
MYSQL_DATABASE: core
MYSQL_USER: guest
MYSQL_PASSWORD: guest

adminer:
image: adminer
ports:
- 8081:8080
environment:
ADMINER_DEFAULT_DB_DRIVER: mysql
ADMINER_DEFAULT_DB_HOST: mariadb
ADMINER_DEFAULT_DB_SERVER: mariadb
ADMINER_DEFAULT_SERVER: mariadb
ADMINER_DEFAULT_DB_NAME: core
ADMINER_DESIGN: dracula
ADMINER_PLUGINS: tables-filter tinymce
expose:
- 8081
depends_on:
- mariadb

mq-service:
image: rabbitmq:3-management-alpine
ports:
- 15672:15672
- 5672:5672
environment:
RABBITMQ_DEFAULT_USER: "test"
RABBITMQ_DEFAULT_PASS: "password"
RABBITMQ_DEFAULT_USER: 'test'
RABBITMQ_DEFAULT_PASS: 'password'
volumes:
- rabbitmq-data:/var/lib/rabbitmq

api:
build: .
container_name: api
tty: true
command: yarn start
ports:
- ${APP_PORT}:3000
- 3000:3000
expose:
- 3000
volumes:
- ./:/usr/app
- ./node_modules:/usr/app/node_modules
- api-data:/var/lib/api
env_file: .env
depends_on:
- mysql-db
- mq-service
- mariadb
environment:
NODE_ENV: 'development'
APP_PORT: 3000
TYPEORM_HOST: mariadb
REDIS_HOST: redis
AMQP_HOST: mq-service

volumes:
mysql:
rabbitmq-data:
mariadb-data:
driver: local
rabbitmq-data:
driver: local
api-data:
driver: local
18 changes: 0 additions & 18 deletions jest.config.js

This file was deleted.

6 changes: 6 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"moduleNameMapper": {
"^@root/(.*)$": "<rootDir>/$1",
"^@app/(.*)$": "<rootDir>/src/$1"
}
}
Loading

0 comments on commit 635cfa6

Please sign in to comment.