What’s the recommended way to handle namespacing of models and controllers? Let’s say I have
User
, Account
, and Group
, where:
- A
user
has manyaccounts
throughmemberships
- A
user
has manygroups
throughmemberships
- A
group
belongs to anaccount
.
I can…
Option 1
Namespace Group.Membership
model and controller using subfolders.
In app/web/controllers
defmodule App.MembershipController
In app/web/controllers/group/
defmodule App.Group.MembershipController
In app/web/models/
defmodule App.Membership
In app/web/models/group/
defmodule App.Group.Membership
Option 2
Or I can keep the structure flat and prefix the group membership model and controller with group
In app/web/controllers
defmodule App.MembershipController
defmodule App.GroupMembershipController
In app/web/models/
defmodule App.Membership
defmodule App.GroupMembership
Option 3
Same as option 1, but namespace both models.
Option 4
Same as option 2, flat structure, but prefix both membership models and controllers with organisation
and group
.
Option 5
Don’t namespace anything. Just find different names that make sense.
Option 6
None of the above.
It’s great that whatever choice I take doesn’t make things magically blow up (like in Rails, for example, where folder naming and class naming, as well as load paths make a difference).
But I would like to know the best way to usually go about this…