cdddg / py-clean-arch

A Python implementation of Clean Architecture, inspired by Uncle Bob's book
67 stars 12 forks source link

Using mail operations by example clean architecture #37

Open metallist203 opened 1 month ago

metallist203 commented 1 month ago

Hello, i'm developing my project, witch i using aiosmtplib. How i can use this library in clean architecture? Do you have any example?

cdddg commented 6 days ago

Apologies for the delayed reply; I've been busy with work.


The email sending functionality can involve two layers:

Infrastructure Layer: This layer is responsible for interacting with external services like SMTP servers. It handles the technical details of external systems, such as sending emails using aiosmtplib.

Interface Adapters Layer: This layer encapsulates the logic for sending emails, converting application requirements into operations on the infrastructure layer. It defines abstract interfaces.


Based on my experience, I use a folder dedicated to external services:

adapters/mail.py

class MailAdapter:

    def __init__(self, *args, **kwargs):
         ...

    def send_mail(self, *args, **kwargs):
         ...

* If there's a need to configure SMTP settings, I might handle it in infrastructure/mail.py or core/mail.py.

* Naming Issue: For the adapters, I've previously used names like service, adapter, or gateway. Ultimately, our team settled on using adapter based on our preferences.