Files
2nd/10_Wiki/Topics/AI_and_ML/Modern Scalable Frontend Architecture.md
T
Antigravity Agent f8b21af4be Wiki cleanup: error-doc removal, dedup merge, link normalization
10_Wiki/Topics 대규모 정리:
- 오류 캡처/미완성 stub 문서 227개 제거
- 교차폴더 중복 43클러스터 병합 (63파일 → redirect)
- 링크명 정규화: 깨진 링크 수정·redirect 직결·개념 매핑 ~2,400건
- 카테고리 MOC 6개 신규 생성
- Graph 섹션 미해결 related-keyword 링크 10,058건 제거

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 23:52:15 +09:00

230 lines
6.8 KiB
Markdown

---
id: wiki-2026-0508-modern-scalable-frontend-archite
title: Modern Scalable Frontend Architecture
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [Frontend Architecture, Micro-frontends, RSC, Edge SSR, Islands]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
verification_status: applied
tags: [frontend, architecture, micro-frontend, rsc, monorepo, edge]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack: { language: typescript, framework: next-js }
---
# Modern Scalable Frontend Architecture
## 매 한 줄
2026년 확장형 프론트엔드는 **monorepo + RSC + edge SSR + islands** 의 4축으로 정리되며, 거대 조직은 micro-frontend, 콘텐츠 사이트는 islands, 풀 앱은 RSC가 default다.
## 매 핵심
### 1. Monorepo (코드 공유 단위)
- **도구**: Turborepo, Nx, pnpm workspaces.
- **구조**: `apps/` (배포 단위) + `packages/` (공유 라이브러리).
- 핵심 가치: type-safe cross-package import, 단일 PR로 다중 앱 변경, 캐시된 빌드.
### 2. Micro-frontends (배포 분리)
- **Module Federation** (webpack/Vite): runtime 동적 로드.
- **Single-SPA / Piral**: 라우팅 단위 통합.
- **iframe + postMessage**: 강한 격리 (legacy 통합).
- 적용: 100+ 개발자, 다중 팀, 다른 release cadence.
- 트레이드오프: 번들 중복, 상태 공유 어려움 — 작은 조직에는 over-engineering.
### 3. RSC (React Server Components, Next.js 14+)
- 서버에서 렌더링 → 직렬화 → 클라이언트 hydration 없이 렌더.
- DB·secret 직접 접근, JS 번들 0 (server-only 컴포넌트).
- `"use client"` 경계로 클라이언트 컴포넌트 분리.
- 2026 표준: Next.js App Router, Remix v2 (React Router 7).
### 4. Edge SSR
- Cloudflare Workers, Vercel Edge, Netlify Edge.
- TTFB 50ms- (지리적으로 사용자 근처).
- 제약: Node API 일부 미지원, V8 isolate 메모리 제한, cold start 거의 0.
### 5. Islands Architecture
- **Astro, Qwik, Fresh** — 정적 HTML + 선택적 hydration.
- "interactive island"만 JS 로드 → JS 50-90% 감소.
- 콘텐츠/마케팅/블로그/EC 카탈로그에 최적.
### 6. State / Data Layer
- **Server state**: TanStack Query, RSC fetch.
- **Client state**: Zustand, Jotai (Redux는 거의 사라짐).
- **Form**: react-hook-form + zod.
- **Real-time**: Liveblocks, Convex, Supabase realtime.
### 7. 2026 Trend
- **Server actions** (Next.js): RPC 보일러플레이트 제거.
- **Partial Prerendering** (PPR): 정적 + 동적 hybrid.
- **Streaming SSR + Suspense**: TTFB ↓, 인지속도 ↑.
- **TypeScript 5.5+ inferred types**: tRPC, Zod, Drizzle e2e type safety.
- **AI agent UI**: streaming token UI, generative UI (RSC + structured output).
## 💻 패턴
```ts
// 1. Turborepo turbo.json
{
"tasks": {
"build": { "dependsOn": ["^build"], "outputs": [".next/**", "dist/**"] },
"test": { "dependsOn": ["^build"] },
"lint": {},
"dev": { "cache": false, "persistent": true }
}
}
```
```tsx
// 2. RSC — server component (Next.js App Router)
// app/products/page.tsx
import { db } from "@/lib/db";
export default async function Page() {
const products = await db.product.findMany(); // server-only
return <ProductList products={products} />;
}
```
```tsx
// 3. Client component boundary
"use client";
import { useState } from "react";
export function AddToCart({ id }: { id: string }) {
const [pending, setPending] = useState(false);
return <button disabled={pending}>Add</button>;
}
```
```ts
// 4. Module Federation (Vite plugin)
import federation from "@originjs/vite-plugin-federation";
export default {
plugins: [federation({
name: "shell",
remotes: { checkout: "https://checkout.app/assets/remoteEntry.js" },
shared: ["react", "react-dom"],
})],
};
```
```tsx
// 5. Astro island
---
import Counter from "../components/Counter.tsx";
---
<html>
<body>
<h1>Static content (no JS)</h1>
<Counter client:visible /> <!-- hydrate when in viewport -->
</body>
</html>
```
```ts
// 6. Server action (Next.js)
"use server";
import { z } from "zod";
const Schema = z.object({ email: z.string().email() });
export async function subscribe(formData: FormData) {
const { email } = Schema.parse(Object.fromEntries(formData));
await db.newsletter.create({ data: { email } });
}
```
```ts
// 7. Edge runtime
export const runtime = "edge";
export async function GET(req: Request) {
const geo = req.headers.get("x-vercel-ip-country");
return Response.json({ country: geo });
}
```
```tsx
// 8. Streaming SSR with Suspense
import { Suspense } from "react";
export default function Page() {
return (
<>
<Header />
<Suspense fallback={<Skeleton />}>
<SlowFeed />
</Suspense>
</>
);
}
```
```ts
// 9. TanStack Query — client cache
import { useQuery } from "@tanstack/react-query";
const { data } = useQuery({
queryKey: ["user", id],
queryFn: () => fetch(`/api/user/${id}`).then(r => r.json()),
staleTime: 60_000,
});
```
```ts
// 10. End-to-end type safety with tRPC
// server
export const appRouter = t.router({
user: t.procedure.input(z.string()).query(({ input }) => db.user.find(input)),
});
// client
const user = await trpc.user.query("123"); // 자동 타입
```
## 매 결정 기준
| 상황 | 권장 아키텍처 |
|------|--------------|
| 마케팅/블로그/EC 카탈로그 | **Islands** (Astro) |
| SaaS 풀 앱 (단일팀-중규모) | **Next.js RSC + Server Actions** |
| 대조직 다팀 다배포 | **Module Federation micro-frontend** |
| 글로벌 저지연 | **Edge SSR** (Vercel/Cloudflare) |
| 실시간 협업 | **Convex / Liveblocks** + RSC |
| 정적 + 동적 혼합 | **PPR (Partial Prerendering)** |
| 모바일 우선 PWA | **Vite + Workbox** |
## 🔗 Graph
- 부모: [[Large_Frontend_Projects|Frontend Architecture]], [[Web Performance]]
- 변형: [[Micro-Frontends]], [[Islands Architecture]], [[React Server Components]]
- 응용: [[Astro]], [[Qwik]], [[Edge Runtime]]
- Adjacent: [[Monorepo]], [[Turborepo]], [[Module Federation]]
## 🤖 LLM 활용
- v0.dev / Bolt.new — RSC + shadcn 코드 생성.
- "이 SPA를 RSC로 마이그레이션하는 단계별 계획" — 점진적 변환.
- LLM이 component boundary (`"use client"`) 자동 추론.
## ❌ 안티패턴
- **소규모 팀의 micro-frontend**: 운영 비용 >> 이익.
- **RSC 안에서 useState/useEffect**: 컴파일 에러 — boundary 누락.
- **Edge에서 무거운 Node API 사용**: 런타임 실패.
- **모든 컴포넌트 client**: RSC 이점 무화.
- **큰 모놀리식 SPA + 무한 스크롤**: TTI > 5s — islands/SSR로.
## 🧪 검증 / 중복
- 검증: Next.js / Astro / Vercel docs, web.dev Core Web Vitals.
- 중복: [[Next.js App Router]] (specific) — 본 문서는 architectural overview.
## 🕓 Changelog
- 2026-05-10: 신규 작성. Monorepo + RSC + Edge SSR + Islands 4축 + 2026 trend.