HackSoftware / Django-Styleguide

Django styleguide used in HackSoft projects
MIT License
5.12k stars 520 forks source link

Where to store interfaces/adapters/ports? #124

Closed skonik closed 1 year ago

skonik commented 1 year ago

Hey

I would like to discuss if you have any thoughts on where to store interfaces/adapters. Let's say you have notification system used in your services. You know that you might change it from expo push API to firebase push API. You have written an interface for that(abstract push notification client). Where would you put abstract and concrete classes of push notification client? Is it good idea to store it inside services or maybe in another place? What would you say?

You have really good styleguide, btw.

RadoRado commented 1 year ago

@skonik hello :wave:

The service layer might not be a good place for what you are describing.

I'd do the following:

  1. If your abstraction around interfaces has nothing to do with any parts of Django - I'll isolate it in a module somewhere. We usually have an integrations app, so I'd do something like integrations/notifications/ and then have the Python implementation there (depending on how you like to structure your Python modules. The simplest would be to place it in __init__.py)
  2. If your notifications are dealing with the ORM, you might want to have a different Django app called notifications/ and put everything there.
    • You might want to have a service layer as the main interface & then call something from the Python module.

That's my take for now.

If you have some codesnippets & more examples, I might be able to be more helpful ✨

skonik commented 1 year ago

I think that's all what I wanted to hear. Thank you!