What is HelloWeb for in this Hello project?

In the book Programming Phoenix the Hello project produces

scope “/”, HelloWeb
defmodule HelloWeb.HelloController
defmodule HelloWeb.HelloView

What are those HelloWeb for?

The HelloWeb it’s the structure(folders, files) for the things of the Web.
It’s a way for organize the files.
You can see the tree how they are organized( Hello for contexts, schemas, databases and HelloWeb for the files relationated with things of the web).

lib
├── hello
|   ├── application.ex
|   └── repo.ex
├── hello_web
|   ├── channels
|   ├── controllers
|   ├── templates
|   ├── views
|   ├── endpoint.ex
|   ├── gettext.ex
|   └── router.ex

Further you’ll see how this structure play very well with the Umbrella app.

3 Likes

This highlights “Phoenix is not your application”.

By separating your business logic from the web part, it add a strong point about Phoenix being just the web rendering layer of your application.

You could add a Text based client, scenic, or anyting else and switch between them, without change to core system.

2 Likes

So HelloWeb is for namespacing or just convention?

It is a conventional namespace.

1 Like

So Elixir has namespaces?

In functional programming you can think of modules as fancy namespaces. Behind the scenes in the BEAM they are 1-1 with binary blobs and can be dynamically loaded and unloaded but you’ll go a long way thinking of them as namespaces (in other languages, too, like julia.)

Merely by convention. Functions belong to modules. All module names belong to a global namespace. However by convention, Elixir modules can include .s to provide a sense of sub-grouping.

1 Like

I see HelloWeb is not a namespace but just a way to group related modules in this case such modules belong to all web related modules of the hello project. That means that HelloWeb could have been anything say like MyWeb.

1 Like

That is correct.

1 Like