Skip to content

Backend Practices

Julia Nguyen edited this page Jul 29, 2018 · 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.

Clone this wiki locally