Compilation issues on umbrella project

Hello everyone,

I am currently working on an Elixir project that utilizes an umbrella app setup. Unfortunately, we are encountering numerous compilation issues that are adversely affecting our development experience. I would greatly appreciate your assistance and guidance regarding these challenges.

To provide some context, our umbrella app consists of the following apps:

  • web: Live view user-facing app
  • admin: Live view internal admin app
  • api: GraphQL API app
  • db: DB schemas, changeset, contexts
  • pool: Background jobs, cron jobs, Broadway, etc.

Here is a visual representation of the dependency graph:

Now, let’s delve into the problems we are currently facing:

  1. Lazy Compilation:
    We have observed that when we make code changes, the code only partially compiles. We expected that running mix compile followed by starting the server would eliminate the need for further compilation. However, we are encountering situations where the code starts compiling again after the server is launched or upon hitting certain code paths, such as specific browser URLs.

  2. Mismatch in Compile-time vs. Runtime Value Configuration:
    During server startup, we often encounter errors indicating a mismatch between the compile-time and runtime values of certain configurations. For example:

    ERROR! the application :db has a different value set for key :default_admin_id during runtime compared to compile time. Since this application environment entry was marked as compile time, this difference can lead to different behaviour than expected:
    
    * Compile time value was set to: nil
    * Runtime value was set to: "xxxx"
    

    The environment variable is correctly sourced in the terminal and available during compilation. This error typically occurs when restarting the server process within the same terminal. The only workaround we have found is to kill the server process and execute mix compile --force.

  3. Nebulex:
    We are utilizing Nebulex for caching purposes, but we frequently encounter the following error:

    (Nebulex.RegistryLookupError) could not lookup Nebulex cache App.API.Cache.UserCache because it was not started or it does not exist
    

    This issue often arises when code changes trigger recompilation while the server is running or when manually recompiling in the iex session. The only solution we have found is to restart the server.

  4. Unfinished Compilation:
    When making code changes, we often encounter errors due to the code attempting to access modules that are still in the process of compilation. For instance, the web app may attempt to access a module in the db app that is still compiling, leading to errors. This becomes more problematic due to live reloading in Phoenix.
    We expect the app to wait until all related modules and umbrella dependencies have finished compiling before attempting to load a page. Additionally, we feel that there are unnecessary compilations of unrelated components even for minor code changes, resulting in slower development cycles.

I would greatly appreciate any help, suggestions, or insights regarding these issues.