Server-Client Architecture & Design Review
Server and Client Components are most useful when they clarify ownership.
A strong design answers:
Where does this data live?
Where is trust established?
Which code needs the browser?
Which code should never reach the browser?
Which state is local, shared, URL-driven, or server-owned?
What must hydrate?
What can remain server-rendered?
This chapter closes Phase 4 by turning individual rules into an architecture method.
Start from capabilitiesβ
For each component, classify its needs.
Server capabilitiesβ
database access
private credentials
request/session data
server filesystem/services
server-side authorization
large non-interactive rendering
Client capabilitiesβ
event handlers
stateful interaction
effects
browser APIs
client router hooks
DOM measurement
client subscriptions
Then place the boundary where the capability changes.
Pattern 1: Server shell + interactive islandsβ
Server Product Page
βββ Server Header
βββ Server Product Details
βββ Server Reviews
βββ Client QuantityPicker
βββ Client AddToCart
βββ Server Recommendations
Use when most UI is content/data and only small pieces are interactive.
Benefits:
- smaller client graph
- server data access stays direct
- less hydration
- clear ownership
Trade-off:
- client islands need explicit props/contracts
Pattern 2: Client shell with server content slotsβ
Server Page creates
<Client Modal>
<Server Cart />
</Client Modal>
Use when the outer interaction is client-owned but inner content is server-rendered.
Examples:
- modal shell
- tabs with server-rendered panels
- resizable client layout around server content
- disclosure/accordion shell around server-rendered body
Pattern 3: Server-started data + client consumptionβ
Server layout starts Promise
β
Client provider receives Promise
β
client component calls use()
Use when:
- data should start on the server early
- multiple client consumers need it
- Suspense is part of the UX
Do not use it merely to avoid passing normal props.
Pattern 4: Feature-scoped providersβ
Server Root Layout
βββ global theme client provider
βββ Server Dashboard Layout
βββ dashboard client provider
βββ filters
βββ selection inspector
Keep client state scoped to the feature that owns it.
Avoid a single global provider tree containing unrelated feature state.
Pattern 5: Server facade over privileged integrationsβ
Client Component
β mutation/API request
trusted server boundary
β
server-only integration module
β
private provider/database
The browser never receives privileged credentials.
The server facade owns validation, authorization, and integration details.
Pattern 6: Browser-only adapterβ
Server Page
βββ Client MapShell
βββ lazy browser map library
Use when a package fundamentally needs DOM/browser execution.
Keep the browser-only adapter narrow and keep unrelated route content server-side.
Decision treeβ
Does this component need state/events/effects/browser APIs?
β
βββ no β keep it Server Component by default
β
βββ yes
β
βββ can only a child own that interaction?
β βββ yes β move 'use client' to child
β βββ no β make cohesive interactive boundary
β
βββ does it import browser-only/heavy libraries?
βββ yes β isolate/lazy-load where useful
βββ no β normal Client Component
Then separately ask:
Does this code need secrets/database/private services?
βββ yes β server-only module
βββ no β shared/client depending on capabilities
Data decision treeβ
Who needs the data?
β
βββ only Server Components
β β keep data server-side
β
βββ one Client Component
β β pass minimal serializable props
β
βββ many Client Components
β β consider feature-scoped provider
β
βββ browser needs live/revalidated state
β define client data strategy explicitly
Later phases cover fetching/caching choices in depth.
State taxonomyβ
Do not put all state into Client Context.
Classify it:
Server stateβ
user record
project permissions
catalogue data
billing state
URL stateβ
filters
pagination
selected tab when shareable
search query
Client local stateβ
modal open
input draft
hover state
expanded row
Client shared stateβ
dashboard selection
editor session UI
multi-panel coordination
Choose the owner before choosing the library.
Architecture smell: root-level 'use client'β
Root layouts often contain:
- fonts
- metadata shell
- navigation
- providers
- static structure
If one provider forces the entire file to become a Client Component, use a wrapper instead.
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html>
<body>
<AppProviders>{children}</AppProviders>
</body>
</html>
)
}
Keep the document/layout server-owned unless client capability genuinely belongs there.
Architecture smell: client fetch after server renderβ
Server page renders shell
β
Client component mounts
β
fetches data required for first meaningful content
If the server could have fetched that data directly, you may have created an unnecessary client waterfall.
There are valid client-fetching cases, but they should be intentional.
Architecture smell: enormous serialized recordβ
<ClientDashboard organisation={organisationWithEverything} />
This creates:
- larger transport
- accidental sensitive exposure
- tight client/server coupling
- harder schema evolution
Create explicit public models.
Architecture smell: shared barrel with mixed runtimesβ
@/lib
βββ db
βββ cookies
βββ local-storage
βββ formatting
βββ analytics-browser
One index.ts exports all of them.
Split server/client/shared entry points.
Architecture smell: auth lives in Client Contextβ
If the server trusts:
authContext.role
or data derived from browser state for authorization, the trust model is wrong.
Client state can reflect permissions for UX; server code decides permissions for operations/data access.
Architecture smell: ssr: false everywhereβ
A migration team may disable SSR for components until the app βworks.β
That often recreates a client SPA inside Next.js and hides boundary bugs.
Use client-only rendering only for components that truly cannot prerender.
Large application folder strategyβ
Example:
src/
βββ app/
β βββ dashboard/
βββ features/
β βββ projects/
β β βββ server/
β β βββ client/
β β βββ components/
β β βββ types.ts
β βββ billing/
βββ lib/
β βββ server/
β βββ client/
β βββ shared/
βββ components/
Do not copy the exact folders mechanically.
The principle is visible runtime ownership.
Code review questionsβ
For a new Client Component:
- What capability requires
'use client'? - Can the boundary move lower?
- Which dependencies enter the client graph?
- What data crosses from server?
- Is any field sensitive/unnecessary?
- Does this subtree need context?
- Does the server still authorize operations?
- Is initial render deterministic?
- Does the feature need lazy loading?
- Did bundle size change?
For a Server Component:
- Does it directly access trusted server resources?
- Is authorization enforced before sensitive reads?
- Is server work parallelised/cached appropriately later?
- Is it calling an internal Route Handler unnecessarily?
- Does it pass only minimal data to client children?
- Are sensitive modules marked server-only?
Migration from client-heavy Reactβ
A safe migration approach:
1. Keep existing interactive feature working.
2. Move route/page shell to Server Component.
3. Identify server-owned reads.
4. Move data reads server-side.
5. Keep existing interaction subtree client-side.
6. Split client boundary lower over time.
7. Introduce server-only modules.
8. Measure JS/hydration changes.
Do not attempt to rewrite every stateful component at once.
Team conventionsβ
Useful conventions might include:
- Server Components by default.
'use client'requires a documented browser/interactivity reason.- privileged modules import
server-only. - browser adapters import
client-only. - no mixed server/client barrel exports.
- database records are mapped to public client DTOs.
- providers are feature-scoped where possible.
- permission checks live at server trust boundaries.
- production build is mandatory in CI.
Production failure scenarioβ
Symptom: A deployment fails after a designer imports a formatting helper into a Client Component.
Root cause:
formatting helper barrel
β re-exports db helper
β db helper imports server-only
Fix:
shared/formatting
server/db
The build failure exposed an unhealthy package boundary.
Senior interview scenarioβ
Scenario: The team says βServer Components are faster, so we should eliminate all Client Components.β
A strong response:
- Server Components reduce browser JS for server-owned UI.
- Client Components are required for browser interactivity/state/effects.
- Server execution can still be slow due to I/O and compute.
- The goal is correct ownership, not maximum server percentage.
- Measure server latency, payload, client JS, hydration, and interaction together.
Senior interview scenario: global providerβ
Scenario: A SaaS app has one global provider containing current user, organisation, feature flags, open modal, selected rows, filters, and editor state.
A strong redesign separates:
server identity/permissions
URL filters
feature-scoped selection state
local modal state
editor-specific provider
minimal client user presentation data
This improves trust boundaries, history behavior, rerender scope, and ownership.
Milestone project: Server-first SaaS dashboardβ
Build:
/dashboard
βββ server layout
βββ server user/organisation authorization
βββ server KPI cards
βββ server recent activity
βββ client date-range filter using URL state
βββ client chart wrapper
βββ dashboard-only selection provider
βββ server-rendered detail panel passed into a client modal shell
Requirements:
Boundariesβ
- no root-level
'use client' - every client boundary has a documented reason
- no server database module enters client graph
Dataβ
- server reads do not make internal HTTP hops unnecessarily
- public DTOs cross to client
- sensitive fields stay server-side
Securityβ
- route params/query input validated
- organisation membership checked server-side
- client context not trusted for permissions
Performanceβ
- heavy chart library lazy-loaded if measurements justify it
- client JS before/after recorded
- server render/data timings recorded
Reliabilityβ
- full reload works
- client navigation works
- hydration produces no warnings
- CI production build passes
Phase 4 completion questionsβ
You should now be able to answer:
- Why are App Router pages Server Components by default?
- What exactly does
'use client'declare? - Why can a Client Component still be prerendered to HTML?
- How can server-rendered children appear inside a Client Component?
- What values may cross the boundary?
- Why are DTOs a security tool?
- Where should context providers live?
- How do
server-onlyandclient-onlyprevent environment mistakes? - How do you isolate a DOM-dependent third-party package?
- How do you measure whether a boundary is good?
If those answers are clear, the next phaseβData Fetchingβhas the right foundation.