Skip to content

A NodeJs / TypeScript application boilerplate with Federated 2 GraphQL. It uses MongoDB as a persistent database layer with Mongoose as an ODM.

License

Notifications You must be signed in to change notification settings

the-vishal-kumar/nodejs-typescript-federated-graphql-boilerplate

Repository files navigation

nodejs-typescript-federated-graphql-boilerplate

A NodeJs / TypeScript application boilerplate with Federated 2 GraphQL.

Problem Statement

  • Create an application that pulls current charging station data from Open Charge Map API and then persists the data in MongoDB.

    • The following fields are to be imported from Open Charge Map API:
      • operatorInfo
      • statusType
      • addressInfo
      • connections
  • The service pulls the data and updates our own database. It shall update the database only in case of changes in the pulled data.

    Read more...

Solution

  • There is one entity - Socket. It represents charging stations in our database.

  • There are two graphql queries - Socket and Sockets.

    Read more...

Initial setup

  1. Clone from GitHub

    git clone https://github.com/the-vishal-kumar/nodejs-typescript-federated-graphql-boilerplate.git
  2. Setup Docker and Docker-Compose

    • Install docker and docker-compose on your machine
    • Copy docker-compose.sample.yml as docker-compose.yml
  3. Install dependencies using npm

    cd nodejs-typescript-federated-graphql-boilerplate
    npm i
  4. Set environment variables

    • Copy .env.sample to the root directory as .env.

      • Put the value of OPEN_CHARGE_MAP_API_KEY.

        • Leaving it empty won't prevent the application from starting/running, but the polling won't work.
        • The application will be able to serve queries from already polled data (which will be empty if the application is started without a key).
      • (Optional) Put the value of NEW_RELIC_LICENSE_KEY. Generate a key from here.

Development

  1. Execute the command from the root directory to start the application

    npm start

Testing

  1. Some end-to-end and unit tests are included in src/test directory for the socket subgraph

  2. Tests are run using Jest

  3. Execute the command from the root directory to run the tests

    npm test

API Documentation

  1. Import Postman collection and environment variable
    • Import Collection from here.
    • Import Environment Variables from here.

Technology

Code Quality

Code Review

  • A feature branch is created from the dev branch, and after completion of the code, a PR is generated for the dev branch
  • If changes are requested by a reviewer on Github, then the person who has made the PR makes appropriate changes. The reviewer reviews again and marks the comments as resolved
  • If there are no new changes required, then PR is merged with the dev branch

Managing Credentials

  • Credentials live in the .env file

Git Workflow

  • A branch is created for each ticket from the dev branch

  • Example of Branch Name:

    • feature/{ticket_number}
    • bugfix/{ticket_number}
    • hotfix/{ticket_number}
    • dev
    • staging
    • master
  • Read the next section for more information

Error Logging

Application Performance Monitoring

Log Monitoring

