There’s no one size fits all. If this fits you, and your style of coding go and encourage that. But make others aware that it’s not the only true way. Damn, “this is the Rails way” made so much damage to Ruby projects that it’s painful to think of it.
Luckily, both Elixir and Erlang are more flexible. You cn use contexts, sure. I just call them namespaces / modules, and do not follow the convention at all. I’d normally namespace my services, sure, but I would not namespace either controllers (and templates, views) unless they’re nested in router. I would not namespace schemas either. Controllers and schemas map to routes and database tables, and does not make sense in my head to namespace them in contexts having some extra meaning.
I do like another abstraction that comes with OTP, which are the applications. And I tend to use them more heavily than the others I think. What I would normally do when starting a project would be to start with umbrella project and two apps in it. apps/ui
and apps/backend
. In ui
I make another heresy of getting rid of the web
subfolder and just putting everything straight to lib
. I even skip the lib/ui
. Everything in this project is scoped within Ui.*
namespace, I don’t need a Ui.Web
, nor extra directory. It’s hard to reach to the files with such long paths even with Ctrl+P. That’s okay, it’s my project and I decide.
Then I’d put stuff to app/backend
that is generally a place for the business logic. If I feel like separating the some things more, I’d create apps/whatever
in addition to backend. Usually I’d extract the schemas and abstract the database read/writes and queries. I’d make apps/storage
and expose some interface to backend
, which in turns exposes some interface to ui
. It’s an uni-directional flow where ui
has no idea of internal data structures and implementation of backend
, which in turns has no idea about internal data structures (including schemas) of storage
. Usually there’ll be a few more apps in apps/
folder. Logs handling, watchdogs, handling integration to external services and other infrastructure bits would find it’s own apps.
And then there’s the kicker in form of testing the layers in separation. Right now, I can test my Ui
, stubbing out the backend
's functions as needed with mox, and test my business logic, stubbing out the database read/writes.
So the above is the reason I like applications. I don’t mind if there’ll be dozen of them in apps/
.
That’s fine. Sorry for lengthish reply and off topic, this been on my mind for some time and had to share