CodePark/ questions / Layered, clean & hexagonal architecture
START PRACTICINGPRACTICE
Backend question · Software design & patterns › Layered, clean & hexagonal architecture

In a clean/hexagonal codebase, the RegisterUser use case must send a welcome email through SendGrid. Which arrangement follows the dependency rule?

The use case defines an EmailSender port, and an infrastructure SendGridEmailSender implements it

The use case should define an EmailSender port, and an infrastructure SendGridEmailSender should implement it. The port belongs to the inner layer, and the inner layer's needs decide its shape. The adapter in the outer layer depends on the port. So all dependencies point inward, which is the dependency rule.

Why the other options are wrong:

• "The infrastructure layer defines
EmailSender": the use case still imports from an outer layer, so the dependency points outward.
• "The use case imports the SendGrid SDK directly": the inner layer now depends on a specific technology.

• "The controller sends the email after the use case returns": this moves a business step into the delivery layer.