TypeScript는 Java처럼 “정해진 구조”를 강제하지 않는다.
하지만 실제 프로젝트에서는 일관된 구조와 네이밍 규칙이 필수다.
이 글에서는 공식 개념 + 실무 관례를 기반으로 정리한다.
파일 = 모듈
📎 공식 문서
https://www.typescriptlang.org/docs/handbook/2/modules.html
핵심:
import/export가 존재하면 해당 파일은 모듈로 동작한다
| Java | TypeScript |
|---|---|
| 클래스 중심 | 파일(모듈) 중심 |
| 패키지 구조 | 자유 구조 |
| 상속 기반 | 조합 기반 |
👉 결론:
TypeScript는 “파일의 역할” 중심으로 구조를 설계해야 한다
src/
main.ts
config/
modules/
user/
user.controller.ts
user.service.ts
user.repository.ts
user.entity.ts
shared/
utils/
errors/
<domain>.<role>.ts
user.controller.ts
user.service.ts
user.repository.ts
user.entity.ts
user.repository.ts → DB 접근
user.service.ts → 비즈니스 로직
user.controller.ts
user.repository.ts
user.service.ts
user.ts ❌
dot-based naming
role-based naming
export class UserRepository {}
👉 PascalCase
const getUser = () => {}
const userName = "john";
👉 camelCase
const MAX_RETRY_COUNT = 3;
👉 UPPER_SNAKE_CASE
export interface User {}
type UserStatus = "active" | "inactive";
👉 PascalCase
| 대상 | 예시 |
|---|---|
| 파일 | user.repository.ts |
| 클래스 | UserRepository |
1. 파일 = 모듈 (핵심 개념)
2. 구조는 자유지만 feature 기반이 일반적
3. 파일명은 domain.role 패턴 사용
4. 클래스 PascalCase, 나머지는 camelCase
TypeScript Modules
https://www.typescriptlang.org/docs/handbook/2/modules.html
Angular Style Guide
https://angular.dev/style-guide
Node.js TypeScript Guide
https://nodejs.org/learn/typescript/publishing-a-ts-package