Ken Crocken Front End Engineer

Ken Crocken | Front End Engineer

Home

Single Page Application Layers & Architecture

I built Lunar Phase to track moon cycles, but let’s be honest—it was mostly a convenient excuse to showcase the anatomy of a SPA: from React components orbiting the presentation layer, to services handling fetch calls like Apollo missions, state management waxing and waning, routing via React Router constellations, and business logic pulling it all together like gravity.


In the architecture of a Single Page Application (SPA), there are typically multiple layers that each serve distinct roles in maintaining modularity, separation of concerns, and scalability. Here’s a breakdown of the common layers and how they interact, especially in the context of React (and similar frameworks) with hooks interacting with the service layer.

1. Presentation Layer (UI Layer)

2. State Management Layer

3. Service Layer (Data Layer)

4. Business Logic Layer

5. Routing Layer

Example Workflow

  1. User Interaction: A user clicks a button to fetch some data.
  2. UI Layer: The button click triggers an action in a React component.
  3. State Management Layer: The component may update some local state using useState or trigger a global state update through a dispatch (useReducer or useDispatch).
  4. Service Layer: A custom hook (like useFetchData) calls the service layer to fetch data from an API.
  5. Business Logic Layer: If there’s any transformation required (e.g., filtering or sorting the fetched data), the business logic layer will handle that.
  6. UI Update: Once the data is returned and processed, it is passed back to the UI layer to update the state and re-render the component.

Key Takeaways

This architecture separates concerns, improves reusability, and provides a scalable way to manage data flow and interactions in a SPA.

Scroll to top