Ken Crocken Front End Engineer

Ken Crocken | Front End Engineer

Home

Single Page Application Layers & Architecture

Lunar Phase is a small demo app in React that displays the current phase of the moon by fetching data from the Naval Observatory API. Demonstrates the use of React hooks, the fetch API and an architectural approach to keep your app organized.

repo project site

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