Course contentsShow
← Software Engineering
Lesson 1276 of 1,93338. Layered and Modular ArchitectureFree lesson

Interface Adapters Layer

Converting data between use case and external agency formats through controllers, presenters, and gateways.

Interface Adapters Layer

What you'll learn: How the Interface Adapters Layer translates data formats between your application's business logic and the external world.

The Translation Problem

Your use cases work with clean, business-focused data structures—think domain entities and simple values. But the outside world (databases, web frameworks, APIs) speaks different languages: SQL rows, JSON payloads, HTTP requests, GUI widgets.

The Interface Adapters Layer sits between your use cases and these external agencies, performing the crucial job of converting data back and forth. It ensures your business logic never has to know whether it's talking to PostgreSQL, MongoDB, or a REST API.

The Three Types of Adapters

Controllers

Controllers receive input from external sources (like HTTP requests), convert that data into a format your use cases understand, call the appropriate use case, then hand off the result.

Think of them as translators at the entrance: "User sent JSON? Let me turn that into a domain object the use case expects."

Presenters

Presenters take output from use cases and format it for the external world—converting domain objects into JSON, HTML, XML, or whatever the delivery mechanism needs.

They're translators at the exit: "Use case returned a domain entity? Let me format that as the JSON structure the API consumer expects."

Gateways

Gateways implement the interfaces (ports) defined by your use cases to communicate with external systems like databases or third-party services. They translate between domain objects and database schemas or external API formats.

They're the persistent translators: "Need to save this domain object? I'll convert it to SQL. Need to fetch data? I'll turn those rows back into domain objects."

Why This Matters

By isolating format conversion, you can swap web frameworks, change databases, or modify API contracts without touching your business rules. The use cases remain pure and testable.

Key Takeaway: The Interface Adapters Layer protects your business logic from external format concerns through controllers (input conversion), presenters (output conversion), and gateways (persistence/external service conversion).