Auto complete and Data Manipulation service to resolve the Challenge for hiring process on Dito
This repository contains an API service, a Database service and a Frontend service.
Those services, integrated, provide ways to POST events, GET events and GET timeline.
NodeJS, was chosen as language to develop the API.
Some libraries was used with NodeJS:
- Express - used to manage and to configure the routes of API
- BodyParser - used because of the necessity to parsing the requests
- Request Pomisse Native - used to enable the use of promisses natively, with async / await
- Dotenv - used to store enviroment variables
- Cors - used to avoid errors when accessing the API in a localhost browser
ReactJS was chosen as language to build the frontend interface.
One library was used with ReactJS:
- AutoSuggest - used to create an auto complete component.
Used ESLint with the basic NodeJS configuration. The linter is configurated only in development enviroment.
To store common variables that will be use in some parts of code, was used Dotenv.
There is one .env example file on repository. You need to create a .env file and put your own values here. Remember, your .env file will not be commited to the repository.
To get validation of data, was used AJV.
MongoDB was used as storage. The reasons for this choice are, mainly, the speed and the simplicity of the data.
For connect and execute operations in database, was used Mongoose.
MongoDB was configured with auth to provide more security.
In development mode, was used Nodemon.
Docker was chosen to create to services for this application:
- NodeJS Server: a simple server, with the minimum configuration, running node and exposing the port 3005
- MongoDB Server: a server with minimum configuration, running MondoDB and exposing the port 3006
- Frontend Server: a simple server, using NodeJS, NPM and Webpackage and exposing the port 3007
In the API there are 3 endpoints:
- GET a list of events, filtering by name
- POST a new event
- GET a timeline, with a list of events
For more details about the API, use the file (docs/dito_autocomplete.postman_collection.json) with Postman.
To running this project, the best way is up the docker, because it will up NodeJS, MongoDB and Frontend services. And all are integrated. For this, use
docker-compose up -d
If you want to run only the NodeJS service, you can run (inside /api folder)
npm run start:dev
If you want to run only the Frontend service, you can run (inside /front folder)
npm start
If you run only NodeJS service, you need start manually the container of database. And your connection with mongo, configured on env file, must be done using localhost:exposed_port.
For the tests was used Mocha as library to execute and to describe the tests. For the assertion and validation was used ShouldJS. For faker returns and throws of server, was used Sinon. And for HTTP tests was used Supertest.
To run the tests, run (inside /api folder)
npm test
My suggestion is to run the tests outside a container. For this, you need to update the env file changing the MONGODB_HOST and MONGODB_PORT to your localhost configuration, like localhost and 3006
The VSCode was chosen as the IDE to develop this API. Was created config about that IDE and the file is [docs/vscode.config.json] with configurations about Debug using mocha, that can be used for anybody.