Frontend System Design · Lesson 2 of 15 · 4 min
Core Frontend Architecture Concepts
This is how you explain the big picture of your app's structure and justify your design choices.
Decomposing UIs into Components
This is the fundamental pattern of modern frontend development. You break down a user interface into small, reusable, and independent pieces. A Button is a component. A ProductCard that uses that Button is another component. A ProductGrid that displays ProductCards is a parent component.
This approach lets you build complex UIs by composing simple parts. It improves maintainability because a change to one component is isolated. It speeds up development because multiple engineers can work on different components in parallel.
In an interview, talk about trade-offs. The key decision is component granularity.
- Too granular: A
<BoldText>component is probably overkill. You create an abstraction with no real benefit, adding complexity.- Too monolithic: A 500-line
<UserProfilePage>component that handles data fetching, multiple form states, and its own styling is a maintenance nightmare.Your goal is to find the right boundaries. A good component encapsulates a distinct piece of UI and its related logic. If you find yourself copying and pasting a chunk of JSX with its associated state and effects, it's a strong signal to extract a component.
Managing Data Flow and State
Once you have components, they need to communicate. The standard pattern is unidirectional data flow: data flows down from parent to child via props, and events flow up from child to parent via callbacks.
This makes your application predictable. When state changes, you know exactly where the change came from and how it will propagate. It simplifies debugging immensely compared to models where any part of the app can arbitrarily change any other part.
// ParentComponent.tsx
import React, { useState } from 'react';
import ChildComponent from './ChildComponent';
const ParentComponent = () => {
// State lives in the highest-level component that needs it.
const [counter, setCounter] = useState(0);
// Parent defines the logic for updating state.
const handleIncrement = () => {
setCounter(prevCounter => prevCounter + 1);
};
return (
<div>
<p>Parent Counter: {counter}</p>
{/* Data (counter) flows down. */}
{/* Callback (handleIncrement) flows down. */}
<ChildComponent currentCount={counter} onIncrement={handleIncrement} />
</div>
);
};
// ChildComponent.tsx
import React from 'react';
interface ChildProps {
currentCount: number;
onIncrement: () => void;
}
const ChildComponent = ({ currentCount, onIncrement }: ChildProps) => {
return (
<div>
<p>Received Count: {currentCount}</p>
{/* Child triggers the parent's callback on an event. */}
<button onClick={onIncrement}>
Increment
</button>
</div>
);
};
This flow is easy to trace. The child doesn't know how the state is updated; it only knows to call onIncrement.
The trap: Unidirectional data flow can lead to "prop drilling," where you pass props through many intermediate components that don't use them. This is a sign that your state is too far from where it's needed.
This is the problem that state management solutions solve. They provide a centralized store for state that any component can access without passing props down the tree.
- Local state (
useState): For state used by only one component or a few direct children. This should be your default. - Context API: For low-frequency updates of state needed by many components at different levels (e.g., theme, user authentication).
- External libraries (Redux, Zustand): For complex, high-frequency state changes that are central to the application's function (e.g., the state of a collaborative editor). Using these adds boilerplate but gives you powerful debugging tools and strict update patterns.
Choosing the right tool is a key architectural decision. Don't reach for a global state library until prop drilling becomes a clear and present problem.
Structuring the Application Shell
Beyond components and state, your application needs a skeleton. This primarily involves routing and how you communicate with the server.
Client-Side Routing
In a Single-Page Application (SPA), you don't want a full page reload every time the user navigates. A client-side router intercepts URL changes and maps them to different component views.
This is what allows for a fast, app-like experience. It's responsible for rendering the correct page component (e.g., /dashboard, /profile/:userId) and handling things like 404 pages. Every major framework has a standard library for this (React Router, Vue Router). Being able to explain how it works—manipulating the browser's History API to change the URL without a page request and re-rendering the component tree—is expected.
API Layer
Hardcoding fetch calls inside components is a common mistake. It mixes concerns and makes your code difficult to test and refactor.
A better approach is to create an API layer or service module. This module is solely responsible for communication with the backend. It abstracts away the implementation details of making HTTP requests, handling authentication tokens, and parsing responses or errors.
Your components then call functions from this service layer, like api.getUser() or api.updatePost(postId, data). This keeps components focused on UI and state, while the API service handles the network. This separation is one of the clearest indicators of a thoughtfully designed frontend.
Try it
Take a component you've written that is over 100 lines long. Identify a distinct piece of UI within it (like a form section, a list item, or a modal) and extract it into its own component. Move the necessary state and props to make it work. Notice how this clarifies the logic in both the parent and the new child.
Next: Client-Server Interaction Fundamentals
Lock it in — apply this lesson under interview conditions.