[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -2,109 +2,186 @@
|
||||
id: wiki-2026-0508-웹-애플리케이션의-3계층-구조
|
||||
title: 웹 애플리케이션의 3계층 구조
|
||||
category: 10_Wiki/Topics
|
||||
status: needs_review
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [P-Reinforce-AUTO-073A5E]
|
||||
aliases: [3-Tier Architecture, Three-Tier Web App, Presentation-Logic-Data]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
tags: [auto-reinforced]
|
||||
verification_status: applied
|
||||
tags: [architecture, 3-tier, web, layered]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-04-20
|
||||
github_commit: "[P-Reinforce] Continuous Worker - 웹 애플리케이션의 3계층 구조"
|
||||
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: unspecified
|
||||
framework: unspecified
|
||||
language: typescript
|
||||
framework: nextjs
|
||||
---
|
||||
|
||||
# [[웹 애플리케이션의 3계층 구조|웹 애플리케이션의 3계층 구조]]
|
||||
# 웹 애플리케이션의 3계층 구조
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
> 웹 애플리케이션의 3계층 구조(3-Tier [[Architecture|Architecture]])는 관심사의 분리(SoC) 원칙에 따라 시스템을 수평적인 층으로 나누어 각각 특정 책임을 부여하는 전통적이고 영향력 있는 소프트웨어 아키텍처 패턴입니다 [1, 2]. 이 구조는 애플리케이션을 사용자 인터페이스를 담당하는 프레젠테이션 계층, 핵심 비즈니스 규칙을 처리하는 비즈니스 로직 계층, 데이터베이스 통신을 관리하는 데이터 액세스 계층으로 엄격히 분리합니다 [2, 3]. 이러한 분리를 통해 개발자는 한 계층의 변경 사항이 다른 계층에 미치는 영향을 최소화하면서 시스템을 보다 모듈화하고 테스트 및 유지보수하기 쉽게 만들 수 있습니다 [1, 4].
|
||||
## 매 한 줄
|
||||
> **"매 presentation / logic / data 의 separation"**. 매 1990 년대 client-server 의 evolution — 매 thick client 의 limit 의 escape. 2026 년 매 SPA + BFF + DB 의 form, 또는 SSR (Next.js) 의 collapsed form 의 dominant.
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
웹 애플리케이션을 구성하는 3계층의 구체적인 역할과 성공적인 구축을 위한 구현 원칙은 다음과 같습니다 [2, 3, 5, 6].
|
||||
## 매 핵심
|
||||
|
||||
* **프레젠테이션 계층 (Presentation Layer):**
|
||||
* 시스템의 최상단에 위치하며, 사용자 인터페이스(UI)와 렌더링, 사용자 경험(UX)과 관련된 모든 로직을 처리합니다 [2, 3].
|
||||
* 사용자에게 데이터를 표시하고 입력을 캡처하는 역할을 수행하며, 주로 HTML, CSS 및 [[JavaScript|JavaScript]] 프레임워크로 구성됩니다 [2, 3].
|
||||
* 이 계층의 구조용 마크업 및 시각적 표현 로직은 데이터 조작이나 비즈니스 규칙과 엄격히 분리되어야 합니다 [6].
|
||||
### 매 3 layers
|
||||
- **Presentation (UI)**: 매 user-facing rendering — browser, mobile app.
|
||||
- **Application/Logic (BLL)**: 매 business rule + orchestration — API server.
|
||||
- **Data (DAL)**: 매 persistence — RDBMS, NoSQL, cache.
|
||||
|
||||
* **비즈니스 로직 계층 ([[business|business]] [[Logic|Logic]] Layer / Domain Layer):**
|
||||
* 애플리케이션의 작동 방식을 정의하는 핵심 비즈니스 규칙, 로직 및 워크플로우를 포함하는 중심 계층입니다 [3, 6].
|
||||
* 프레젠테이션 계층으로부터 들어온 명령을 처리하고, 데이터 액세스 계층과의 작업을 오케스트레이션합니다 [3].
|
||||
* 주로 Node.js, Django, Spring과 같은 서버 사이드 스크립트나 백엔드 서비스를 통해 구현되며, 프레젠테이션 계층 및 하위 인프라와는 독립적으로 존재해야 합니다 [2, 6].
|
||||
### 매 communication
|
||||
- **Client → API**: HTTPS REST / GraphQL / gRPC-Web.
|
||||
- **API → DB**: 매 connection pool — TCP.
|
||||
- **Layer rule**: 매 adjacent layer only — UI 의 DB 직접 access 의 X.
|
||||
|
||||
* **데이터 액세스 계층 (Data Access Layer / Persistence Layer):**
|
||||
* 시스템의 최하단에 위치하며, 데이터베이스와 같은 데이터 소스와의 모든 통신 및 CRUD(생성, 읽기, 업데이트, 삭제) 작업을 전담합니다 [2, 3].
|
||||
* 비즈니스 로직을 데이터 스토리지의 세부 구현 사항으로부터 격리하는 역할을 합니다 [3].
|
||||
* 일반적으로 ORM(객체 관계 매핑) 프레임워크 등을 사용하여 저수준의 데이터베이스 상호 작용을 추상화합니다 [6].
|
||||
### 매 응용
|
||||
1. Traditional LAMP/MEAN — 매 separated tier.
|
||||
2. Next.js SSR — 매 server component 가 logic + data 의 collapse.
|
||||
3. Mobile app + REST API + Postgres — 매 classic 3-tier.
|
||||
|
||||
* **구현을 위한 모범 사례 (Actionable Tips):**
|
||||
* **엄격한 계층 간 통신 제어:** 각 계층은 바로 아래에 있는 계층과만 통신해야 합니다. 예를 들어 프레젠테이션 계층이 데이터 액세스 계층을 직접 호출하지 않게 하여 시스템의 결합도를 낮춰야 합니다 [5].
|
||||
* **의존성 주입 (Dependency Injection, DI) 활용:** 상위 계층이 하위 계층의 인스턴스를 직접 생성하지 않고 외부에서 의존성을 주입받도록 구현하여, 느슨한 결합을 촉진하고 테스트 가능성을 향상시켜야 합니다 [5].
|
||||
* **명확한 인터페이스 정의:** 각 계층 간에 명확히 정의된 인터페이스를 생성해야 합니다. 이를 통해 데이터베이스를 변경하더라도 상위 계층의 로직에 영향을 주지 않고 새로운 구현체로 교체할 수 있습니다 [5].
|
||||
## 💻 패턴
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
- **과거 데이터와의 충돌:** 자동화 엔진에 의해 매핑된 지식으로, 추후 정밀 검증 필요.
|
||||
- **정책 변화:** Programming & Language 분야의 자동 자산화 수행.
|
||||
### Next.js 15 server component (collapsed 3-tier)
|
||||
```tsx
|
||||
// app/users/page.tsx — server component
|
||||
import { db } from '@/lib/db'; // DAL
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
- **Related Topics:** [[관심사의 분리 (Separation of Concerns)|관심사의 분리 (Separation of Concerns]], 의존성 주입 (Dependency Injection), MVC (Model-View-Controller), [[클린 아키텍처 (Clean Architecture)|클린 아키텍처 (Clean Architecture]]
|
||||
- **Projects/Contexts:** [[현대 웹 애플리케이션 설계|현대 웹 애플리케이션 설계]], [[엔터프라이즈 소프트웨어 개발|엔터프라이즈 소프트웨어 개발]]
|
||||
- **Contradictions/Notes:** 3계층 구조와 같은 계층화 아키텍처는 명확한 분리를 통해 유지보수성과 확장성을 높여주지만, 초기 개발 시 계층과 추상화를 정의하고 구현해야 하므로 개발 시간이 증가할 수 있으며, 자칫 과도한 엔지니어링(Over-Engineering)으로 인해 시스템 구조가 불필요하게 비대해질 위험도 존재합니다 [7].
|
||||
async function getUsers() { // BLL
|
||||
return db.user.findMany({ where: { active: true } });
|
||||
}
|
||||
|
||||
---
|
||||
*Last updated: 2026-04-18*
|
||||
|
||||
---
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(TODO)*
|
||||
|
||||
## 🧪 검증 상태 (Validation)
|
||||
|
||||
- **정보 상태:** needs_review
|
||||
- **출처 신뢰도:** A
|
||||
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
|
||||
|
||||
## 🧬 중복 검사 (Duplicate Check)
|
||||
|
||||
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
|
||||
- **처리 방식:** UPDATE (자동 정규화)
|
||||
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
|
||||
|
||||
## 🕓 변경 이력 (Changelog)
|
||||
|
||||
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|
||||
|------|-----------|-----------|--------|
|
||||
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
|
||||
|
||||
## 💻 코드 패턴 (Code Patterns)
|
||||
|
||||
**패턴 1:** *(TODO: 이 프로젝트 컨벤션 반영한 구조 스켈레톤)*
|
||||
|
||||
```text
|
||||
# TODO
|
||||
export default async function UsersPage() { // Presentation
|
||||
const users = await getUsers();
|
||||
return (
|
||||
<ul>
|
||||
{users.map((u) => <li key={u.id}>{u.name}</li>)}
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
## 🤔 의사결정 기준 (Decision Criteria)
|
||||
### Classic separated tier (REST)
|
||||
```typescript
|
||||
// Tier 1: React SPA
|
||||
const res = await fetch('/api/users');
|
||||
const users = await res.json();
|
||||
|
||||
**선택 A를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
// Tier 2: Express API (Node.js)
|
||||
app.get('/api/users', async (req, res) => {
|
||||
const users = await userService.listActive(); // BLL
|
||||
res.json(users);
|
||||
});
|
||||
|
||||
**선택 B를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
// Tier 3: Repository (Postgres)
|
||||
class UserRepository {
|
||||
async listActive() {
|
||||
return pool.query('SELECT * FROM users WHERE active = true');
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**기본값:**
|
||||
> *(TODO)*
|
||||
### BFF (Backend for Frontend)
|
||||
```typescript
|
||||
// 매 mobile + web 의 다른 BFF — 매 tier 2 의 split.
|
||||
// /api/web/dashboard — web-tailored aggregate
|
||||
app.get('/api/web/dashboard', async (req, res) => {
|
||||
const [user, stats, notifs] = await Promise.all([
|
||||
userSvc.get(req.userId),
|
||||
statsSvc.summary(req.userId),
|
||||
notifSvc.unread(req.userId),
|
||||
]);
|
||||
res.json({ user, stats, notifs });
|
||||
});
|
||||
```
|
||||
|
||||
## ❌ 안티패턴 (Anti-Patterns)
|
||||
### Repository pattern (DAL boundary)
|
||||
```typescript
|
||||
interface UserRepository {
|
||||
findById(id: string): Promise<User | null>;
|
||||
save(user: User): Promise<void>;
|
||||
}
|
||||
|
||||
- **[안티패턴]:** *(TODO: 무엇을 하면 안 되는가 + 이유 + 대신 무엇을)*
|
||||
class PostgresUserRepository implements UserRepository {
|
||||
constructor(private pool: Pool) {}
|
||||
async findById(id: string) {
|
||||
const { rows } = await this.pool.query(
|
||||
'SELECT * FROM users WHERE id = $1', [id]
|
||||
);
|
||||
return rows[0] ?? null;
|
||||
}
|
||||
async save(user: User) {
|
||||
await this.pool.query('INSERT INTO users ... ON CONFLICT ...');
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Service layer (BLL)
|
||||
```typescript
|
||||
class OrderService {
|
||||
constructor(
|
||||
private orders: OrderRepository,
|
||||
private inventory: InventoryService,
|
||||
private payments: PaymentService,
|
||||
) {}
|
||||
|
||||
async place(userId: string, items: CartItem[]): Promise<Order> {
|
||||
await this.inventory.reserve(items);
|
||||
const charge = await this.payments.charge(userId, total(items));
|
||||
const order = await this.orders.create({ userId, items, chargeId: charge.id });
|
||||
return order;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Cache layer (between BLL and DAL)
|
||||
```typescript
|
||||
class CachedUserRepo implements UserRepository {
|
||||
constructor(private inner: UserRepository, private redis: Redis) {}
|
||||
|
||||
async findById(id: string) {
|
||||
const cached = await this.redis.get(`user:${id}`);
|
||||
if (cached) return JSON.parse(cached);
|
||||
const user = await this.inner.findById(id);
|
||||
if (user) await this.redis.setex(`user:${id}`, 300, JSON.stringify(user));
|
||||
return user;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Architecture |
|
||||
|---|---|
|
||||
| Simple CRUD app | Next.js full-stack (collapsed) |
|
||||
| Mobile + web + admin | BFF per client |
|
||||
| Microservices | API gateway + service mesh |
|
||||
| Monolithic enterprise | Strict 3-tier with DI |
|
||||
| Real-time | Add WebSocket/SSE tier |
|
||||
|
||||
**기본값**: 매 Next.js server components 의 simplest path.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Layered Architecture]] · [[Client-Server]]
|
||||
- 변형: [[N-Tier]] · [[BFF]] · [[Microservices]]
|
||||
- 응용: [[LAMP Stack]] · [[MEAN Stack]] · [[JAMstack]]
|
||||
- Adjacent: [[Repository Pattern]] · [[Service Layer]] · [[MVC]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: web app 의 layer separation 의 design 의 결정 시.
|
||||
**언제 X**: real-time game, embedded system — 매 different model.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Smart UI**: 매 SQL 의 frontend — 매 layer 의 violate.
|
||||
- **Anemic service**: 매 service 의 pass-through 의 only — 매 logic 의 controller.
|
||||
- **Chatty DAL**: 매 N+1 query — 매 batch 의 X.
|
||||
- **Leaky DB schema**: 매 ORM entity 의 API 의 expose — 매 DTO 의 separate.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Fowler *PoEAA*; Microsoft *Application Architecture Guide*; Next.js docs 2026).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — 3-tier + BFF + repository patterns |
|
||||
|
||||
Reference in New Issue
Block a user