Folder Structure

    ๐Ÿ“ฆnodejs-typescript-federated-graphql-boilerplate
    โ”ฃ ๐Ÿ“‚.husky
    โ”ƒ โ”ฃ ๐Ÿ“‚_
    โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œ.gitignore
    โ”ƒ โ”ƒ โ”— ๐Ÿ“œhusky.sh
    โ”ƒ โ”ฃ ๐Ÿ“œcommit-msg
    โ”ƒ โ”ฃ ๐Ÿ“œpre-commit
    โ”ƒ โ”— ๐Ÿ“œpre-push
    โ”ฃ ๐Ÿ“‚src
    โ”ƒ โ”ฃ ๐Ÿ“‚database-test
    โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œDockerfile
    โ”ƒ โ”ƒ โ”— ๐Ÿ“œsockets.seed.data
    โ”ƒ โ”ฃ ๐Ÿ“‚gateway
    โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“‚src
    โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“‚test
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”— ๐Ÿ“‚unit
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”— ๐Ÿ“‚util
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”— ๐Ÿ“œlogger.unit.test.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“‚util
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œindex.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”— ๐Ÿ“œlogger.ts
    โ”ƒ โ”ƒ โ”ƒ โ”— ๐Ÿ“œindex.ts
    โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œ.nvmrc
    โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œDockerfile
    โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œnewrelic.js
    โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œpackage.json
    โ”ƒ โ”ƒ โ”— ๐Ÿ“œtsconfig.json
    โ”ƒ โ”— ๐Ÿ“‚subgraphs
    โ”ƒ โ”ƒ โ”— ๐Ÿ“‚socket
    โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“‚src
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“‚app
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“‚mongo-server
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”— ๐Ÿ“œindex.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“‚node-server
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œindex.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”— ๐Ÿ“œschema.graphql
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”— ๐Ÿ“œindex.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“‚config
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œcountries.json
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œcow.txt
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œindex.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”— ๐Ÿ“œmongo-config.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“‚cron
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œindex.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”— ๐Ÿ“œpullSocket.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“‚middleware
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“‚model
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œindex.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”— ๐Ÿ“œsocket.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“‚resolver
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“‚query
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œindex.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œsocket.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”— ๐Ÿ“œsockets.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”— ๐Ÿ“œindex.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“‚test
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“‚e2e
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”— ๐Ÿ“‚resolver
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”— ๐Ÿ“‚query
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œsocket.e2e.test.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”— ๐Ÿ“œsockets.e2e.test.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”— ๐Ÿ“‚unit
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”— ๐Ÿ“‚util
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œarray.unit.test.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œenum.unit.test.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œgenerateCountriesJson.unit.test.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œgenerateSubBoundingBoxesOfCountry.unit.test.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”— ๐Ÿ“œlogger.unit.test.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“‚type
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“‚config
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œcountry.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”— ๐Ÿ“œindex.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“‚model
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œindex.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”— ๐Ÿ“œsocket.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“‚resolver
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“‚query
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œindex.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”— ๐Ÿ“œsockets.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”— ๐Ÿ“œindex.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”— ๐Ÿ“œindex.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“‚util
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œarray.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œenum.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œgenerateCountriesJson.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œgenerateSubBoundingBoxesOfCountry.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œindex.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”— ๐Ÿ“œlogger.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ƒ โ”— ๐Ÿ“œindex.ts
    โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œ.nvmrc
    โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œDockerfile
    โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œnewrelic.js
    โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œpackage.json
    โ”ƒ โ”ƒ โ”ƒ โ”— ๐Ÿ“œtsconfig.json
    โ”ฃ ๐Ÿ“œ.commitlintrc.json
    โ”ฃ ๐Ÿ“œ.dockerignore
    โ”ฃ ๐Ÿ“œ.env
    โ”ฃ ๐Ÿ“œ.env.sample
    โ”ฃ ๐Ÿ“œ.env.test
    โ”ฃ ๐Ÿ“œ.eslintrc.json
    โ”ฃ ๐Ÿ“œ.gitignore
    โ”ฃ ๐Ÿ“œ.nvmrc
    โ”ฃ ๐Ÿ“œ.prettierrc.json
    โ”ฃ ๐Ÿ“œLICENSE
    โ”ฃ ๐Ÿ“œPROBLEM.md
    โ”ฃ ๐Ÿ“œREADME.md
    โ”ฃ ๐Ÿ“œSOLUTION.md
    โ”ฃ ๐Ÿ“œdocker-compose.sample.yml
    โ”ฃ ๐Ÿ“œdocker-compose.test.yml
    โ”ฃ ๐Ÿ“œdocker-compose.yml
    โ”ฃ ๐Ÿ“œjest.config.js
    โ”ฃ ๐Ÿ“œpackage-lock.json
    โ”ฃ ๐Ÿ“œpackage.json
    โ”— ๐Ÿ“œtsconfig.json

External Services/API Reference

  • Open Charge Map API

    • The Open Charge Map API provides access to the world's largest registry of charging locations as Open Data.
  • Countries of the World

    • The solution involves conceptualizing each country as a small rectangle, encompassing all of its borders, and representing each corner of the rectangle with coordinates.

    • The data for edge coordinates was obtained from here where I reached through this stack exchange answer.

License

  • AGPL-3.0-or-later

Meet The Maker

Vishal Kumar - Software Engineer ๐Ÿ‘จโ€๐Ÿ’ป and an Aspiring Entrepreneur๐Ÿ‘จโ€๐Ÿ’ผ