mishaelajay / company-manager

Company manager using awesome_nested_set

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The ui is very basic and just enough to interact with the application. Please go through the ui label diagram i have added below.

I have deployed this repository on heroku - Company Manager

How to read the ui:

ui_labels

After going through the task description i explored various ways of doing this in the most efficient way.

So when storing hierarchial data we have to make a bargain between fast read times and fast write times. I went with the assumption that companies don't get created that very often and decided to use nested set which gives us fast read times but the write times is slower when compared to a no-sql implementation or an adjaceny list for that matter.

Below is a representation of how companies look visually when stored in a database that uses nested set.

comapny_nested_set company_tree_representation

Dependencies:

  • I have made use of awesome_nested_set gem.
  • I have implemented the solution in Rails 6.1.4 and thereby using many of the benefits that come along with Rails.

Testing:

  • I have added the tools that i usually use for testing. If you have a look at my Gemfile you will see the description of what each one does.
  • I have added minimal test cases for the models - Employee.rb and Company.rb.

Linting:

  • I have used rubocop along with a few extensions for linting.
  • I have also setup pre-commit and pre-push hooks in the scripts folder.
  • rubocop runs before commit and brakeman along with test cases run before a push.

Setting it up on your local:

  • Clone the repository.
  • Install ruby 3.0.2. Or set RVM to use 3.0.2
  • Install postgres and create db with name -> company_manager_development
  • bundle install
  • rails db:migrate
  • Start the server using rails s

To run the test cases:

rails test:all

What i have missed:

  • Adding a bottleneck identifier and a error logging service.
  • Validations to prevent invalid data getting stored in the models.
  • Comments explaining what each function does.
  • Too much caching to improve read times which involves overhead.
    • I have a counter cache for employees_count for each company
    • I have a counter cache for sub_company_count for each company
    • I am also maintaining the total_employees_count on destroy or on create

I have covered all the requirements as shown below.

  • Add a company (each company has a unique ID)
  • Set relations between companies (via rails console-> company.move_to_child_of company2)
  • Set required amount of employees for the company
  • Remove a company (via rails console)
  • Add an employee to the company (each employee has a unique ID, other attributes are irrelevant)
  • Remove an employee from the company (via rails console)
  • Get a list of all companies
  • Get a list of all companies where the amount of employees is less than required

Ruby and rails version: Ruby 3.0.2 Rails 6.1.4

About

Company manager using awesome_nested_set


Languages

Language:Ruby 81.7%Language:HTML 13.0%Language:JavaScript 2.6%Language:Shell 1.6%Language:CSS 1.2%