
"Frontend architecture" sounds like one decision, but it's really four that people tend to blur together:
Rendering: where does the HTML come from?
Code organization: how is the codebase structured?
State and data flow: how does data move through the UI?
System scale: how do many teams ship one product?
This post walks through the main patterns in each group: what problem it solves, how it works, and where it hurts. Patterns aren't mutually exclusive. A real app usually mixes several from each group.
mindmap
root((Frontend Architecture))
Rendering
SPA / CSR
MPA
SSR
SSG
ISR
Streaming and RSC
Islands
Code Organization
Component based
Atomic Design
Feature Sliced
Layered and Clean
MVC and MVVM
State and Data Flow
Flux and Redux
Signals
Server vs Client state
State machines
System Scale
Micro frontends
Monorepo
BFF
Local first1. Rendering Patterns
The first question: when and where is the HTML produced?
flowchart LR
subgraph AOT["Ahead of time"]
SSG["SSG"]
ISR["ISR"]
end
subgraph REQ["On each request"]
SSR["SSR"]
RSC["Streaming + RSC"]
EDGE["Edge SSR"]
end
subgraph BRW["In the browser"]
CSR["SPA / CSR"]
ISL["Islands"]
end
classDef green fill:#16a34a,stroke:#166534,color:#fff
classDef blue fill:#2563eb,stroke:#1e40af,color:#fff
classDef pink fill:#db2777,stroke:#9d174d,color:#fff
class SSG,ISR green
class SSR,RSC,EDGE blue
class CSR,ISL pink
style AOT fill:#dcfce7,stroke:#16a34a,color:#111
style REQ fill:#dbeafe,stroke:#2563eb,color:#111
style BRW fill:#fce7f3,stroke:#db2777,color:#111SPA / CSR (Client-Side Rendering)
The server returns an empty HTML shell and a JavaScript bundle. The browser builds the UI and fetches data on its own.
sequenceDiagram
participant B as Browser
participant C as CDN
participant A as API
B->>C: GET /app
C-->>B: Empty HTML + JS bundle
rect rgb(254, 243, 199)
Note over B: Download, parse, run JS
end
B->>A: GET /api/data
A-->>B: JSON
rect rgb(220, 252, 231)
Note over B: Render UI
endPros: instant in-app navigation, rich interactivity, simple static hosting.
Cons: slow first paint, weaker SEO unless you add SSR or pre-rendering, large bundles.
Use for: dashboards, admin panels, anything behind a login.
MPA (Multi-Page Application)
Every navigation is a full request that returns a ready-made HTML page. It's the original web model, and it's having a comeback through HTML-over-the-wire tools like htmx and Hotwire, plus the View Transitions API for smooth page changes.
Pros: simple, SEO-friendly, works without JavaScript.
Cons: full reloads, hard to carry client state across pages.
Use for: content sites and form-heavy apps.
SSR (Server-Side Rendering)
The server renders HTML on every request, then JavaScript hydrates it to make it interactive.
sequenceDiagram
participant B as Browser
participant S as Server
participant D as Data source
B->>S: GET /products
S->>D: Query
D-->>S: Data
rect rgb(219, 234, 254)
Note over S: Render HTML on the server
end
S-->>B: Full HTML (visible immediately)
rect rgb(252, 231, 243)
Note over B: Download JS and hydrate (now interactive)
endPros: fast first paint, great SEO, always-fresh data.
Cons: server cost, slower time to first byte, and a hydration gap where the page looks ready but isn't clickable yet.
Edge SSR is the same idea running on CDN nodes close to the user, which cuts latency.
SSG (Static Site Generation)
Pages are rendered once at build time and served from a CDN. It's the fastest and cheapest option, but content is only as fresh as the last build, and build times grow with page count. Perfect for docs, blogs, and marketing sites.
ISR (Incremental Static Regeneration)
SSG with an expiry date. Pages are served from cache and regenerated in the background when they go stale (stale-while-revalidate).
flowchart LR
U["Request"]:::blue --> CA{"Cached page fresh?"}:::yellow
CA -->|Yes| S1["Serve from CDN"]:::green
CA -->|Stale| S2["Serve stale page now"]:::orange
S2 --> RG["Regenerate in background"]:::purple
RG --> UP["Update cache"]:::teal
classDef blue fill:#2563eb,stroke:#1e40af,color:#fff
classDef yellow fill:#facc15,stroke:#a16207,color:#111
classDef green fill:#16a34a,stroke:#166534,color:#fff
classDef orange fill:#ea580c,stroke:#9a3412,color:#fff
classDef purple fill:#9333ea,stroke:#6b21a8,color:#fff
classDef teal fill:#0d9488,stroke:#115e59,color:#fffGreat for product catalogs and news: thousands of pages that change occasionally.
Streaming SSR and React Server Components
Streaming sends HTML in chunks as each <Suspense> boundary resolves, so one slow query doesn't block the whole page.
React Server Components (RSC) go further. Server components run only on the server and ship zero JavaScript. Only components marked as client components get hydrated.
flowchart TD
P["Page (server)"]:::server --> H["Header (server)"]:::server
P --> L["ProductList (server, fetches data)"]:::server
L --> C["ProductCard (server)"]:::server
C --> B["AddToCartButton (client)"]:::client
P --> F["FilterBar (client)"]:::client
classDef server fill:#2563eb,stroke:#1e40af,color:#fff
classDef client fill:#ea580c,stroke:#9a3412,color:#fffBlue = server only, orange = hydrated in the browser. The trade-off is a new mental model: you have to think about the server/client boundary and what can cross it (only serializable props).
Islands and Resumability
Islands (Astro, Fresh): a page is mostly static HTML with small interactive "islands" that hydrate independently, often only when they scroll into view.
flowchart TB
PG["HTML page"]:::blue
PG --> H["Header<br/>static"]:::gray
PG --> A["Article<br/>static"]:::gray
PG --> S["Search box<br/>island"]:::orange
PG --> CM["Comments<br/>island"]:::orange
PG --> F["Footer<br/>static"]:::gray
classDef blue fill:#2563eb,stroke:#1e40af,color:#fff
classDef gray fill:#9ca3af,stroke:#4b5563,color:#111
classDef orange fill:#ea580c,stroke:#9a3412,color:#fffResumability (Qwik) goes one step further. App state is serialized into the HTML, so the browser can resume where the server left off with no hydration step. Code is lazy-loaded as the user interacts.
Quick Comparison
Pattern | HTML is made | First load | SEO | Good for | Common tools |
|---|---|---|---|---|---|
SPA / CSR | In the browser | Slower | Weaker by default | Dashboards, internal tools | Vite + React/Vue, Angular |
MPA | On the server, per page | Fast | Great | Content sites, forms | Rails, Laravel, Django, htmx |
SSR | On the server, per request | Fast | Great | Personalized pages, e-commerce | Next.js, Nuxt, SvelteKit, React Router |
SSG | At build time | Fastest | Great | Docs, blogs, marketing | Astro, Eleventy, Hugo |
ISR | At build, refreshed in background | Fastest | Great | Catalogs, news | Next.js, Nuxt |
Streaming + RSC | On the server, in chunks | Fast, progressive | Great | Data-heavy pages | Next.js (App Router) |
Islands | At build or request, JS only where needed | Fast | Great | Content sites with some interactivity | Astro, Fresh |
2. Code Organization Patterns
The second question: how do you structure the code so it stays maintainable?
Component-Based Architecture
The foundation of React, Vue, Angular, and Svelte. The UI is a tree of small, reusable, encapsulated components: props flow down, events flow up.
flowchart TD
App:::blue --> Layout:::purple
Layout --> Sidebar:::teal
Layout --> Page:::teal
Page --> Table:::green
Page --> Chart:::green
Table --> Row:::orange
classDef blue fill:#2563eb,stroke:#1e40af,color:#fff
classDef purple fill:#9333ea,stroke:#6b21a8,color:#fff
classDef teal fill:#0d9488,stroke:#115e59,color:#fff
classDef green fill:#16a34a,stroke:#166534,color:#fff
classDef orange fill:#ea580c,stroke:#9a3412,color:#fffA common refinement is separating logic from presentation (the old container/presentational split, today usually done with custom hooks or composables).
Atomic Design
A shared vocabulary for component levels, from smallest to largest.
flowchart LR
A["Atoms<br/>Button, Input"]:::pink --> M["Molecules<br/>Search field"]:::orange --> O["Organisms<br/>Header, Product grid"]:::yellow --> T["Templates<br/>Page layout"]:::green --> P["Pages<br/>Real content"]:::blue
classDef pink fill:#db2777,stroke:#9d174d,color:#fff
classDef orange fill:#ea580c,stroke:#9a3412,color:#fff
classDef yellow fill:#facc15,stroke:#a16207,color:#111
classDef green fill:#16a34a,stroke:#166534,color:#fff
classDef blue fill:#2563eb,stroke:#1e40af,color:#fffGreat for design systems. Less helpful for deciding where business logic lives.
Feature-Based and Feature-Sliced Design
Group code by feature, not by file type. Instead of components/, hooks/, and services/ folders that scatter one feature across the tree, each feature owns its UI, state, and API code.
src/
features/
cart/
ui/
model/
api/
checkout/
entities/
product/
shared/Feature-Sliced Design formalizes this into layers with one strict rule: imports only go downward.
flowchart TD
APP["app: init, providers, routing"]:::red --> PAGES["pages: route screens"]:::orange
PAGES --> WIDGETS["widgets: large UI blocks"]:::yellow
WIDGETS --> FEATURES["features: user actions, e.g. add to cart"]:::green
FEATURES --> ENTITIES["entities: business objects, e.g. Product"]:::blue
ENTITIES --> SHARED["shared: UI kit, utils, API client"]:::purple
classDef red fill:#dc2626,stroke:#991b1b,color:#fff
classDef orange fill:#ea580c,stroke:#9a3412,color:#fff
classDef yellow fill:#facc15,stroke:#a16207,color:#111
classDef green fill:#16a34a,stroke:#166534,color:#fff
classDef blue fill:#2563eb,stroke:#1e40af,color:#fff
classDef purple fill:#9333ea,stroke:#6b21a8,color:#fffLayered, Clean, and Hexagonal Frontend
Keep business rules independent of the framework and the backend. The UI calls use cases, use cases talk to ports (interfaces), and adapters (REST client, GraphQL, localStorage) implement them.
flowchart LR
UI["UI layer<br/>components"]:::blue --> APP["Application layer<br/>hooks, use cases"]:::green
APP --> DOM["Domain<br/>entities, rules"]:::yellow
INF["Infrastructure<br/>API client, storage"]:::purple -->|implements ports| APP
classDef blue fill:#2563eb,stroke:#1e40af,color:#fff
classDef green fill:#16a34a,stroke:#166534,color:#fff
classDef yellow fill:#facc15,stroke:#a16207,color:#111
classDef purple fill:#9333ea,stroke:#6b21a8,color:#fffIt pays off in long-lived apps with complex domain logic or several clients. For a marketing site it's overkill.
MVC, MVP, and MVVM
Older patterns that separate data, display, and glue code. They're still the mental model behind many frameworks.
Pattern | Glue layer | How the view updates | Seen in |
|---|---|---|---|
MVC | Controller handles input and updates the model | View reads from the model | Backbone, server-rendered frameworks |
MVP | Presenter drives a passive view | Presenter calls view methods | GWT, older mobile apps |
MVVM | ViewModel exposes observable state | Data binding | Angular, Vue, Knockout |
3. State and Data Flow Patterns
The third question: how does data move, and who owns it?
Unidirectional Data Flow (Flux / Redux)
Data moves in one direction in a loop, so every change is traceable.
flowchart LR
V["View"]:::blue -->|dispatch| A["Action"]:::orange
A --> R["Reducer"]:::purple
R --> ST[("Store / State")]:::green
ST -->|subscribe| V
classDef blue fill:#2563eb,stroke:#1e40af,color:#fff
classDef orange fill:#ea580c,stroke:#9a3412,color:#fff
classDef purple fill:#9333ea,stroke:#6b21a8,color:#fff
classDef green fill:#16a34a,stroke:#166534,color:#fffRedux Toolkit and NgRx follow this model strictly; Zustand and Pinia are lighter store-based cousins. The cost is boilerplate; the payoff is predictability and great devtools.
Reactive State and Signals
Instead of re-rendering a component tree, fine-grained reactivity tracks which DOM nodes depend on which values and updates only those. Solid and Svelte 5 work this way by default, and Preact Signals can too when a signal is bound directly in JSX. Vue and Angular use the same dependency-tracking idea (refs, signals) but still update at the component level.
flowchart LR
S1(["count (signal)"]):::orange --> D["double (computed)"]:::purple
S1 --> T1["Text node A"]:::teal
D --> T2["Text node B"]:::teal
classDef orange fill:#ea580c,stroke:#9a3412,color:#fff
classDef purple fill:#9333ea,stroke:#6b21a8,color:#fff
classDef teal fill:#0d9488,stroke:#115e59,color:#fffIn a Solid-style framework, when count changes only the two text nodes update and no component function re-runs.
Server State vs Client State
Most "global state" is really cached server data. Treat the two separately. Let TanStack Query, SWR, or RTK Query handle fetching, caching, deduping, and revalidation, and keep only true UI state (modals, form drafts) in a client store.
flowchart LR
API["Server / API"]:::blue <--> QC["Query cache<br/>TanStack Query, SWR"]:::green
QC --> UI["UI"]:::pink
CS["Client store<br/>Zustand, Context, useState"]:::orange --> UI
classDef blue fill:#2563eb,stroke:#1e40af,color:#fff
classDef green fill:#16a34a,stroke:#166534,color:#fff
classDef pink fill:#db2777,stroke:#9d174d,color:#fff
classDef orange fill:#ea580c,stroke:#9a3412,color:#fffThis one split deletes a surprising amount of Redux code in most apps.
State Machines and Statecharts
Model the UI as explicit states and allowed transitions (XState is the popular library), so impossible combinations like "loading and error at the same time" can't exist.
flowchart LR
I(["idle"]):::gray -->|FETCH| L(["loading"]):::blue
L -->|SUCCESS| OK(["success"]):::green
L -->|FAILURE| E(["error"]):::red
E -->|RETRY| L
classDef gray fill:#9ca3af,stroke:#4b5563,color:#111
classDef blue fill:#2563eb,stroke:#1e40af,color:#fff
classDef green fill:#16a34a,stroke:#166534,color:#fff
classDef red fill:#dc2626,stroke:#991b1b,color:#fffOther styles you'll meet: atomic stores (Jotai, Recoil), proxy-based mutable state (MobX, Valtio), and the URL itself as state for filters and pagination.
4. System-Scale Patterns
The fourth question: how do many people and many apps fit together?
Micro-Frontends
Split a large UI into independently built and deployed slices owned by different teams, composed by a shell.
flowchart TB
SH["Shell / Host app<br/>routing, auth, layout"]:::blue
SH --> MF1["Catalog<br/>Team A"]:::green
SH --> MF2["Checkout<br/>Team B"]:::orange
SH --> MF3["Account<br/>Team C"]:::purple
classDef blue fill:#2563eb,stroke:#1e40af,color:#fff
classDef green fill:#16a34a,stroke:#166534,color:#fff
classDef orange fill:#ea580c,stroke:#9a3412,color:#fff
classDef purple fill:#9333ea,stroke:#6b21a8,color:#fffIntegration options include Module Federation (runtime), iframes, Web Components, server or edge composition, and plain build-time npm packages. The costs are duplicated dependencies, inconsistent UX, and operational complexity. It's worth it only when team autonomy is the real bottleneck, not as a default.
Monorepo with Shared Packages
Keep several apps and shared libraries (UI kit, utils, config) in one repo using Nx, Turborepo, or pnpm workspaces. You get atomic changes across apps, easier dependency alignment, and cached builds. It's the pragmatic middle ground before micro-frontends.
Backend for Frontend (BFF)
A thin server per client type that aggregates and reshapes backend APIs, so each UI makes fewer, simpler calls. It's also a good place to handle sessions and cookies, keeping tokens out of the browser.
flowchart LR
WEB["Web app"]:::blue --> BW["Web BFF"]:::purple
MOB["Mobile app"]:::pink --> BM["Mobile BFF"]:::purple
BW --> U["Users service"]:::green
BW --> O["Orders service"]:::green
BM --> U
BM --> O
classDef blue fill:#2563eb,stroke:#1e40af,color:#fff
classDef pink fill:#db2777,stroke:#9d174d,color:#fff
classDef purple fill:#9333ea,stroke:#6b21a8,color:#fff
classDef green fill:#16a34a,stroke:#166534,color:#fffOffline-First and Local-First
The local database is the source of truth. The UI reads and writes locally and syncs with the server in the background. Service workers and IndexedDB power offline PWAs, and CRDTs enable conflict-free multi-device editing.
flowchart LR
UI["UI"]:::blue <--> DB[("Local DB<br/>IndexedDB / SQLite")]:::green
DB <-->|background sync| SY["Sync engine<br/>queue / CRDT"]:::purple
SY <--> SRV["Server"]:::orange
classDef blue fill:#2563eb,stroke:#1e40af,color:#fff
classDef green fill:#16a34a,stroke:#166534,color:#fff
classDef purple fill:#9333ea,stroke:#6b21a8,color:#fff
classDef orange fill:#ea580c,stroke:#9a3412,color:#fffUse it for editors, note apps, and field tools that must work with bad connectivity.
5. How to Choose
Start with rendering, since it shapes the rest of your stack.
flowchart TD
Q1{"Behind login,<br/>no SEO needed?"}:::yellow
Q1 -->|Yes| SPA["SPA / CSR"]:::pink
Q1 -->|No| Q2{"Content mostly static?"}:::yellow
Q2 -->|Yes| Q3{"Changes often?"}:::yellow
Q3 -->|No| SSG["SSG + islands"]:::green
Q3 -->|Yes| ISR["ISR"]:::teal
Q2 -->|No| SSR["SSR or MPA<br/>streaming, RSC"]:::blue
classDef yellow fill:#facc15,stroke:#a16207,color:#111
classDef pink fill:#db2777,stroke:#9d174d,color:#fff
classDef green fill:#16a34a,stroke:#166534,color:#fff
classDef teal fill:#0d9488,stroke:#115e59,color:#fff
classDef blue fill:#2563eb,stroke:#1e40af,color:#fffRules of thumb:
Pick the simplest rendering model that meets your SEO and performance needs.
Organize by feature before reaching for layered or clean architecture.
Separate server state from client state early.
Reach for micro-frontends only when organizational problems, not technical ones, demand it.
Every pattern here trades simplicity for something else. Adopt one when you can name the specific pain it removes.
Comments(0)
Join the discussion by logging into your account.
No comments yet. Be the first to comment!