Skip to main content

What is "Layered Architecture" in frontend?

What Layered Architecture is

Layered Architecture is the principle of splitting an application into layers, where each layer has its own area of responsibility and limited dependencies.

In other words:

Each layer is responsible for one aspect of the system, and knows only about the layers below it, never above.


Why layers are needed

As an application grows, logic, data, and UI start to mix together. Layers let you structure this:

  • each layer solves its own task,
  • interaction between layers is clearly defined,
  • and the code becomes predictable and scalable.

Typical levels (frontend version)

LayerArea of responsibilityExample
UI / Presentation LayerDisplays data to the userReact components, forms, buttons
State / Application LayerManages application state and business rulesRedux / Zustand / Hooks / Context
Domain LayerHolds business logic and domain modelsfunctions like calculateDiscount(), UserEntity
Data / Infrastructure LayerWorks with external data sourcesREST, GraphQL, API clients, LocalStorage

Example (React + API)

Without layers (everything in one component)

javascript
function ProductList() { const [products, setProducts] = useState([]); useEffect(() => { fetch("/api/products") .then(res => res.json()) .then(setProducts); }, []); return ( <div> {products.map(p => ( <div key={p.id}>{p.name} - {p.price}$</div> ))} </div> ); }

Here the component simultaneously:

  • makes the request (data layer),
  • manages state (application layer),
  • renders the UI (presentation layer).

→ An architectural "mess".


With separation into layers

javascript
// data/productsApi.js export async function getProducts() { const res = await fetch("/api/products"); return res.json(); } // domain/productService.js export function calculateDiscount(product) { return product.price * 0.9; } // model/useProducts.js (application/state layer) import { useEffect, useState } from "react"; import { getProducts } from "../data/productsApi"; import { calculateDiscount } from "../domain/productService"; export function useProducts() { const [products, setProducts] = useState([]); useEffect(() => { getProducts().then(res => { setProducts(res.map(p => ({ ...p, discounted: calculateDiscount(p) }))); }); }, []); return products; } // ui/ProductList.jsx (presentation layer) import { useProducts } from "../model/useProducts"; export function ProductList() { const products = useProducts(); return ( <div> {products.map(p => ( <div key={p.id}> {p.name} - {p.discounted}$ </div> ))} </div> ); }

Now each layer is isolated:

  • data/ - handles requests
  • domain/ - business logic
  • model/ - state
  • ui/ - rendering

Layer dependency rules

javascript
UIModelDomainData
  • UI knows about Model, but not about Domain directly
  • Model can reach into Domain and Data
  • Domain is independent (knows nothing about UI or the API)
  • Data is the bottom layer, serving everyone

The direction of dependencies always points "downward".


Layered Architecture in Feature-Sliced Design

In FSD (Feature-Sliced Design), this principle is formalized as project layers:

javascript
shared/ (infrastructure and shared modules) entities/ (domain models) features/ (application features) pages/ (assembling features into pages) processes/ (cross-cutting scenarios) app/ (application initialization)

Each layer depends only on the layers below it - for example, features can use entities, but not the other way around.


Advantages of Layered Architecture

AdvantageDescription
Separation of responsibilitiesEach layer solves one task
Isolation of changesYou can change a layer without breaking others
A clear structureThe project is easy to read and scale
TestabilityLayers are tested independently
ReusabilityBusiness logic can be extracted into other projects
Compatibility with DDD/FSDIntegrates easily with modern architectural approaches

Layered vs Feature-Based Architecture

ApproachSplits by...Example
Layered ArchitectureRoles (UI, Logic, Data)ui/, domain/, data/
Feature-Based ArchitectureFunctionality (auth, cart)features/auth/, features/cart/

The best option is to combine both: inside each feature you can also keep layers (ui/, model/, domain/, api/).


Summary

WhatDescription
IdeaSplit the application into logical levels with clear dependencies
Main layersUI / Application / Domain / Data
Direction of dependenciesTop to bottom only
GoalStructure, readability, scalability
In ReactOften implemented inside features (through FSD or Clean Architecture)

Main idea: Layered Architecture is the "architectural skeleton" of an application: each layer knows its place and does not interfere with others' business.

This makes the code understandable, testable, and resilient to project growth.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.