Hi, I’m fairly new to Phoenix and have a design question.
I have a project that has two components, a JSON API and an HTML interface. They both share one common database.
One thing I could do is to have an umbrella application with two separate apps in it. I am also considering to have just one application and use two separate controllers.
What is the best practice and how would you organize the code for maintainability?
The router file already allows You to separate multiple pipelines. One for the browser, one for api.
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
end
pipeline :api do
plug :accepts, ["json"]
end
scope "/api", BlahWeb do
pipe_through :api
scope "/v1" do
# versioned API routes
end
end
scope "/", BlahWeb do
pipe_through :browser # Use the default browser stack
# HTML routes
end
Further to what Koko has said, I think it depends on your approach to the project - are you following something like the Replaceable Component Architecture? If so you might want to check out PragDave’s course in which he uses two separate (Phoenix) apps/components in the app - one for the html layer and one for web sockets/the spa