Databox Backend Engineer Challenge MS is an API, serving as a bridge between Databox API and 3rd party service providers (such as Facebook, Google Analytics, GitHub etc.).
To be able to run the service, you must ensure you have the following tools installed:
- Node.js: version 20.6.1 or higher. You can download and install it from here.
We encourage you to use nvm to install, update and maintain multiple Node.js versions at the same time on your machine.
In case you use macOS with Homebrew package manager, you can install it via the following commands:
# Node.js
$ brew install node
- TypeScript - Typed JavaScript programming language used for developing the service.
- NestJS - Framework for building efficient, scalable Node.js server-side applications, used to define the architecture and structure of the service.
- class-validator - Decorator-based property validation for classes, used to perform request validation.
- swagger-ui-express - Serve auto-generated Swagger UI for express-based applications.
- Jest - Testing framework.
For installing all required dependencies, make sure you have npm
installed on your machine.
Then, you just need to execute the following command:
$ npm install
Once the installation is finished, you should see something like this:
added 941 packages from 670 contributors and audited 957 packages in <seconds>
122 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
Before running the service, you must define the ENV variables, required to make the integrations work.
Here you can find the complete list of ENV variables that the Databox Challenge MS uses:
Variable | Description |
---|---|
DEVICE_CONFIGURATION_MODE | Determines on which environment the service is running. Can be one of: development , production |
MS_PORT | Allows modifying the port where the MS will run on (default is 3000 ) |
SELF_URL | Used for scheduler/cronjob purposes to be able to externally access the API (in case we'd use an external service for task scheduling) |
TYPEORM_PORT | Port, where the MySQL instance is running |
TYPEORM_HOST | Host, where the MySQL instance is running |
TYPEORM_DATABASE | Database name to which TypeORM has to connect in order to perform queries |
TYPEORM_USERNAME | Username with which TypeORM will be able to perform queries in database from the previous row |
PRINT_CURL_REQUESTS | Enables printing curl requests |
DATABOX_BASE_URL | Url to which a connection will be made when calling Databox Push API |
DATABOX_USER_AGENT | User-agent header that will be sent along the requests when calling Databox Push API |
DATABOX_PUSH_INTERVAL | Timeout between respective calls to Databox Push API to avoid throttling or overloading the API |
DATABOX_ITEMS_PER_BATCH | Number of external service providers that will be called per batch and push the metrics to Databox |
GITHUB_BASE_URL | Url to which a connection will be made when calling GitHub API |
GITHUB_API_VERSION | Target API version to fetch from when calling GitHub API |
GITHUB_CLIENT_ID | Client id of the GitHub application, created for this service |
Secret | Description |
---|---|
SECRET_TYPEORM_PASSWORD | Password with which TypeORM will be able to perform queries |
SECRET_DATABOX_PUSH_TOKEN | Push token expected to be able to connect to the Databox Push API |
SECRET_GITHUB_CLIENT_SECRET | Client secret, sent along with requests in order to be able to connect to the GitHub API |
Add your application configuration to your .env
file in the root of your project by duplicating .env-example
file:
DEVICE_CONFIGURATION_MODE=development
SECRET_X_API_KEY=SERVICEAPIKEY
...
Make sure you have Docker installed.
To create an instance of your database, run one of the following commands:
# For Apple Silicon chips
$ docker-compose -f docker-compose.arm.yml up
# For every other chip
$ docker-compose up
After executing these commands you should have the db container up and running.
After successfully starting the database in docker, run migrations and seeder to populate some test data:
$ npm run typeorm:migration:run
$ npm run seed
After executing these commands you should have the entities created and ready to be used with some autogenerated data.
You can run the service in development mode with:
# development mode
$ npm run start
That's it! This way, the service should be running on port 3000, with the configuration from your local .env
file, accessible through http://localhost:3000.
Run the service in development mode, watching file changes and reloading the running service with:
# watch mode
$ npm run start:dev
The tests are located in the test directory and named as the classes they test. Testing files have a .spec
or .test
suffix.
To only execute unit tests, use the following script:
# unit tests
$ npm run test:unit
The service is using the Swagger module for NestJS to define and expose the databox-challenge MS API specification.
When the service is running, the API definition is exposed via Swagger UI in the /api
endpoint.
In case you want to get the corresponding JSON file of the specification, you can get it from the /api-json
endpoint.
When running the service on your machine, you can get to them via:
- http://localhost:3000/api - Swagger UI
- http://localhost:3000/api-json - JSON file
The structure used for the project follows the domain-based design, so each module/feature is isolated in its own folder, like databox
, auth
, health
, making it easy to find and locate where the different functionalities exposed from the service might be.
The naming convention used for the files follows the pattern <name>.<type>.ts
, where:
- name: The name of the component, class, or model you are defining.
- type: The type of content you have inside that file, e.g.,
module
,controller
,service
,guard
,interceptor
,entity
, etc.
# Examples:
databox.module.ts
databox.controller.ts
databox.service.ts
databox-session.entity.ts
databox.dto.ts
If the name is complex, we use hyphens to separate the different words, e.g. api-key-identification.entity.ts (Kebab Case)
- Databox - Webpage - Official company website.
- Databox - Documentation - General development documentation (Push API etc.).
- GitHub - Webpage - Official company website.
- GitHub - Documentation - General development documentation (GitHub Apps, OAuth apps, Marketplace etc.).
- CoinCap - Webpage - Official company website.
- CoinCap - Documentation - General development documentation (RESTful API & WebSocket docs).