A Node.js backend server: RESTful API & GraphQL services written in TypeScript.
Made with ❤️ by DappHero.io
This project main goal is a to provide a complete server application for dapphero's administration tool and javascript bundle.
- 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)
- Getting Started
- Project Structure
- API Routes
- Database Management
- GraphQL
- Further Documentations
- License
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. 🚀
A quick introduction of the minimal setup you need to get the server up & running on your local machine.
You need to set up your development environment before you can do anything.
Install Node.js and NPM
- on OSX use homebrew
brew install node - on Windows use chocolatey
choco install nodejs
Install all project dependencies:
npm installConfigure 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
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:upFinally, run all the available migrations:
npm run-script run-migrationsThis command will start the server using nodemon dependency. This dependency will reload the server on any new code change:
npm run-script start:devServer is now available on port 5001! 😄
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 |
The route prefix is / by default
| Route | Description |
|---|---|
| /api | API routes |
| /graphql | Route to the graphql editor |
| /swagger | Swagger UI with our API documentation |
We created a few custom scripts to make TypeORM's Database Management easier:
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>After creating a new migration, you will have to run it in order to update your database schema:
npm run-script run-migrations(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;
}(WIP)
(WIP)