magosi

magosi

Hi, my current Phoenix project involves a website with a lot of different functionality, like a digital store, chat system, file uploads, blog posts, comments, etc. How can I go about developing this project so that each feature is a self-contained unit that I can reuse in future projects? For example, how can I make the digital store (with its contexts, views, templates, routes, etc) a unit that can plug into the project and plug into future projects? I know Django has a concept called apps that serves this purpose. Does Phoenix have a similar feature? I have seen people mention umbrella projects and I have made a small umbrella project before when I read the book “Programming Phoenix”, but I am not sure how to go about splitting these features so that they are almost pluggable. Any advice is appreciated and I would like to know how some of the more experienced Phoenix developers reuse code between projects to avoid reimplementing functionality.

Showing Posts 1 to 7

wolf4earth

wolf4earth

AFAIK there is no support for this out of the box but it should be doable.


Assuming you really want to have multiple Phoenix apps, then going down the umbrella app route is most likely the best approach.

For that you would have one “main” app, and a number of “sub” apps (just by name though, from the umbrella perspective they are all equal).

Your “main” app would then depend on all these “sub” apps and actually serve requests. In the main apps router you could then use forward to forward the request to the router of the correct “sub” app. From here on it’s business as usual.

In the “sub” apps you would merely disable the server option of the Phoenix endpoint (in the config, the default is false), so that they do not bind to a port.

If you then at any point in the future want to extract a “sub” app into a standalone app you would have to set the server option back to true (and of course clean up the umbrella stuff, there are guides for this).

Does this help you?

magosi

magosi OP

Thank you very much for your detailed answer @wolf4earth! It is a good starting point for me and I will definitely attempt it.

Do you think it will be ok to make associations between models as needed, even though they live in different umbrella apps? For example, the “main” app will have a user model, and a “sub app” a blog post model. These have to be associated with one another (user is author of a post).

Also, why is this not a frequently asked question? Do other people just write their apps from scratch?

fireproofsocks

fireproofsocks

I have re-used modules many times from different Phoenix projects: they are very portable. The only wiring that was needed to install them was to reference them somewhere (e.g. in a plug or a controller). It’s not a plug-and-play as, say, a WordPress plugin, but 1 size doesn’t always fit all. Sometimes the “simplicity” in having things as easy to install as a WordPress plugin backfires when you need to customize it, and jail-breaking the functionality out of its carefully defined environment is harder than just wiring in more generic modules.

Phoenix Plugs might be the middle ground there: they revolve around a well-documented struct and are easy enough to reference in various projects. They can be used to handle an entire request, from soup to nuts, so I would recommend giving them a look before trying to balance multiple Phoenix apps under an umbrella or some other more sophisticated solution.

egze

egze

I don’t think it a good idea, given your requirements that apps are self-contained. What you are proposing definitely breaks it.

What you need is sort of micro-service design. There is an accounts application. It is concerned with users and everything related. It also publishes changes (PubSub, AMQP, whatever).

Blog application deals with blogs and posts. But since it needs users also, it subscribes to the messages from the Accounts app and keeps a local copy of users table. But their DBs and tables are not touching each other. Each app has its own.

This is only a quick idea, there are more ways how to build such a thing. But it is a good amount of work to set it up properly. I’d only do this if working in a company where each team implements their own service.

magosi

magosi OP

Thanks @egze. So if I understand correctly, its best to implement microservices revolving around core datastructures that can subscribe to one another, but only in the case where you write a suite of apps that will use these services. Otherwise for individual apps, write it from scratch?

egze

egze

Yeah, I would not bother with such strict boundaries for a simple application.

Btw, have a look at this video: https://www.youtube.com/watch?v=hgDCg3QdZgU

magosi

magosi OP

Thank you very much. I will certainly check it out.

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews