Help Understanding Elixir Namespacing

Phoenix/Elixir namespacing is confusing. After creating a Phoenix project hello, user_socket.ex constains defmodule HelloWeb.UserSocket. But it’s under the channels folder so should it be defmodule HelloWebChanels.UserSocket instead?

In fact, you can name it as you want. The folder architecture doesn’t define your module’s name.

Think about domain. Here, UserSocket are in the web domain, so it make sens to prefix then with HelloWeb. In that way, when someone read your modules he can know easily what domain is concerned.

1 Like

Are you saying there is no namespacing in Elixir or Phoenix?

Not really in term of runtime/compile system. It’s more a norm that people follow. Here, an interesting conversation on it Namespaces in Elixir (and how to change namespaces)?