Phoenix API-only with Admin Panel

Hey! I’m returning back to Elixir and Phoenix after 2 years break, so I need to catch up a bit.
In my project, I’m going to build frontend with ReactJS, and backend with Elixir Phoenix, as API-only. I’m aware that I can use --no-html flag to create Phoenix without HTML. But also, I would like to have the Admin Panel, and I would like to have this with the minimal effort. I could use “standalone” admin panel like AppSmith running in another Docker Container. But I believe that doing it with Phoenix Elixir and Kaffy/Torch, it should be easier (+ I have an access to models/methods/actions, etc.).

Not looking here a detailed instructions how to do it, but your opinions and experience, whether does it make sense or not, and what can be tricky. And maybe how to start building this. For instance, I can use --no-html and then add missing libraries, or go opposite: start with full package and then remove unnecessary.

Thanks for all your help!

1 Like

I’m using the following pattern:

  1. create an umbrella.
  2. create an app for the core business domain:
$ mix phx.new.ecto demo
  1. create an app for Web API:
$ mix phx.new.web \
  --binary-id \
  --no-assets \
  --no-html \
  --no-live \
  --no-dashboard \
  demo_web_api
  1. create an app for admin dashboard:
$ mix phx.new.web \
  --binary-id \
  --no-dashboard \
  demo_admin

In development, I:

  1. I will abstact my business in demo.
  2. expose demo to frontend developers by demo_web_api
  3. expose demo to administrators by demo_admin

When I am ready to ship, I will create a release with all these apps.

Pros:

  • every app has its own responsibility, It’s easy to add or remove new app without changing the core business domain. And you are confident to do that.

Cons:

  • a little verbose.

Back to your questions:

  1. Should I start from minimal deps or full deps? In demo, I prefer minimal. In demo_web_api and demo_admin, I prefer full deps.
  2. Should I use an AppSmith or Kaffy / Torch? I depends. If the work schedule is tight, and you don’t want to improve your skills by writing an admin panel, It’s ok to use them.
3 Likes

The same can be done using the Components projects approach, that @pragdave promotes and that I think its very well suited to separate responsibilities, like suggested with the use of umbrella apps. You can see this approach in my repo for his course:

3 Likes

Cool! I like the umbrella approach, thanks!

I really like this approach as well and started on a similar path by setting up an umbrella project, but I’m a bit confused about the details.

I’m building an app that fetches user health/activity data from a 3rd party API, I want to visualise that data with a Progressive Web App, so I’m looking into using Phoenix as API only.

The umbrella project contains the following projects:

  1. Thirdparty - only does the API calls to the 3rd party to fetch the data, doesn’t save it. The external API is quirky, so I decided to contain it in a separate project.
  2. Core - uses Thirdparty to get the data and saves it to our database. Contains all the domains and business logic.
  3. Client - the Phoenix API that will be consumed by the PWA
  4. Admin - internal admin interface

What I’m not sure of:

  1. Where do I put the authentication related code/domains for the Client API? Would I also include it in Core or put it in Client? Should I create a different database within Client?
  2. Same question, but for Admin.
  3. How should the projects communicate with each other? Currently I define for example Thirdparty as a dependency of Core and I just use Thirdparty.fetch_some_data() and it works fine, wondering about what’s the usual way and any upsides/downsides compared to something like processes.
  4. I’ve just started building the Client and generated it with mix phx.new.web and got the PubSub warning message. Before opening up another can of worms, could someone explain how PubSub fits into the picture?
  5. I’ve generated the Core project simply with mix new and added Ecto, not with mix phx.new.ecto. Am I missing something if I don’t use the latter?

Sorry for asking so many questions and feel free to just point me to a link/book/chapter if it’s too much to write.

Thanks a bunch!!