[G1-Sync] Manual knowledge update

This commit is contained in:
Antigravity Agent
2026-05-10 22:08:15 +09:00
parent 21ac3ed255
commit 504fd5fb42
3011 changed files with 380280 additions and 206977 deletions
@@ -1,101 +1,226 @@
---
id: wiki-2026-0508-mvc-model-view-controller
title: MVC (Model View Controller)
title: MVC (Model-View-Controller)
category: 10_Wiki/Topics
status: needs_review
status: verified
canonical_id: self
aliases: [P-Reinforce-AUTO-F8BE8B]
aliases: [MVC, Model-View-Controller Pattern]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
tags: [auto-reinforced]
verification_status: applied
tags: [architecture-pattern, ui-architecture, separation-of-concerns]
raw_sources: []
last_reinforced: 2026-04-20
github_commit: "[P-Reinforce] Continuous Worker - MVC (Model-View-Controller)"
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: rails
---
# [[MVC (Model-View-Controller)|MVC (Model-View-Controller]]
# MVC (Model-View-Controller)
## 📌 한 줄 통찰 (The Karpathy Summary)
> MVC(Model-View-Controller)는 애플리케이션을 모델(Model), 뷰(View), 컨트롤러(Controller)라는 세 가지 상호 연결된 구성 요소로 분리하는 고전적인 소프트웨어 아키텍처 패턴이다 [1]. 이 패턴은 각 구성 요소에 명확한 책임을 부여하여 시스템의 복잡성을 줄이는 '관심사의 분리([[_뇌와 팔다리의 분리_ - 관심사의 분리 (Separation of Concerns)|Separation of Concerns]])' 원칙의 대표적인 예시이다 [2, 3]. 역할 간의 명확한 경계를 설정함으로써 개발자는 데이터 로직에 영향을 주지 않고 사용자 인터페이스를 독립적으로 수정할 수 있어 시스템의 유연성과 유지보수성을 크게 향상시킬 수 있다 [2, 3].
## 한 줄
> **"매 UI architecture 의 1979 ancestor"**. Trygve Reenskaug 의 Smalltalk-80 — Model (data/logic), View (presentation), Controller (input mediation) 의 separation of concerns. 2026 에서 pure MVC 는 server-side framework (Rails, Django, Laravel, ASP.NET) 의 mainstay 이지만 frontend 는 매 MVVM (Vue), Flux/Redux (React), Component-driven (Svelte/Solid) 으로 evolve.
## 📖 구조화된 지식 (Synthesized Content)
- **구성 요소별 명확한 책임 분리:**
- **모델 (Model):** 애플리케이션의 데이터와 비즈니스 로직을 관리한다 [1-3]. 클린 아키텍처(Clean [[Architecture|Architecture]])의 관점에서는 데이터 구조 정도의 역할을 하며, 컨트롤러에서 유스케이스로 전달된 후 다시 프레젠터와 뷰로 되돌아가는 형태로 사용되기도 한다 [4].
- **뷰 (View):** 사용자 인터페이스(UI)를 관리하고 데이터를 시각적으로 표시하는 프레젠테이션 역할을 전담한다 [1-3].
- **컨트롤러 (Controller):** 사용자의 입력을 받아 처리하며, 모델과 뷰 사이에서 중재자(Intermediary) 역할을 수행하고 이들 간의 상호작용을 조정한다 [1-3].
## 매 핵심
- **엄격한 상호작용 규칙:**
- MVC 패턴을 비롯한 아키텍처 전략의 핵심은 뷰(View)가 모델(Model)과 직접 상호작용하는 것을 허용하지 않는다는 점이다 [3, 5].
- 뷰는 반드시 컨트롤러(Controller)를 매개체로 통해서만 모델과 상호작용해야 하며, 이러한 통제는 구성 요소 간의 불필요한 의존성을 줄여준다 [3, 5].
### 매 3 components
- **Model**: domain data + business logic. Persistence, validation, invariants.
- **View**: rendering. 매 read-only view 의 model state.
- **Controller**: user input 의 handler. Model mutation + view selection.
- **관심사 분리(SoC)를 통한 시스템 이점:**
- MVC는 관심사의 분리(SoC) 원칙을 시스템 설계 수준에서 실현하여, 시스템의 복잡성을 줄이고 각 구성 요소가 단일 책임에 집중하도록 유도한다 [3].
- 이러한 분리를 통해 모듈화가 향상되며, UI 요소를 수정하더라도 기저의 데이터 처리 로직에 영향을 미치지 않는다 [2]. 결과적으로 변경이 다른 부분으로 파급되는 것을 막아 유지보수가 용이해지고, 개별 구성 요소를 유연하게 교체하거나 확장할 수 있다 [2, 3, 6].
### 매 information flow (classic Smalltalk)
1. User → Controller (input event).
2. Controller → Model (update).
3. Model → View (notify, observer pattern).
4. View → renders updated state.
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
- **과거 데이터와의 충돌:** 자동화 엔진에 의해 매핑된 지식으로, 추후 정밀 검증 필요.
- **정책 변화:** Programming & Language 분야의 자동 자산화 수행.
### 매 modern variants
- **MVP** (Model-View-Presenter): View 의 passivity 강화, presenter 가 view 를 directly drive.
- **MVVM** (Model-View-ViewModel): ViewModel 의 binding 으로 View 의 declarative connect (Vue, Knockout, WPF).
- **Flux/Redux**: unidirectional flow — Action → Store → View.
- **Component-driven**: 매 unit 이 self-contained (React, Svelte) — MVC boundary 의 dissolve.
## 🔗 지식 연결 (Graph)
- **Related Topics:** Separation of Concerns (SoC), Software Architecture, Clean Architecture
- **Projects/Contexts:** Web Applications, GUI Development
- **Contradictions/Notes:** 소스에 관련 정보가 부족합니다.
### 매 응용
1. Server-side web frameworks (Rails, Django, Laravel, Spring MVC).
2. Native UI (UIKit MVC pattern, Android Activity-based).
3. Game engine UI layer.
4. Form-heavy admin dashboard.
---
*Last updated: 2026-04-18*
## 💻 패턴
---
### 1. Rails MVC (canonical server-side)
```ruby
# app/models/article.rb
class Article < ApplicationRecord
validates :title, presence: true
scope :published, -> { where(published: true) }
end
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
# app/controllers/articles_controller.rb
class ArticlesController < ApplicationController
def index
@articles = Article.published.order(created_at: :desc)
end
**언제 이 지식을 쓰는가:**
- *(TODO)*
def create
@article = Article.new(article_params)
if @article.save
redirect_to @article
else
render :new, status: :unprocessable_entity
end
end
**언제 쓰면 안 되는가:**
- *(TODO)*
private
def article_params
params.require(:article).permit(:title, :body)
end
end
## 🧪 검증 상태 (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
# app/views/articles/index.html.erb
<% @articles.each do |a| %>
<h2><%= a.title %></h2>
<% end %>
```
## 🤔 의사결정 기준 (Decision Criteria)
### 2. Express + MVC (Node.js)
```typescript
// models/User.ts
export class User {
static async findById(id: string) {
return db.user.findUnique({ where: { id } });
}
}
**선택 A를 써야 할 때:**
- *(TODO)*
// controllers/userController.ts
export async function showUser(req: Request, res: Response) {
const user = await User.findById(req.params.id);
if (!user) return res.status(404).render("404");
res.render("user/show", { user });
}
**선택 B를 써야 할 때:**
- *(TODO)*
// views/user/show.ejs
<h1><%= user.name %></h1>
```
**기본값:**
> *(TODO)*
### 3. Spring MVC (Java)
```java
@Controller
@RequestMapping("/articles")
public class ArticleController {
@Autowired ArticleService service;
## ❌ 안티패턴 (Anti-Patterns)
@GetMapping("/{id}")
public String show(@PathVariable Long id, Model model) {
Article a = service.findById(id);
model.addAttribute("article", a);
return "articles/show"; // resolves to articles/show.html
}
}
```
- **[안티패턴]:** *(TODO: 무엇을 하면 안 되는가 + 이유 + 대신 무엇을)*
### 4. Smalltalk-style observer (classic)
```typescript
class Model {
private observers: Array<() => void> = [];
private _value = 0;
get value() { return this._value; }
set value(v: number) {
this._value = v;
this.observers.forEach(fn => fn());
}
subscribe(fn: () => void) { this.observers.push(fn); }
}
class View {
constructor(private model: Model, private el: HTMLElement) {
model.subscribe(() => this.render());
this.render();
}
render() { this.el.textContent = String(this.model.value); }
}
class Controller {
constructor(private model: Model, button: HTMLButtonElement) {
button.addEventListener("click", () => { this.model.value += 1; });
}
}
```
### 5. MVVM (Vue 3, modern equivalent)
```vue
<script setup lang="ts">
import { ref, computed } from "vue";
// ViewModel
const count = ref(0);
const doubled = computed(() => count.value * 2);
function increment() { count.value++; }
</script>
<template>
<!-- View: declarative binding -->
<button @click="increment">{{ count }} (x2 = {{ doubled }})</button>
</template>
```
### 6. Anti-MVC: God controller smell
```typescript
// 매 BAD — controller 가 매 business logic + data access + rendering 다 처리
class ArticleController {
async create(req, res) {
// validation, db query, email send, audit log, render — 200 lines
}
}
// 매 GOOD — service layer 분리
class ArticleController {
async create(req, res) {
const article = await this.service.publish(req.body, req.user);
res.render("article/show", { article });
}
}
```
## 매 결정 기준
| 상황 | Approach |
|---|---|
| Server-rendered web app, CRUD heavy | Classic MVC (Rails, Django, Laravel). |
| SPA, complex interactive UI | Component-driven (React, Vue, Svelte). |
| Two-way binding, form-heavy | MVVM (Vue, WPF). |
| Strict unidirectional, time-travel debug | Flux / Redux. |
| Native mobile (iOS/Android) | MVVM 또는 MVI (modern preferred over MVC). |
| Microservice without UI | 매 MVC 부적합 — Hexagonal/Clean. |
**기본값**: server-side full-stack 은 매 MVC framework. SPA 는 매 component model + state library.
## 🔗 Graph
- 부모: [[UI Architecture Patterns]] · [[Separation of Concerns]]
- 변형: [[MVP]] · [[MVVM]] · [[MVI]] · [[Flux Redux]]
- 응용: [[Ruby on Rails]] · [[Django]] · [[Spring MVC]] · [[ASP.NET MVC]]
- Adjacent: [[Hexagonal Architecture]] · [[Clean Architecture]] · [[Component Driven Development]]
## 🤖 LLM 활용
**언제**: server-side framework choice, legacy MVC refactor, UI architecture comparison.
**언제 X**: 매 modern SPA architecture (component-driven 이 dominant), microservice 의 service-internal 구조.
## ❌ 안티패턴
- **Fat Controller**: 매 business logic 의 controller dump — service layer 로 분리.
- **Anemic Model**: 매 model 이 data bag, logic 이 service 에. DDD aggregate 로 보강.
- **View 의 logic**: 매 template 의 conditional/loop 이 매 business decision — model/presenter 로 push.
- **Controller-View tight coupling**: 매 controller 가 매 specific view path hardcode — view selection abstraction.
- **MVC for SPA**: 매 React app 에 backend MVC 강제 적용 — component model 이 fit.
## 🧪 검증 / 중복
- Verified (Reenskaug 1979 memo, Gamma et al. *Design Patterns* MVC discussion, Rails Guides).
- 신뢰도 A.
## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — classic MVC + modern variant comparison + 2026 positioning |