I’m currently developing a web application and am wondering if I’m heading in the right direction.
I decided to opt for Dave Thomas’ approach, where each application resides in its own directory. And all dependencies between them is linked through path. i.e.:
# mix.exs
defp deps do
[
{:accounts, [path: "../accounts"]},
{:mailer, [path: "../mailer"]},
]
end
And the dependencies are as follows
web
├── mailer (../mailer)
└── accounts (../accounts)
└── db (../db)
First thing I’m unsure of, is the separation between accounts and db. As the project grows and I need a new module, i.e. products. This would be a new dependency of web, and would also be dependent on db.
web
├── mailer (../mailer)
└── accounts (../accounts)
└── db (../db)
└── products (../products)
└── db (../db)
One of the reasons I bought into this method of dependencies is that it strives to make a module reusable. In this case accounts and inventory would not be reusable applications on their own.
- Taking into account the previous statement, is this still a good approach to structure the application, or should it be made simpler?
Another issue I encountered was configuring the application. I want to test each module individually. This leads to many applications needing the same configuration.
I opted for configuring each application within its own folder, and importing it in any of the applications depending on it.
Here is an example of that: accounts loading config from db
# /accounts/config/config.exs
use Mix.Config
import_config "../../db/config/config.exs"
And
# /accounts/config/test.exs
use Mix.Config
import_config "../../db/config/test.exs"
- Would this be considered good practice for configuring a project like this?
Any insights will be appreciated