liveBook · Manning

Adapter

As explained in Acing the Frontend Interview

An adapter is a component that translates between an application port and a concrete external interface or infrastructure mechanism.

An adapter keeps application logic separate from a concrete way of accessing data or infrastructure. A React component can call a consistent data interface instead of depending directly on REST, GraphQL, or a mock. In Hexagonal Architecture, adapters connect external interfaces to ports around the core domain. section 5.2 section 6.1

In an architecture interview, clarify which side of the boundary an adapter serves:

  • A driving adapter handles input from a web UI, CLI, or API and invokes an inbound port. section 6.1
  • A driven adapter implements an outbound port for a database, external authentication service, or notification service. section 6.1
  • A frontend data adapter gives components one interface while the underlying source can change or be mocked. section 5.2

Refactoring user management

Suppose user-management logic directly handles SQL, HTTP, and JWT concerns. Move user entities and services into a core without those dependencies. Define inbound ports for registration, authentication, and updates; define outbound ports for persistence, authentication, and notifications. UI and API adapters call the inbound ports, while infrastructure adapters implement the outbound ones. This makes the core easier to test and lets external technologies change without rewriting domain logic. section 6.1

Listing 5.12 Data accessing using the Adapter pattern
export const userAdapter = {
  getUser: async (id) => fetch(`/api/users/${id}`).then(res => res.json()),
  updateUser: async (id, data) => axios.put(`/api/users/${id}`, data),
};

The small user adapter illustrates a consistent frontend access point for getting and updating users; its methods hide the component’s direct use of fetch and axios. section 5.2

Figure 6.5 Hexagonal Architecture of the user management domain.

The diagram places driving and driven adapters on opposite sides of the user-management core, making their relationships to inbound and outbound ports visible. section 6.1

How Acing the Frontend Interview covers it

How deep it goes
Works through frontend and domain-refactoring examples, distinguishing driving from driven adapters without specifying a full implementation for each port.
Examples
Uses a React user-data adapter and a user-management refactor with web, CLI, API, database, authentication, and notification adapters.
What it assumes
Assumes familiarity with React components and external services; introduces ports through a concrete refactoring scenario.
What you can do after
Build it from scratch: place an adapter between components or domain ports and concrete services so implementations can be tested or replaced.
How it connects
Connects to Hexagonal Architecture, inbound and outbound ports, separation of concerns, mocking, and real-time data access.

Also explained in

Compare how 17 books explain adapter →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Acing the Frontend Interview. The section links point to the parts of the book it draws on.