How does `mix run` work in an umbrella app?

I have an umbrella app where one of the /apps is a Phoenix project.

I’m wondering how it works that I can run mix phx.server from the root directory.

Additionally, there’s a Mix project. How does Mix know which Application to startup first?

As your root application depends on the phoenix application, the phoenix application will be searched for mix-tasks, as any other dependency. Then at some point it will it will find phx.server in some transitive dependency and run it. But to be honest, such a search is not even necessary as mix compiles all dependencies and your code and then builds a module name from the task given on the CLI, and then simply run the run/1 function in that module.

mix doesn’t really know the order in which applications should be started. The BEAM does. Each application has some metadata available to the BEAM which specifies applications that needs to be started in advance to the current one. The BEAM then simply walks this tree of dependencies and starts the applcations starting from the leaves of the tree.

2 Likes