This is the backend of the Crypto Journal App, built with NestJs, Graphql and MongoDB.
This project implements all the server-side logic to handle the user data. Firebase is used to handle user auth, while MongoDB stores the user data. The cryptocurrencies data is retrieved using the CoinApi. As the project is hosted on Heroku, instead of having a cron-job to update regularly the crypto-currencies data, the project will do it on start-up if it wasn't already updated. A different approach, inspired by the Golang programming language, is used to handle errors. Instead of throwing errors, functions and methods return a tuple of two elements where the first is the error while the latter is the data itself.
The project is built with the following tools:
The API layer is exposed using Graphql. Every resource is exposed as a Graphql Union of two types to improve error handling on the client-side. These are:
- ApiError
- The requested resource (User, Operation ...)
If an error were to happen during a request, instead of sending the default graphql error response, the API would respond with a nicely formatted error.
Is the framework used to develop all the server side logic. Its main advantages are that it is built upon the express framework, it's easy to use, can be easily integrated with third party packages and enforces a good project structure.
The Firebase Admin SDK is used to verify that the tokens received from the client app are valid so that a user can be successfully logged in or registered.
MongoDB is used to store the data. The aggregation framework is used to retrieve the overview and holding data belonging to a user.
Docker is used to standardize the project environment and to make it easier to deploy it to Heroku.
The project can be run either with docker or with the npm run start
command. In both cases, the following variables must be provided:
PORT
NODE_ENV -> optional
DB_URI
ACCESS_TOKEN_SECRET
ACCESS_TOKEN_EXP
REFRESH_TOKEN_SECRET
REFRESH_TOKEN_EXP
GOOGLE_SERVICE_ACCOUNT -> Full google service account json object for firebase
COIN_API_BASE_URL -> Api url without version key
COIN_API_KEY