Skip to content

Backend Practices

Julia Nguyen edited this page May 20, 2020 · 9 revisions

File and Folder Structure

Our backend is in Ruby on Rails and follows the typical file and folder structure of scaffolded apps. To learn more read the official Getting Started with Rails guide.

Code Quality

  • We use 2 space indentation.
  • We use snakecase for Ruby files and id/class names in HTML.
  • We use single quotes for Ruby files.
  • We follow Airbnb's Ruby style guide

Rubocop

Rubocop is a Ruby static code analyzer that we also integrate in Codeclimate, an automated code review we run when pull requests are made.

rubocop

Concern vs. Service vs. Helper

Ruby on Rails encourages various patterns to yield modularity in the codebase. It can be tricky to figure out where you want your code to go.

Useful Terms

  • Business logic: Operations that get carried out when Models calls are made
  • Modularity: Separating the functionality of a program into independent, interchangeable modules, such that each contains everything necessary to execute only one aspect of the desired functionality
  • Mixins: A class that contains methods for use by other classes without having to be the parent class of those other classes

Concern

  • Dependency-free
  • No business logic
  • Mixins

Service

  • Can have dependencies
  • Business logic

Helper

  • Presentation methods that are called from your views or controllers

Schema Documentation

If you add or modify a model, please run annotate to update the schema comments and rake db:drop db:create db:migrate; rake db:schema:load to update db/schema.rb.

Automated Testing

Please see our Automated Testing document, specifically the backend document.

Maintaining Gemfile

Running bundle update will update all gems and modify Gemfile.lock.

You can also run bundle exec bundle-audit check --ignore CVE-2015-9284 --update to check for security vulnerabilities in gems. We're ignoring CVE-2015-9284 because there is still no update on a CSRF vulnerability for OmniAuth. This PR has more info.

Clone this wiki locally