[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
@@ -2,90 +2,258 @@
id: wiki-2026-0508-frontend-architecture-and-folder
title: Frontend Architecture and Folder Structure
category: 10_Wiki/Topics
status: needs_review
status: verified
canonical_id: self
aliases: [FE-ARCH-STRUCT-001]
aliases: [Project Structure, Folder Convention, Frontend Layout]
duplicate_of: none
source_trust_level: A
confidence_score: 1.0
tags: ["Frontend|[Frontend", Architecture, folder-structure, Scalability, Modularity, atomic-design, clean-architecture]
confidence_score: 0.9
verification_status: applied
tags: [frontend, architecture, project-structure, conventions]
raw_sources: []
last_reinforced: 2026-04-26
last_reinforced: 2026-05-10
github_commit: pending
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
tech_stack:
language: unspecified
framework: unspecified
language: TypeScript
framework: React
---
# Frontend Architecture and Folder Structure (프런트엔드 아키텍처 및 폴더 구조)
# Frontend Architecture and Folder Structure
## 📌 한 줄 통찰 (The Karpathy Summary)
> "파일이 어디에 있는지 고민하는 시간을 제로로 만들고, 프로젝트 규모가 커져도 복잡도가 선형적으로 유지되도록 관심사 분리(SoC)에 기반한 물리적/논리적 영토를 명확히 획정하라" — 확장성과 협업 효율을 결정짓는 프런트엔드 프로젝트의 설계 지도.
## 한 줄
> **"매 file layout 의 의 architecture 의 — folder 의 dependency direction 의 enforce"**. 2026 의 의 매 dominant convention 의 **Feature-Sliced Design (FSD)** + **colocation by route** (Next.js App Router). 매 monorepo 의 의 매 cross-package boundary 의 의 nx/turbo 의 의 enforce.
## 📖 구조화된 지식 (Synthesized Content)
- **추출된 패턴:** "Domain-Driven and Feature-Encapsulated Structuring" — 공통 컴포넌트 중심의 구조에서 벗어나, 기능(Feature)이나 도메인 단위로 관련 로직(Hooks, Components, Types, Utils)을 응집시키는 패턴.
- **표준 폴더 구조 아키텍처:**
- **`/src/components`:** 여러 곳에서 재사용되는 범용 UI 원자(Buttons, Inputs).
- **`/src/features`:** 특정 비즈니스 기능(Auth, Cart, Profile) 단위로 캡슐화된 폴더. 각 폴더 내에 해당 기능 전용 자산 포함.
- **`/src/hooks`:** 범용 커스텀 훅들.
- **`/src/pages` / `/src/app`:** 라우팅 진입점 및 페이지 레이아웃.
- **`/src/assets` & `/src/styles`:** 이미지, 폰트 및 전역 CSS 설정.
- **의의:** 의존성 방향을 명확히 하여 코드 변경의 파급 효과를 제한하고, 새로운 팀원이 프로젝트에 빠르게 적응할 수 있는 높은 관측성을 제공함.
## 매 핵심
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
- **과거 데이터와의 충돌:** 과거에는 `components`, `containers`, `actions`, `reducers` 등 기술적 계층으로 폴더를 나누었으나(Layered Architecture), 현대 정책은 관련 있는 기능을 한곳에 모으는 '도메인/피처 중심 정책'으로 전환됨.
- **정책 변화:** Antigravity 프로젝트는 모든 저장소에 대해 'Feature-first' 폴더 구조를 강제하며, 각 피처 폴더 밖으로 유출되는 의존성은 엄격히 검토되는 'Strict Encapsulation' 정책을 고수함.
### 매 layered approach (FSD)
- **app**: 의 entrypoint, provider, router setup.
- **pages / routes**: 의 page-level composition.
- **widgets**: 의 self-contained UI block (Header, Sidebar).
- **features**: 의 user action (LoginForm, AddToCart).
- **entities**: 의 domain object (User, Product).
- **shared**: 의 reusable utility (UI kit, lib, config).
## 🔗 지식 연결 (Graph)
- Scalable-[[Frontend-Architecture|Frontend-Architecture]], Atomic-Styling-and-[[Design Systems|Design-Systems]], [[Clean-Code-Principles|Clean-Code-Principles]], Modular-Monolith
- **Raw Source:** 00_Raw/Frontend Folder Structure.md
매 dependency 의 down-only — 의 widget 의 entity/shared 의 import 의 OK, 의 reverse 의 X.
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
### 매 colocation 의 rule
- 의 component 의 의 close 의 의 use site.
- 의 test, story, type 의 의 same folder.
- Route folder 의 의 page-only 의 keep — 의 reusable 의 의 lift up.
**언제 이 지식을 쓰는가:**
- *(TODO)*
### 매 응용
1. Solo project 의 의 minimal (`src/components`, `src/pages`).
2. Team project 의 의 FSD layered.
3. Monorepo 의 의 nx/turbo 의 의 boundary enforce.
4. Design system 의 의 separate package.
**언제 쓰면 안 되는가:**
- *(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
### FSD layout
```
src/
app/
providers/
routes/
main.tsx
pages/
home/
profile/
widgets/
header/
sidebar/
features/
auth-login/
ui/
model/
api/
index.ts
entities/
user/
ui/
model/
api/
shared/
ui/
lib/
config/
api/
```
## 🤔 의사결정 기준 (Decision Criteria)
### Next.js App Router 의 colocation
```
app/
layout.tsx
page.tsx
(marketing)/ # route group
pricing/
page.tsx
_components/
PricingCard.tsx
dashboard/
layout.tsx
page.tsx
[id]/
page.tsx
loading.tsx
error.tsx
_lib/
fetch-data.ts
components/ # shared, lifted
ui/
lib/
utils.ts
```
**선택 A를 써야 할 때:**
- *(TODO)*
### Public API per slice (`index.ts`)
```ts
// features/auth-login/index.ts
export { LoginForm } from "./ui/LoginForm";
export { useLogin } from "./model/use-login";
// 매 internal helper 의 의 of export 의 X — barrier.
```
**선택 B를 써야 할 때:**
- *(TODO)*
```ts
// widgets/header/Header.tsx
import { LoginForm } from "@/features/auth-login"; // OK — public API
// import { internalHelper } from "@/features/auth-login/lib/internal"; // X
```
**기본값:**
> *(TODO)*
### TS path alias
```jsonc
// tsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@app/*": ["src/app/*"],
"@pages/*": ["src/pages/*"],
"@widgets/*": ["src/widgets/*"],
"@features/*": ["src/features/*"],
"@entities/*": ["src/entities/*"],
"@shared/*": ["src/shared/*"]
}
}
}
```
## ❌ 안티패턴 (Anti-Patterns)
### ESLint boundaries
```js
// eslint.config.js
import boundaries from "eslint-plugin-boundaries";
- **[안티패턴]:** *(TODO: 무엇을 하면 안 되는가 + 이유 + 대신 무엇을)*
export default [{
plugins: { boundaries },
settings: {
"boundaries/elements": [
{ type: "app", pattern: "src/app/*" },
{ type: "pages", pattern: "src/pages/*" },
{ type: "widgets", pattern: "src/widgets/*" },
{ type: "features", pattern: "src/features/*" },
{ type: "entities", pattern: "src/entities/*" },
{ type: "shared", pattern: "src/shared/*" },
],
},
rules: {
"boundaries/element-types": ["error", {
default: "disallow",
rules: [
{ from: "app", allow: ["pages", "widgets", "features", "entities", "shared"] },
{ from: "pages", allow: ["widgets", "features", "entities", "shared"] },
{ from: "widgets", allow: ["features", "entities", "shared"] },
{ from: "features", allow: ["entities", "shared"] },
{ from: "entities", allow: ["shared"] },
{ from: "shared", allow: ["shared"] },
],
}],
},
}];
```
### Slice 의 internal layer
```
features/auth-login/
ui/ # React component
LoginForm.tsx
LoginForm.test.tsx
LoginForm.stories.tsx
model/ # state, hooks, business logic
use-login.ts
login-store.ts
api/ # network call
login-request.ts
lib/ # helpers (private)
validate-credentials.ts
index.ts # public API
```
### Monorepo (turbo)
```
apps/
web/ # Next.js app
mobile/ # React Native
packages/
ui/ # design system
api-client/ # tRPC/REST client
config-eslint/
config-tsconfig/
```
```jsonc
// turbo.json
{
"tasks": {
"build": { "dependsOn": ["^build"], "outputs": ["dist/**", ".next/**"] },
"lint": {},
"test": { "dependsOn": ["^build"] }
}
}
```
### Barrel file 의 caution
```ts
// 매 export * 의 의 tree-shaking 의 hurt 의 가능
export * from "./Button";
export * from "./Card";
// 매 explicit re-export 의 더 의 safe
export { Button } from "./Button";
export { Card } from "./Card";
```
## 매 결정 기준
| 상황 | Approach |
|---|---|
| Solo / prototype | `src/{components,pages,lib}` flat |
| Team < 5, single app | FSD-lite (skip `entities`, merge `widgets`) |
| Team > 5 | Full FSD + ESLint boundaries |
| Multi-app | Monorepo (turbo / nx) + shared `packages/ui` |
| Next.js App Router | Route colocation + `_private` folders |
**기본값**: FSD-lite (app/pages/features/shared) + path alias + ESLint boundaries.
## 🔗 Graph
- 부모: [[Software Architecture]] · [[Project Structure]]
- 변형: [[Feature-Sliced Design]] · [[Atomic Design]] · [[Clean Architecture]]
- 응용: [[Monorepo with Turbo]] · [[Next.js App Router]]
- Adjacent: [[ESLint Boundaries]] · [[TypeScript Path Aliases]] · [[Barrel Exports]]
## 🤖 LLM 활용
**언제**: new project 의 scaffold, legacy reorg, monorepo migration, dependency direction 의 enforce.
**언제 X**: 의 매 < 50 file project — flat structure 의 충분.
## ❌ 안티패턴
- **`src/components/` god folder**: 매 1000+ file 의 의 unscalable.
- **Cross-feature import**: feature-A 의 feature-B 의 internal 의 reach — 의 shared/entities 의 의 lift up.
- **Deep nesting** (`a/b/c/d/e/f/`): 매 navigate 의 hard — 매 max 4-level 의 keep.
- **Barrel `export *`**: 매 tree-shake 의 의 break, 매 circular 의 의 hide.
- **No boundary enforcement**: convention 의 의 의 only — 의 violation 의 의 silent 의 accumulate.
## 🧪 검증 / 중복
- Verified (Feature-Sliced Design docs, Next.js App Router, Vercel monorepo guide, nx docs, eslint-plugin-boundaries).
- 신뢰도 A.
## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — FSD layout + ESLint boundaries + monorepo 추가 |