As far as I understand (and I may be wrong since I am new to Elixir), one can choose to create a single-app Mix project with multiple .ex files, each with multiple modules in them. And they can be used within each other through alias, import etc.
If that is the case, what is the purpose of the "main module" during creation, either implicitly (Uppercased project name) or explicitly (as in, mix new ... --module <modulename>
)?
PS: I understand that escripts require a main module to be specified in mix.exs
, but that is not what I am referring to in my question (or am I?).
An Elixir system may be composed of many applications, which can be your own apps or third-party apps, including libs. Think of an application as a component, a "box" of related code, in fact, many libs are applications.
And the main module is where you put all the public functions that will be used by other applications, in other words, that's the public API for your application. Take a look at some libs like Jason and you'll see this pattern, example: https://github.com/michalmuskala/jason/blob/master/lib/jason.ex
But if you're building an application based on Phoenix without distributed applications, you probably won't have any code in the main module, although I recommend you to read https://hexdocs.pm/phoenix/contexts.html which is related to this topic and will give you a deeper understanding.