Code Monkey home page Code Monkey logo

cmms-api's Introduction

Tractian Backend Challenge API

The purpose of this API is to fulfill Tractian's challenge demands. More information about the company can be found on this link

Testing

Production:

This project has been deployed for testing purposes on https://cmms-api.herokuapp.com/api/ and can be tested by anyone.

Postman:

If you use postman for testing you can download the postman json file in the root directory to test it.

Integration Tests:

Also, every endpoint has an integration test written that can be found on src/routes/_tests_ . If you want, you can clone the project, run 'npm install' and then 'npm run test' to see it in action.

API Documentation

  • The endpoints are documented using SwaggerUI available on this link.
  • Basically there are CRUD endpoints for each entity (User, Company, Unit and Asset).
  • There are two endpoints to list objects with pagination: /unit and /asset
  • There is one data aggregated endpoint /company/{id}/info that returns two informations:
    • Asset Status Summary: which contains an object with the asset count for each status (Running, Stopped and Alerting)
    • Critical Assets: Assets with a health level lower than a given threshold or the default (0.75).

How the project is structured

This project has been organized trying to keep up with Clean Code best practices. The src folder holds all project files. Configurations and readme are on root. The 6 folders inside src and their responsability are listed below:

  • routes: api endpoints
  • controllers: presentation phase
  • services: business logic
  • db: data access layer (db connection and data access objects).
  • models: entity models (mongoose schema)
  • middlewares: contains only the error middleware which is responsible for handling errors globally for the api.

Also there is the index file inside src which initiate the server

Inside each folder there is a file for each entity of the model.

Packages

Dependencies

  • cors: enabling cors config to express
  • dotenv: configuring environment variables
  • express: express server
  • express-async-errors: library to enable async error handling globally with express
  • mongoose: Database (mongoDB) ORM and connection

Development dependencies

  • chai: assertion testing library
  • chai-http: chai plugin to enable http requests testing
  • cross-env: environment selection
  • mocha: testing library
  • nodemon: enables hot-reload when saving project locally
  • ts-node: enables typescript testing files
  • typescript: project language

Disclaimers and Future Improvements

Better typying and controllers adjustments

The routes and controllers files could be much better typed. There should be a better treatment of the user input in order to avoid some type errors such as a number been passed as a string. I have experimented some type aliases in src/routes/unit.ts that could be useful for a controller to infer types from the routes in the future.

Authentication

  • Authentication was not a demand, but implementing should be mandatory in a company production environment. Given the business needs, I think the user should be identified by a authorization token in order to use the API.
  • Since the user is linked to a company, he would be able to read and write Units and Assets only for his company.
  • Company and User creation should always be open to anyone. The sign up flow could be:
    • Create Company and User with Company Admin (no authentication needed)
    • Read and Write Units and Assets (company user authentication needed)

Thanks

I want to thank Tractian's team for creating this challenge and giving this opportunity. I learned a lot! =)

cmms-api's People

Contributors

eng-gabs avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.