I used the
--no-html options when making a new phoenix project, and I don’t understand why the MyAppWeb module has controller, view, router, channel, and view_helpers.
The structure of the default phoenix app just doesn’t make a lot of sense to me, and I’m wondering if I should build my app from scratch. Any reason to not do this?
I don’t understand why phoenix apps have a MyAppWeb module and a MyApp module. It’s not clear to me what belongs in Web, and what belongs outside of Web.
I’m wanting to have some rest endpoints and websocket channels to serve a variety of clients, but all frontend UI would be independent. In other words, if I’m going to deploy a React app and connect to my phoenix-based API, I will deploy it as a standalone app, rather than manage it with an assets pipeline.
You could try getting a hold of the Phoenix in Action book by Geoffrey Lessel. It starts with creating a plain elixir application, and later you add phoenix onto it with the book explaining how it’s all wired up.
You need these when You build an API… a router, controllers, and views to render json.
And You have only an api pipeline in your router.
You don’t have assets when using --no-webpack, and You don’t use any templates with --no-html. You don’t use phoenix_html, phoenix_live_reload as dependencies.
You separate Web from your business domain and Ecto. Nothing related to your Core should go in Web… only channels, controllers, views etc.
Correct, your business logic and your API logic should be split. That’s why phoenix generates a
_web and your domain separately, as these should be seperate.
You don’t need to deploy HTML/CSS for your API, but the MVC concept can be used for your REST endpoints, which is where Phoenix (as an API) shines.
You can also add
--no-gettext in there if you don’t need to translate responses from the backend. It will remove one dependency and some boilerplate.
I’ll try to have a stab at this.
Think about it this way:
You have your business. You sell papers.
You order paper from suppliers and your employees stock them and arrange them in your store and sell them to customers.
You have suppliers, papers, employees, stores. Those are parts of your business.
On the other hand, your customers order paper from you through phone calls, emails, or they stop by your store.
Phone calls and emails are not part of your paper business, they’re tools to help you connect with your customers and receive orders. Phones, obviously, know nothing about your business. They just allow your to receive orders. How do you store and process those orders? Phones don’t care. It’s up to you.
Phones and emails are the
myapp_web part of your business. Controllers, views, and templates should just connect the outside world to your business. They know nothing about your business logic. They just take what the customers tell them and deliver it to your business in a nice way.
In your case, the
myapp_web part is json only since you’re not using html. It’s like saying, “I don’t want to have a physical store where people come by, I’ll just receive orders through emails”.