Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mradian1 authored Apr 27, 2024
0 parents commit 1a7cb56
Show file tree
Hide file tree
Showing 118 changed files with 24,759 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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,
},
rules: {
"@typescript-eslint/no-explicit-any": ["off"],
"@typescript-eslint/no-unused-vars": ["off"],
"@typescript-eslint/ban-ts-comment": ["off"],
"@typescript-eslint/no-empty-function": ["off"],
"@typescript-eslint/ban-types": ["off"],
"@typescript-eslint/no-var-requires": ["off"],
"@typescript-eslint/no-inferrable-types": ["off"],
"require-await": ["error"],
"@typescript-eslint/no-floating-promises": ["error"],
"max-len": ["off"],
"semi": ["error"],
"comma-dangle": ["error", "always-multiline"],
"eol-last": ["error"],
},
ignorePatterns: ['.eslintrc.js'],
};
24 changes: 24 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## Type

- [ ] Bug
- [ ] Feature
- [ ] Refactoring
- [ ] Performance improvement

## Problem setting

-
-
-

## Proposed Changes

-
-
-

## How to test

-
-
-
29 changes: 29 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: ESLint

on:
push:
branches: [main, development]
pull_request:
branches: [main, development]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run lint
39 changes: 39 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# compiled output
/dist
/node_modules
build.yaml

# 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

# Configs
**/*/config/config.yaml
**/*/config/config.custom.yaml
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach NestJS WS",
"port": 9229,
"restart": true,
"stopOnEntry": false,
"protocol": "inspector"
}
]
}
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.validate": [
"javascript"
],
"editor.formatOnSave": true
}
122 changes: 122 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
REST API facade template for microservices that interacts with the MultiversX blockchain.

## Quick start

1. Run `npm install` in the project directory
2. Optionally make edits to `config.yaml` or create `config.custom.yaml` for each microservice

## Dependencies

1. Redis Server is required to be installed [docs](https://redis.io/).
2. MySQL Server is required to be installed [docs](https://dev.mysql.com/doc/refman/8.0/en/installing.html).
3. MongoDB Server is required to be installed [docs](https://docs.mongodb.com/).

You can run `docker-compose up` in a separate terminal to use a local Docker container for all these dependencies.

After running the sample, you can stop the Docker container with `docker-compose down`

## Available Features

These features can be enabled/disabled in config file

### `Public API`

Endpoints that can be used by anyone (public endpoints).

### `Private API`

Endpoints that are not exposed on the internet
For example: We do not want to expose our metrics and cache interactions to anyone (/metrics /cache)

### `Cache Warmer`

This is used to keep the application cache in sync with new updates.

### `Transaction Processor`

This is used for scanning the transactions from MultiversX Blockchain.

### `Queue Worker`

This is used for concurrently processing heavy jobs.

### `Grafana dashboard`

You can find a predefined Grafana dashboard with basic metrics at [http://localhost:3010](http://localhost:3010)

Use `admin` for user and password fields. Then navigate to `Dashboards` -> `Template Service`

## Available Scripts

This is a MultiversX project built on Nest.js framework.

### `npm run start:mainnet`

Runs the app in the production mode.
Make requests to [http://localhost:3001](http://localhost:3001).

Redis Server is required to be installed.

## Running the api

```bash
# development watch mode on devnet
$ npm run start:devnet:watch

# development debug mode on devnet
$ npm run start:devnet:debug

# development mode on devnet
$ npm run start:devnet

# production mode
$ npm run start:mainnet
```

## Running the transactions-processor

```bash
# development watch mode on devnet
$ npm run start:transactions-processor:devnet:watch

# development debug mode on devnet
$ npm run start:transactions-processor:devnet:debug

# development mode on devnet
$ npm run start:transactions-processor:devnet

# production mode
$ npm run start:transactions-processor:mainnet
```

## Running the queue-worker

```bash
# development watch mode on devnet
$ npm run start:queue-worker:devnet:watch

# development debug mode on devnet
$ npm run start:queue-worker:devnet:debug

# development mode on devnet
$ npm run start:queue-worker:devnet

# production mode
$ npm run start:queue-worker:mainnet
```

Requests can be made to http://localhost:3001 for the api. The app will reload when you'll make edits (if opened in watch mode). You will also see any lint errors in the console.​

### `npm run test`

```bash
# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov
```
33 changes: 33 additions & 0 deletions apps/api/config/config.devnet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
urls:
api: 'https://devnet-api.multiversx.com'
swagger:
- 'https://devnet-microservice.multiversx.com'
- 'https://testnet-microservice.multiversx.com'
- 'https://microservice.multiversx.com'
redis: '127.0.0.1'
database:
host: 'localhost'
port: 3306
username: 'root'
password: 'root'
name: 'example'
features:
publicApi:
enabled: true
port: 3000
privateApi:
enabled: true
port: 4000
keepAliveAgent:
enabled: true
nativeAuth:
maxExpirySeconds:
acceptedOrigins:
- utils.multiversx.com
security:
admins:
rateLimiterSecret:
keepAliveTimeout:
downstream: 61000
upstream: 60000
useCachingInterceptor: true
33 changes: 33 additions & 0 deletions apps/api/config/config.mainnet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
urls:
api: 'https://api.multiversx.com'
swagger:
- 'https://microservice.multiversx.com'
- 'https://devnet-microservice.multiversx.com'
- 'https://testnet-microservice.multiversx.com'
redis: '127.0.0.1'
database:
host: 'localhost'
port: 3306
username: 'root'
password: 'root'
name: 'example'
features:
publicApi:
enabled: true
port: 3000
privateApi:
enabled: true
port: 4000
keepAliveAgent:
enabled: true
nativeAuth:
maxExpirySeconds:
acceptedOrigins:
- utils.multiversx.com
security:
admins:
rateLimiterSecret:
keepAliveTimeout:
downstream: 61000
upstream: 60000
useCachingInterceptor: true
33 changes: 33 additions & 0 deletions apps/api/config/config.testnet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
urls:
api: 'https://testnet-api.multiversx.com'
swagger:
- 'https://testnet-microservice.multiversx.com'
- 'https://devnet-microservice.multiversx.com'
- 'https://microservice.multiversx.com'
redis: '127.0.0.1'
database:
host: 'localhost'
port: 3306
username: 'root'
password: 'root'
name: 'example'
features:
publicApi:
enabled: true
port: 3000
privateApi:
enabled: true
port: 4000
keepAliveAgent:
enabled: true
nativeAuth:
maxExpirySeconds:
acceptedOrigins:
- utils.multiversx.com
security:
admins:
rateLimiterSecret:
keepAliveTimeout:
downstream: 61000
upstream: 60000
useCachingInterceptor: true
Loading

0 comments on commit 1a7cb56

Please sign in to comment.