Skip to content

Create new models / classes within a module / namespace

Description

GitLab has become an incredibly broad product with so many features and components. There are multiple on-going initiatives that try to help with reducing cognitive load that engineers experience when working on gitlab-org/gitlab.

The essential complexity of having so many concepts represented in our backend code in gitlab-rails is significant.

Problem

We keep creating top-level classes like class Requirement < ApplicationRecord ee/app/models/requirement.rb. Given the amount of concepts and business rules that our backend code needs to model, it might be difficult for some people to understand what the Requirement class stands for. Looking at the class implementation does not make it easier to understand that as well.

Proposal

  • New classes should be created inside a module if there is no good reason to make them top-level classes
  • Add Rubocop rule that forbids adding new top-level classes without a comment describing a class purpose
  • Document it better what the benefits of using modules and nested structure are and what the impact on engineers productivity might be

What do you think @gitlab-org/maintainers/rails-backend?

Edited by Chad Woolley