Skip to content

Latest commit

Β 

History

History
124 lines (92 loc) Β· 5.45 KB

File metadata and controls

124 lines (92 loc) Β· 5.45 KB

ν”„λ‘ νŠΈμ—”λ“œ νƒ€μž… μ‹œμŠ€ν…œ β€” TypeScript

StackUp ν”„λ‘ νŠΈμ—”λ“œμ˜ TypeScript νƒ€μž… κ·œμ•½. νƒ€μž…μ€ μ‚¬μš©λ˜λŠ” λ ˆμ΄μ–΄μ— μ‚°λ‹€. μ΄λ¦„μ˜ 접미사가 μ±…μž„ 경계λ₯Ό μ„ μ–Έν•œλ‹€.

μƒμœ„ μ»¨ν…μŠ€νŠΈ β€” coding-conventions.md (μ–Έμ–΄ 곡톡 κ·œμ•½), frontend/CLAUDE.md (FSD ꡬ쑰) 적용 λ²”μœ„ β€” frontend/src/


λͺ©μ°¨

  1. 원칙
  2. 접미사 ↔ λ ˆμ΄μ–΄ 맀트릭슀
  3. λ ˆμ΄μ–΄λ³„ νƒ€μž… 흐름
  4. type vs interface
  5. μ •μ˜ μœ„μΉ˜
  6. shared 승격 μž„κ³„
  7. μ•ˆν‹°νŒ¨ν„΄

1. 원칙

  • PascalCase + 의미 μžˆλŠ” 접미사. 접미사가 νƒ€μž…μ˜ μ±…μž„Β·λ ˆμ΄μ–΄λ₯Ό μ‹ κ³ ν•œλ‹€.
  • I / T Hungarian prefix κΈˆμ§€ β€” TypeScript μ»΄νŒŒμΌλŸ¬κ°€ type / interface λ₯Ό μΆ©λΆ„νžˆ κ΅¬λΆ„ν•œλ‹€.
  • 단방ν–₯ 흐름: Dto β†’ Entity β†’ Model β†’ Props. μ—­λ°©ν–₯ import κΈˆμ§€.
  • μ „μ—­ types/ 폴더 κΈˆμ§€. 슬라이슀 λ‚΄λΆ€μ—μ„œ μ‹œμž‘, μ§„μ§œ 곡유될 λ•Œλ§Œ λŒμ–΄μ˜¬λ¦°λ‹€.

2. 접미사 ↔ λ ˆμ΄μ–΄ 맀트릭슀

접미사 λ ˆμ΄μ–΄ μ±…μž„ 예
XxxDto shared/api/ (OpenAPI μžλ™ 생성) λ°±μ—”λ“œ wire format μŠ€λƒ…μƒ·. μˆ˜μ • κΈˆμ§€ SessionDto, UserDto
XxxRequest / XxxPayload API ν˜ΈμΆœλΆ€, 이벀트 publisher HTTP μš”μ²­ body, RabbitMQ λ©”μ‹œμ§€ payload CreateSessionRequest, ResumeAnalyzedPayload
XxxResponse API ν˜ΈμΆœλΆ€ HTTP 응닡 raw shape (μˆ˜λ™ μ •μ˜ μ‹œ) β€” ν•¨μˆ˜ λ°˜ν™˜μ— μ‚¬μš© βœ— LoginResponse
Xxx (접미사 μ—†μŒ) domain/{slice}/model/ λΉ„μ¦ˆλ‹ˆμŠ€ μ—”ν„°ν‹°. Dtoμ—μ„œ 맀핑됨 User, Session, Resume
XxxResult 도메인 / μœ μ¦ˆμΌ€μ΄μŠ€ ν•¨μˆ˜ λ°˜ν™˜ λΉ„μ¦ˆλ‹ˆμŠ€ 둜직 좜λ ₯ (HTTP 비쒅속) AnalysisResult, ValidationResult
XxxModel features/*/ui/, widgets/*/ui/ UI ν‘œμ‹œ μ „μš© 가곡 데이터 SessionListItemModel, ServiceCardModel
XxxProps μ»΄ν¬λ„ŒνŠΈ μ˜† React props ButtonProps, HomeHeroProps
XxxState store / state machine λͺ…μ‹œμ  μƒνƒœ λͺ¨λΈ. λ‹¨λ°œ useState shape 에 μ‚¬μš© βœ— AuthState, SessionMachineState
XxxOptions ν•¨μˆ˜Β·ν›… μ„€μ • μ˜΅μ…”λ„ 인자 묢음 UseTypewriterOptions
XxxId μ–΄λ””λ“  branded identifier type SessionId = number & { readonly __brand: 'SessionId' }

