Skip to content

Commit

Permalink
Integrate best practices (#39)
Browse files Browse the repository at this point in the history
* updated vscode settings

* added config, schema, upgraded sdk-nestjs to latest version

* added functionality for config yaml

* improved startup experience

* cache warmer app fix

* fixed queue worker app

* fixed transactions processor, deleted confings

* unified app module for tx processor

* some more simplifications

* processed queue module in the new simplified way

* cache warmer app processing

* simplified api

* major refactoring

* small improvements

* better loading of db entities

* added linting rules

* fixed metrics service import

* deleted abi, simplified linting rules, simplified package json

* code formatting, simplified eslint rules

* moved examples in apps/api

* added annotation to token service

* more restrictive dependencies

* implemented env-specific loaders
  • Loading branch information
tanghel authored May 7, 2024
1 parent 417cc20 commit 621818d
Show file tree
Hide file tree
Showing 128 changed files with 3,585 additions and 1,863 deletions.
1 change: 1 addition & 0 deletions .env.devnet
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
API_URL=https://devnet-api.multiversx.com
1 change: 1 addition & 0 deletions .env.mainnet
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
API_URL=https://api.multiversx.com
1 change: 1 addition & 0 deletions .env.testnet
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
API_URL=https://testnet-api.multiversx.com
116 changes: 116 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,55 @@ module.exports = {
extends: [
'plugin:@typescript-eslint/recommended',
// 'plugin:prettier/recommended',
'plugin:boundaries/strict',
],
root: true,
env: {
node: true,
jest: true,
},
settings: {
"import/resolver": {
typescript: {
alwaysTryTypes: true,
project: 'tsconfig.json'
},
},
'boundaries/elements': [
{
type: 'apps/api',
pattern: 'apps/api',
},
{
type: 'apps/cache-warmer',
pattern: 'apps/cache-warmer',
},
{
type: 'apps/queue-worker',
pattern: 'apps/queue-worker',
},
{
type: 'apps/transactions-processor',
pattern: 'apps/transactions-processor',
},
{
type: 'libs/common',
pattern: 'libs/common'
},
{
type: 'libs/database',
pattern: 'libs/database'
},
{
type: 'libs/entities',
pattern: 'libs/entities'
},
{
type: 'libs/services',
pattern: 'libs/services'
},
]
},
rules: {
"@typescript-eslint/no-explicit-any": ["off"],
"@typescript-eslint/no-unused-vars": ["off"],
Expand All @@ -28,6 +71,79 @@ module.exports = {
"semi": ["error"],
"comma-dangle": ["error", "always-multiline"],
"eol-last": ["error"],
'no-restricted-imports': ['error', {
patterns: ['libs/*', 'apps/*', '**/apps', '**/libs'],
}],
"boundaries/element-types": ["error", {
default: 'disallow',
rules: [
{
from: 'apps/api',
allow: ['libs/common', 'libs/entities', 'libs/services']
},
{
from: 'apps/cache-warmer',
allow: ['libs/common', 'libs/entities', 'libs/services']
},
{
from: 'apps/queue-worker',
allow: ['libs/common', 'libs/entities', 'libs/services']
},
{
from: 'apps/transactions-processor',
allow: ['libs/common', 'libs/entities', 'libs/services']
},
{
from: 'libs/database',
allow: ['libs/common', 'libs/entities']
},
{
from: 'libs/services',
allow: ['libs/common', 'libs/entities', 'libs/database']
},
{
from: 'libs/common',
allow: ['libs/entities']
}
]
}],
'boundaries/no-unknown': [2],
'boundaries/no-unknown-files': [2],
'boundaries/no-private': [0]
},
ignorePatterns: ['.eslintrc.js'],
"overrides": [
{
"files": ["libs/common/**/*.ts"],
"rules": {
"no-restricted-imports": ["error", {
"patterns": ["@libs/common*"]
}]
}
},
{
"files": ["libs/database/**/*.ts"],
"rules": {
"no-restricted-imports": ["error", {
"patterns": ["@libs/database*"]
}]
}
},
{
"files": ["libs/entities/**/*.ts"],
"rules": {
"no-restricted-imports": ["error", {
"patterns": ["@libs/entities*"]
}]
}
},
{
"files": ["libs/services/**/*.ts"],
"rules": {
"no-restricted-imports": ["error", {
"patterns": ["@libs/services*"]
}]
}
}
]
};
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ lerna-debug.log*

# Configs
**/*/config/config.yaml
**/*/config/config.custom.yaml
**/*/config/config.custom.yaml

**/*/config/schema.json
**/*/config/config.yaml
**/*/config/schema.yaml
8 changes: 3 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"eslint.validate": [
"javascript"
],
"eslint.validate": ["javascript"],
"editor.formatOnSave": true
}
}
33 changes: 0 additions & 33 deletions apps/api/config/config.devnet.yaml

This file was deleted.

33 changes: 0 additions & 33 deletions apps/api/config/config.mainnet.yaml

This file was deleted.

33 changes: 0 additions & 33 deletions apps/api/config/config.testnet.yaml

This file was deleted.

11 changes: 0 additions & 11 deletions apps/api/config/configuration.ts

This file was deleted.

13 changes: 13 additions & 0 deletions apps/api/src/config/app-config.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Global, Module } from "@nestjs/common";
import { AppConfigService } from "./app-config.service";

@Global()
@Module({
providers: [
AppConfigService,
],
exports: [
AppConfigService,
],
})
export class AppConfigModule { }
7 changes: 7 additions & 0 deletions apps/api/src/config/app-config.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { configuration } from "@libs/common/config/configuration";
import { Injectable } from "@nestjs/common";

@Injectable()
export class AppConfigService {
readonly config = configuration().apps.api;
}
8 changes: 3 additions & 5 deletions apps/api/src/endpoints/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import { ApiResponse, ApiTags } from "@nestjs/swagger";
export class AuthController {
@Get("/auth")
@UseGuards(NativeAuthGuard)
@ApiResponse({
status: 200,
description: 'Authorizes the user and returns the encoded address',
})
authorize(@NativeAuth('address') address: string
@ApiResponse({ status: 200, description: 'Authorizes the user and returns the encoded address' })
authorize(
@NativeAuth('address') address: string
): string {
return address;
}
Expand Down
13 changes: 13 additions & 0 deletions apps/api/src/endpoints/auth/auth.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Module } from '@nestjs/common';
import { AuthController } from './auth.controller';
import { DynamicModuleUtils } from '@libs/common';

@Module({
controllers: [
AuthController,
],
providers: [
DynamicModuleUtils.getNestJsApiConfigService(),
],
})
export class AuthModule { }
Loading

0 comments on commit 621818d

Please sign in to comment.