브렌쏭의 Veritas_Garage

Nest.js 폴더 구조 : MVC 본문

[Project_만들다]/[Project_자아내다]

Nest.js 폴더 구조 : MVC

브렌쏭 2022. 3. 29. 15:13

https://nestjs.com/

 

NestJS - A progressive Node.js framework

NestJS is a framework for building efficient, scalable Node.js web applications. It uses modern JavaScript, is built with TypeScript and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Reactive Progr

nestjs.com

일단 모오든 폴더들을 끌어모아서 트리형식으로 만들면 아래와 같은 구조를 가지고 있다.

src
├── auth
│   ├── decorators
│   ├── dtos
│   ├── exceptions
│   ├── guards
│   └── interfaces
├── common
│   ├── decorators
│   ├── dtos
│   ├── entities
│   ├── exceptions
│   ├── helpers
│   └── interfaces
├── config
│   ├── app
│   ├── database
│   │   └── mysql
│   └── jwt
├── database
│   ├── migrations
├── modules
│   ├── item
│   │   ├── brands
│   │   │   ├── entities
│   │   │   ├── interfaces
│   │   │   └── repositories
│   │   └── items
│   │       ├── entities
│   │       ├── interfaces
│   │       └── repositories
│   └── user
│       └── users
│           ├── entities
│           ├── interfaces
│           └── repositories
├── providers
|   ├── aws
│   │   ├── s3
│   │   └── sqs
|   ├── cache
│   │   └── redis
│   ├── database
│   │   └── postgres
│   └── elasticsearch
│       ├── helpers
│       └── types
├── app.controller.ts
├── app.module.ts
└── main.ts

일단 압도되는 광경이지만, 일단은.. 간단하게 시작하자.

  • 눈에 보이는 것은 views 폴더에 넣는다
  • 이벤트를 감지하는 것은 controllers 폴더에,
  • 그 이벤트를 통해 원하는 액션을 취하는 비즈니스 로직은 controllers 하위의 services 폴더로 간다

뭐가 서비스입니까

일단 DB와 연동되는 부분은 서비스로 간다. 그리고 돈 될만한 핵심 기능이면 전부 서비스로 간다.

뭘 해야 합니까

대부분의 일은 Nestjs가 관리해줄 것이다. 하지만 무엇을 관리당하고 무엇을 할 수 있는지를 알지 못하면 쓰는 의미가 없다. DI라던가.. 일단 저 트리 구조에 맞춰서 잘 작성을 해야 파일 매니지먼트가 원활하게 될 것이다. 니 맘대로 쓴 일기장을 자서전으로 컨버팅해주는 만능툴이 아니다.

우리가 집중해서 볼 부분은 src 폴더 내부 중에서도 일부다. module, controller, service .

시각적요소와 조작요소, 비즈니스 로직 등을 서로 영향 없이 보수 가능해진다
이제 웹의 입장에서 보면 이런 식이다

 

'[Project_만들다] > [Project_자아내다]' 카테고리의 다른 글

데이터베이스 스키마  (0) 2022.03.30
OOP*( NestJS + TypeORM ) = [ DTO & Entity ]  (0) 2022.03.30
Nest.js 로 간다 #20220329  (0) 2022.03.29
Optional Chaining  (0) 2022.03.28
Nest.js 를 위한 기초쌓기 #20220328  (0) 2022.03.28
파이프라인 or ERD  (0) 2022.03.28
스크랩 / 크롤링  (0) 2022.03.24
Comments