3. λ ˆμ΄μ–΄λ³„ νƒ€μž… 흐름

 [Backend OpenAPI]
        β”‚ openapi-typescript μžλ™ 생성
        β–Ό
 shared/api/generated.ts      ──  XxxDto
        β”‚ 맀퍼 ν•¨μˆ˜ (toUser, toSession)
        β–Ό
 domain/{slice}/model/        ──  Xxx (Entity)
        β”‚ feature / widget μ—μ„œ UI 가곡
        β–Ό
 features|widgets/*/ui/       ──  XxxModel
        β”‚ props 둜 μ£Όμž…
        β–Ό
 React Component              ──  XxxProps

경계 κ·œμΉ™:

  • XxxDto λŠ” shared/api/ λ°–μœΌλ‘œ μƒˆμ§€ μ•ŠλŠ”λ‹€. UI Β· 도메인이 Dto λ₯Ό 직접 import ν•˜λ©΄ anti-corruption layer κ°€ λ¬΄λ„ˆμ§„λ‹€.
  • Xxx (Entity) λŠ” domain/ 이 μ†Œμœ . features / widgets λŠ” read-only 둜 μ°Έμ‘°ν•œλ‹€.
  • XxxModel 은 슬라이슀 내뢀에 λ¨Έλ¬Έλ‹€. λ‹€λ₯Έ 슬라이슀둜 export ν•˜μ§€ μ•ŠλŠ”λ‹€ β€” UI ν‘œμ‹œ ν˜•νƒœκ°€ λˆ„μˆ˜λ˜λ©΄ λ³€κ²½ λΉ„μš©μ΄ ν­μ¦ν•œλ‹€.

4. type vs interface

type κΈ°λ³Έκ°’. interface λŠ” 두 κ²½μš°μ—λ§Œ:

  1. ν΄λž˜μŠ€κ°€ implements ν•  λ•Œ (ErrorBoundary λ“±)
  2. declaration merging ν•„μš” μ‹œ (μ™ΈλΆ€ 라이브러리 augmentation)
// μ’‹μŒ
type SessionStatus = 'READY' | 'IN_PROGRESS' | 'COMPLETED';
type CreateSessionRequest = { userId: UserId; mode: SessionMode };
type AnalysisResult = { score: number; suggestions: string[] };

// μ’‹μŒ β€” implements κ°€ ν•„μš”ν•œ μΌ€μ΄μŠ€
interface ErrorBoundaryProps { children: ReactNode; fallback: ReactNode }
class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> { ... }

5. μ •μ˜ μœ„μΉ˜

무엇 μ–΄λ””
μ»΄ν¬λ„ŒνŠΈ props (단일 μ‚¬μš©) {Component}.tsx 상단, export μ•ˆ 함
μ™ΈλΆ€μ—μ„œλ„ import λ˜λŠ” props {Component}.types.ts
도메인 μ—”ν„°ν‹° domain/{slice}/model/types.ts
슬라이슀 λ‚΄ XxxModel features/{slice}/model/types.ts λ˜λŠ” ui/ λ‚΄λΆ€
API XxxDto shared/api/generated.ts (OpenAPI μž¬μƒμ„±μœΌλ‘œλ§Œ κ°±μ‹ )

μ „μ—­ src/types/ ν΄λ”λŠ” λ§Œλ“€μ§€ μ•ŠλŠ”λ‹€. 슬라이슀 λ‚΄λΆ€μ—μ„œ μ‹œμž‘ν•˜κ³ , μ§„μ§œ 곡유될 λ•Œλ§Œ λŒμ–΄μ˜¬λ¦°λ‹€.


6. shared 승격 μž„κ³„

νƒ€μž…μ„ shared/ 둜 μ˜¬λ¦¬λŠ” μ‹œμ μ€ μ„œλ‘œ λ‹€λ₯Έ 슬라이슀 3κ³³ μ΄μƒμ—μ„œ λ™μΌν•œ shape 이 반볡될 λ•Œ. κ·Έ μ „μ—” 슬라이슀 μ•ˆμ— μ‚°λ‹€.

"μ–Έμ  κ°€ 쓸지도 λͺ¨λ₯΄λ‹ˆ 미리 shared 둜" λŠ” 항상 잘λͺ»λœ μΆ”μƒν™”λ‘œ λλ‚œλ‹€.


7. μ•ˆν‹°νŒ¨ν„΄

  • ❌ XxxResponse λ₯Ό ν•¨μˆ˜ λ°˜ν™˜ νƒ€μž…μœΌλ‘œ μ‚¬μš© β€” XxxResult 둜.
  • ❌ UI μ»΄ν¬λ„ŒνŠΈκ°€ SessionDto λ₯Ό props 둜 λ°›μŒ β€” SessionListItemModel 둜 λ§€ν•‘.
  • ❌ 둜컬 useState<{ ... }> shape 에 XxxState 이름 뢙이고 export.
  • ❌ export type Props = { ... } 같은 generic export β€” {Component}Props 둜.
  • ❌ src/types/ λ˜λŠ” src/shared/types/ μ „μ—­ 폴더 (junk drawer ν™”).
  • ❌ IXxx, TXxx Hungarian prefix.
  • ❌ Dto κ°€ features/ / widgets/ / domain/ μ—μ„œ import λ˜λŠ” 경우 β€” boundary μœ„λ°˜.