The project can be found live at heroku.
- Node LTS v10.5 & npm v6.0
- Node
- Express + MongoDB
- Mongoose
- Docker Support
- Request Validation with Joi
- Linting with eslint
- Logging with winston logger.
- Uses helmet to set some HTTP headers for security.
- Pre-commit hook to check lint errors using Husky.
- API documentation using Swagger-jsdoc and Swagger UI.
Make sure you have node and npm installed.
- Clone the repository or Download zip.
- Run
npm installin the directory. - Set environment variables
cp .env.example .env - Run
npm run dev
Dockerfile is present to build image and run container just remember to pass the env vars for container.
- I have feeded the mlab DB with three securities to begin with.
- Portfolio would be empty.
- Price of any security can be changed by the endpoint easily.
- Buy and sell securities by adding trades.
- Check holdings and portfolio by the respective APIs.
- Calculate returns by changing current price through API.
- Run
npm run lint
API is documented using swagger and open API specification.
You can check the documentation online at specified URLs:
You can download/import the Postman Collection from this URL.
- Folder Structure - Folder Structure follows MVC design pattern.
- Routes, Controllers and models are seperated which makes testing specific unit easy.
- Swagger is used to document the API which makes the API easy to understand for other developers.
- Used gzip compression: Gzip compressing can greatly decrease the size of the response body and hence increase the speed of a web app.
- Logging is being handled by winston which can be further extended for log files.
- Try/Catch and Promises are being used and handled properly so that app doesn't crashes.
envfile is used to assign values to environment variables likeMONGO_URI.- App uses async/await and latest ES6 features.
- Seperate Express
appandserverwhich makes testing the express app easy(example by usingsupertest). - App follows
Fail-fast approachand validates arguments using Joi.
- Uses ESLint and husky pre-commit hook to maintain code quality.
- Function and variable names are tried to be kept as self-explanatory.
- Used
constoverlet. Ditched thevar. - Requires come first, and not inside functions.
- Use Strict equals(===), arrow functions(=>) & avoided callback hell.
- App can be run in a cluster by a process manager like pm2.
- Testing can be added using mocha and chai.
- Fixtures can be used for testing purposes.
- App structure can be changed to
component design patternso that scaling the application is more easy. - Proper Error Handler can be made which makes error handling of the API more robust and handles the error centrally instead of the middleware.