-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 47aa9b8
Showing
79 changed files
with
18,696 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module.exports = { | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
project: './tsconfig.json', | ||
sourceType: 'module', | ||
}, | ||
plugins: ['@typescript-eslint/eslint-plugin'], | ||
extends: [ | ||
'plugin:@typescript-eslint/eslint-recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'prettier', | ||
'prettier/@typescript-eslint', | ||
], | ||
root: true, | ||
env: { | ||
node: true, | ||
jest: true, | ||
}, | ||
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', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# compiled output | ||
/dist | ||
/node_modules | ||
|
||
# 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 | ||
|
||
# env | ||
.env.* | ||
/environment/**/.env.* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules/ | ||
dist/ | ||
package.json | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"useTabs": false, | ||
"tabWidth": 4, | ||
"printWidth": 100, | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"semi": true, | ||
"bracketSpacing": true, | ||
"arrowParens": "avoid" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"types": [ | ||
{ "type": "feat", "section":"Features ⭐️" }, | ||
{ "type": "fix", "section": "Bug Fixes \uD83D\uDC1B" }, | ||
{ "type": "refactor", "section": "Refactoring ♻" }, | ||
{ "type": "perf", "section": "Performance \uD83D\uDE80" }, | ||
{ "type": "test", "section": "Tests \uD83E\uDDEA" }, | ||
{ "type": "ci", "section": "CI, Deployment and Configuration \uD83D\uDEE0" }, | ||
{ "type": "build", "section": "Build System and Development \uD83C\uDFD7" }, | ||
{ "type": "docs", "section": "Documentation \uD83D\uDCDD" }, | ||
{ "type": "style", "section": "Code style \uD83C\uDF08" }, | ||
{ "type": "chore", "hidden": true } | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
FROM node:14-alpine AS builder | ||
|
||
# Create api directory | ||
WORKDIR /app | ||
|
||
# A wildcard is used to ensure both package.json AND package-lock.json are copied | ||
COPY package*.json ./ | ||
COPY database ./prisma/ | ||
|
||
# Install api dependencies | ||
RUN npm install | ||
# Generate database client, leave out if generating in `postinstall` script | ||
# RUN npx database generate | ||
|
||
COPY . . | ||
|
||
RUN npm run build | ||
|
||
FROM node:14-alpine | ||
|
||
COPY --from=builder /app/node_modules ./node_modules | ||
COPY --from=builder /app/package*.json ./ | ||
COPY --from=builder /app/dist ./dist | ||
|
||
EXPOSE 3000 | ||
CMD [ "npm", "run", "start:prod" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
# App-name ♻ | ||
|
||
- [Description](#description) | ||
- [Try it out](#try-it-out) | ||
- [Installation](#installation) | ||
- [Configuration](#configuration) | ||
- [Running the app](#running-the-app) | ||
- [DB migrations](#db-migrations) | ||
- [Tests](#tests) | ||
- [APIs docs](#apis-docs) | ||
- [Database schema](#database-schema) | ||
- [Project structure tree](#project-structure-tree) | ||
- [Support](#support) | ||
|
||
## Description | ||
|
||
This repository build as monorepo and consist of ___ project: | ||
|
||
1. ... | ||
2. ... | ||
|
||
Read more about project structure [here](#project-structure-tree). | ||
|
||
Building with: | ||
|
||
<p> | ||
<a href="https://nodejs.org/" target="blank"> | ||
<img src="https://nodejs.org/static/images/logos/nodejs-new-pantone-black.svg" height="40" alt="Node.js logo" /> | ||
</a> | ||
<a href="https://www.typescriptlang.org/" target="blank"> | ||
<img src="https://upload.wikimedia.org/wikipedia/commons/4/4c/Typescript_logo_2020.svg" height="40" alt="TypeScript logo" /> | ||
</a> | ||
<a href="http://nestjs.com/" target="blank"> | ||
<img src="https://nestjs.com/img/logo_text.svg" height="45" alt="NestJS logo" /> | ||
</a> | ||
<a href="https://www.postgresql.org/" target="blank"> | ||
<img src="https://www.postgresql.org/media/img/about/press/elephant.png" width="40" alt="PostgreSQL logo" /> | ||
</a> | ||
<a href="https://www.prisma.io/" target="blank"> | ||
<img src="https://cdn.worldvectorlogo.com/logos/prisma-2.svg" height="40" alt="Prisma logo" /> | ||
</a> | ||
</p> | ||
|
||
|
||
## Try it out | ||
<!--- | ||
This project contains configured ready to code developer environment with modern [Gitpod](https://www.gitpod.io/) online tool. | ||
To try it just click on the button below: | ||
[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://gitlab.com/SP-OKO/security/social/social-security-backend) | ||
--> | ||
## Installation | ||
|
||
First of all, make sure you have installed the following software on your environment: | ||
|
||
- [Node.js](https://nodejs.org/) version 14+ | ||
- [PostgreSQL](https://www.postgresql.org/) version 12+ | ||
|
||
```bash | ||
$ git clone [email protected]:SP-OKO/smart_citi/iot-backend.git | ||
$ cd nest-prisma-monorepo-template | ||
$ npm install | ||
``` | ||
|
||
## Configuration | ||
|
||
Before the first running app configure your project environment variables: | ||
<!--- | ||
- copy `.env.example.{app_name}` to `{app_name}.{your_environment}.env` (where `app_name = api | admin` - current monorepo api name; `your_environment= development | production | testing | gitpod | ...` - current environment; example: `api..env.development` and `admin..env.development`) [required] | ||
- open `.env.example` and read comments for every environment variables for more information [optional] or reade detail description of all configuration parameters in following documents: | ||
- [api.production.env](docs/api-configuration.md) | ||
- [admin.production.env](docs/admin-api-configuration.md) | ||
- set up correct environments variables for every api [required] | ||
- if you want use TypeORM migrations CLI, you mast create `ormconfig.js` from `ormconfig.example.js`* [optional] | ||
``` | ||
* You can running api on new clean db in two way: | ||
1. Sepup envirement variable `TYPEORM_MIGRATIONS_RUN = true`, that automaticaly run migrations on api start (default) | ||
2. Manualy run migration with `npm run migrate` command (for that you must configure `ormconfig.js` file) | ||
``` | ||
--> | ||
|
||
## Running the app | ||
|
||
```bash | ||
# Development mode | ||
$ npm run start:dev | ||
|
||
# Production mode | ||
$ npm run build | ||
$ npm run start:prod | ||
``` | ||
|
||
more scripts view in `package.json` file. | ||
|
||
## Db migrations | ||
<!--- | ||
```bash | ||
# run migration (running all migartions) | ||
$ npm run migrate | ||
# migration rollback (rollback only last migration!) | ||
$ npm run migration:revert | ||
# create new migration manually | ||
$ npm run migration:create -- "YouMigrationName" | ||
# generate new migration from entity changes you made | ||
$ npm run migration:generate -- "YouMigrationName" | ||
``` | ||
--> | ||
## Tests | ||
|
||
**WIP...** | ||
|
||
```bash | ||
# unit tests | ||
$ npm run test | ||
|
||
# e2e tests | ||
$ npm run test:e2e | ||
|
||
# test coverage | ||
$ npm run test:cov | ||
``` | ||
|
||
## APIs docs | ||
|
||
<!--- | ||
- **social-security-api** | ||
- Swagger [https://api.social.openstat.org.ua/swagger](https://api.social.openstat.org.ua/swagger) | ||
- OpenAPI Specification [https://api.social.openstat.org.ua/swagger-json](https://api.social.openstat.org.ua/swagger-json) | ||
- Api monitoring ui [https://api.social.openstat.org.ua/swagger-stats/ui](https://api.social.openstat.org.ua/swagger-stats/ui) | ||
- **admin-api** | ||
- Swagger [https://admin.social.openstat.org.ua/swagger](https://admin.social.openstat.org.ua/swagger) | ||
- OpenAPI Specification [https://admin.social.openstat.org.ua/swagger-json](https://admin.social.openstat.org.ua/swagger-json) | ||
--> | ||
|
||
## Database schema | ||
|
||
<!--- | ||
![](docs/assets/db-schema-light.png) | ||
--> | ||
|
||
## Project structure tree | ||
``` | ||
├─ apps - main project folder with monorepo apps (@see https://docs.nestjs.com/cli/monorepo#monorepo-mode) | ||
│ ├─ main-api - main-api files in standard Nest api structure | ||
| | └─ ... | ||
│ └─ service-x - service-x files in standard Nest api structure | ||
| └─ ... | ||
├─ dist - folder with compiled *.js files (has same structure with /apps, /libs) | ||
| └─ ... | ||
├─ docs - api documents and assets | ||
├─ database - database management files | ||
│ ├─ _pgmigrations - db migrations files | ||
│ ├─ _seeds - db seeds files (custom implementations with prisma runner) | ||
| └─ sql - sql files and scripts | ||
| schema.prisma - prisma schema file (https://www.prisma.io/docs/concepts/components/prisma-schema/) | ||
├─ environment - app environment files (with same folder structure as apps/) | ||
│ ├─ main-api - folder with main-api env files | ||
| | .env - default main-api env file | ||
| └─ service-x - folder with service-x env files | ||
| .env - default service-x env file | ||
| .env - default project env file (with db config and other used in all apps) | ||
├─ libs - own libs sharing between monorepo apps | ||
│ ├─ common - lib with common modules? configs and general nestjs entities files | ||
| └─ prisma - custom prisma service wrapper | ||
└─ node_modules - nodejs third-party libs and dependencies for current project | ||
└─ ... | ||
.eslintrc.js - eslint config | ||
.gitignore - Git untracked files list | ||
.prettierrc - prettier configuration file | ||
.prettierignore - prettier ignored files list | ||
nest-cli.json - nest-cli configuration file | ||
ormconfig.example.js - example typeorm configuration file, used for working with migrations CLI | ||
package.json - npm manifest file | ||
package-lock.json - autogenerated file using by npm | ||
README.md - project readme file | ||
tsconfig.build.json - ts compiler build configuration | ||
tsconfig.json - typescript compiler configuration | ||
``` | ||
|
||
## Support | ||
|
||
Find bug? - Report it: | ||
- on [Gitlab]() | ||
- or in [Trello]() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Module, ValidationPipe } from '@nestjs/common'; | ||
import { APP_FILTER, APP_INTERCEPTOR, APP_PIPE } from '@nestjs/core'; | ||
import { ConfigModule } from '@nestjs/config'; | ||
|
||
import { loadAppConfig } from '@app/common/config'; | ||
import { ApiStatusModule } from '@app/common/api-status'; | ||
import { LoggingInterceptor } from '@app/common/interceptors'; | ||
import { PrismaExceptionFilter } from '@app/prisma'; | ||
|
||
@Module({ | ||
imports: [ConfigModule.forRoot(loadAppConfig({ appName: 'main-api' })), ApiStatusModule], | ||
providers: [ | ||
{ | ||
provide: APP_PIPE, | ||
useValue: new ValidationPipe({ | ||
transform: true, | ||
}), | ||
}, | ||
{ | ||
provide: APP_INTERCEPTOR, | ||
useClass: LoggingInterceptor, | ||
}, | ||
{ | ||
provide: APP_FILTER, | ||
useClass: PrismaExceptionFilter, | ||
}, | ||
], | ||
}) | ||
export class AppModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { NestFactory } from '@nestjs/core'; | ||
import { Logger } from '@nestjs/common'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import helmet from 'helmet'; | ||
import compression from 'compression'; | ||
|
||
import { API_CONF, ApiConfig } from '@app/common/config'; | ||
import { initSwaggerModule } from '@app/common/swagger'; | ||
|
||
import { AppModule } from './app.module'; | ||
|
||
async function bootstrap() { | ||
const app = await NestFactory.create(AppModule); | ||
const apiConfig = app.get(ConfigService).get<ApiConfig>(API_CONF); | ||
const { appName, port, swagger, apiMonitoring } = apiConfig; | ||
const logger = new Logger(appName); | ||
|
||
app.enableCors(); | ||
app.use(compression()); | ||
app.use(helmet({ contentSecurityPolicy: false })); | ||
|
||
initSwaggerModule(app, apiConfig); | ||
|
||
await app.listen(port); | ||
|
||
logger.log(`app is listening on port ${port}`); | ||
if (swagger.isEnabled) { | ||
logger.log(`Swagger is exposed at ${swagger.apiBaseUrl}${swagger.uriPath}`); | ||
} | ||
if (apiMonitoring.isEnabled) { | ||
logger.log( | ||
`Api monitoring is exposed at ${swagger.apiBaseUrl}${apiMonitoring.swStatsOptions.uriPath}/ui`, | ||
); | ||
} | ||
} | ||
|
||
bootstrap().catch(e => console.error(e)); |
Oops, something went wrong.