DEV Community


Discussion on: How to best organize a Rails app folder?

andreasklinger profile image
Andreas Klinger ✌️️ • Edited

re folders:
i used to use app/services - eg ProductHunt is still structured that way

at some point the separation between a few classes in app/models and app/services just became weird - especially if they work super close together - eg a concern calling a service object

so in newer projects i just use app/models - keep in mind that models stands for classes that model your domain logic - not just persisted state

re namespaces:
i do the same setup as benito w/ the namespaces

usually the logic starts in the method - and when it becomes more than a 3 liner i extract it to some class so it easier to extend


module Campaigns
  extend self
  class ParticipationRequired < StandardError; end
  class InviteRequired < StandardError; end

  # ....

  # simple method
  def allowed_to_join_late?(invite:)
    invite.present? && invite.allowed_to_join_late?

  # more complex stuff
  def flag!(**args)

re api/separation:
like benito i try to keep separation - as in: namespaces dont touch into the deeper parts of other namespaces. controllers neither

the exception are usually rake tasks and sometimes admin backend/stuff
Forem Open with the Forem app