Best location for a LinkedIn API call module

A standard Phoenix application with these directories:

lib
├── shop
├── shop_web

We need to interact with the LinkedIn API to upload and download images and text postings. For that we want to create a new module which gets called from the controllers. Let’s assume we call this file linked_in.ex. An example function would be LinkedIn.upload_image/1.

What we discuss in our team is the best location for that file. Should we put it in the /lib/shop/linked_in.ex or should we create a new directory and put it in /lib/social_media/linked_in.ex? Or should we even put it under the /lib/shop_web directory because we are using it only from the controllers?

I am aware of the fact that it doesn’t matter technically where we put this file. I would like to understand what is the best practices approach for this. Where would a normal Phoenix/Elixir programmer search for it? Thank you!

If you’d had not only the web interface, but also a cli/telnet/… interface, would the cli interface interact with the linked in module? If yes then it doesn’t belong in the shop_web part of your application.

As for the lib/shop vs. lib/social_media folder – I’d start with lib/shop/social_media. If this becomes less specific to this shop and more generic for linked in consider pulling it out into a library.

3 Likes

IMO lib/shop/linked_in/ is fine for now because it’s basically one more domain / business context in your main app and that’s how they are usually organized.

2 Likes