Can you have a CLI application and Phoenix application in the same project?

We typically set up a project structure with mix, but what if I need to develop an application that can run as a CLI app and as a phoenix app? For example, an app that converts file formats - I want to be able to pass in file names as arguments and run it from CLI but I also want to expose it as a microservice.

Worst case (is it the worst?) is to define the business logic as a module/repo and import it into my separate CLI app and separate Phoenix app as a dependency…

That’s exactly what mix projects are designed to do!

Projects or applications?

Mix makes a distinction between projects and applications…

When we say “project” you should think about Mix. Mix is the tool that manages your project. It knows how to compile your project, test your project and more. It also knows how to compile and start the application relevant to your project.

When we talk about applications, we talk about OTP. Applications are the entities that are started and stopped as a whole by the runtime.

So within your mix project, you could use something like burrito alongside Phoenix.

2 Likes