Skip to content

DappHeroCore/dapphero-backend

Repository files navigation

w3tec

DappHero.io Backend

A Node.js backend server: RESTful API & GraphQL services written in TypeScript.
Made with ❤️ by DappHero.io



❯ Why

This project main goal is a to provide a complete server application for dapphero's administration tool and javascript bundle.

Features

  • Simplified Database Query with the ORM TypeORM.
  • Clear Structure with different layers such as controllers, services, repositories, models and middlewares.
  • Easy Exception Handling thanks to routing-controllers.
  • Smart Validation thanks to class-validator.
  • API Documentation thanks to swagger. (WIP)
  • Integrated Testing Tool thanks to Jest. (WIP)
  • E2E API Testing thanks to supertest. (WIP)


❯ Table of Contents



Basic Overview

DappHero is a web 2.0 app that allows no-code users to drag & drop blockchain connected components (web 3.0 components) into their webs. 🚀



❯ Getting Started

A quick introduction of the minimal setup you need to get the server up & running on your local machine.

Step 1: Set up the Development Environment

You need to set up your development environment before you can do anything.

Install Node.js and NPM

Install all project dependencies:

npm install

Configure your environment's variables on a new .env file:

TORM_CONNECTION=postgres
TORM_HOST=localhost
TORM_PORT=5432
TORM_USERNAME=postgres
TORM_PASSWORD=dapphero
TORM_DATABASE=postgres
TORM_SYNCHRONIZE=true

Step 2: Set up Postgres Database

If it's your first time with docker, please download it and install it from https://docs.docker.com/install/

Once installed, run the database container locally:

npm run-script postgres:up

Finally, run all the available migrations:

npm run-script run-migrations

Step 3: Run the server on Development Mode

This command will start the server using nodemon dependency. This dependency will reload the server on any new code change:

npm run-script start:dev

Server is now available on port 5001! 😄



❯ Project Structure

Inside the main root folder src/ you will find the following structure

Route Description
server.ts Main entrypoint of the server
/controllers API Controllers declarations, responsible for handling with inconming requests
/db TypeORM entities declarations, migrations and models repositories
/middewares All custom middlewares goes in here
/services Service logics that interacts with controllers and databases repositories
/tests All custom tests goes in here


❯ API Routes

The route prefix is / by default

Route Description
/api API routes
/graphql Route to the graphql editor
/swagger Swagger UI with our API documentation


❯ Database Management

We created a few custom scripts to make TypeORM's Database Management easier:

Create a new Migration

This command will generate a new migration file with all the SQL commands needed to reflect your current schema on the database

npm run-script generate-migrations -- -n <MIGRATION-NAME>

Running Migrations

After creating a new migration, you will have to run it in order to update your database schema:

npm run-script run-migrations


❯ GraphQL

(WIP)

For the GraphQL part we will be using the library TypeGraphQL.

The context(shown below) of the GraphQL is builded in the graphqlLoader.ts file. Inside of this loader we create a scoped container for each incoming request.

export interface Context {
  requestId: number;
  request: express.Request;
  response: express.Response;
  container: ContainerInstance;
}

❯ Further Documentation

(WIP)



❯ License

(WIP)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published