이 강의에서는 NestJS 애플리케이션의 기본 구조와 주요 구성 요소인 Module, Controller, Service 등 각 클래스의 역할과 사용 방법을 이해합니다.
NestJS는 모듈화된 구조를 기반으로 하며, 다음과 같은 주요 구성 요소로 나뉩니다:
Modules: 애플리케이션의 기능을 모듈 단위로 나누어 관리합니다.
Controllers: 클라이언트의 HTTP 요청을 처리하고, 응답을 반환합니다.
Services: 비즈니스 로직을 처리하고, 데이터베이스와 상호작용합니다.
Repositories: TypeORM을 사용하여 데이터베이스와의 상호작용을 처리합니다.
ORM: 코드에 있는 "객체"와 DB에 있는 "데이터"를 편하게 일치시켜주는 도구
(우리가 만든 "객체"에 맞춰 SQL을 자동 생성해 데이터와 "동기화”)
TypeORM: node.js에서 실행되고 TypeScript로 작성된 객체 관계형 매핑 라이브러리(ORM)
전체적인 프로젝트 구조는 다음과 같습니다:
src/
|-- app.module.ts
|-- app.controller.ts
|-- app.service.ts
|-- modules/
|-- user/
|-- user.module.ts
|-- user.controller.ts
|-- user.service.ts
|-- user.entity.ts
|-- user.repository.ts
|-- auth/
|-- auth.module.ts
|-- auth.controller.ts
|-- auth.service.ts
|-- auth.entity.ts
|-- auth.repository.ts
// user.module.ts
import { Module } from '@nestjs/common';
import { UserController } from './user.controller';
import { UserService } from './user.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { UserEntity } from './user.entity';
import { UserRepository } from './user.repository';
@Module({
imports: [TypeOrmModule.forFeature([UserEntity])],
controllers: [UserController],
providers: [UserService, UserRepository],
exports: [UserService],
})
export class UserModule {}