밑에 적은거 말고도 회사나 개인마다 다르게 로직을 분리할 수 있음
로직을 분리하는 이유
계층을 나누는 이유
서비스 계층은 나머지 애플리케이션에서 모든 비즈니스 로직을 캡슐화하고 추상화합니다.
⭕ Service Layer Sould.
❌ Service Layer Sould Not.
req
, res
활용express 프레임워크 기본 폴더 구조
/public
/routes
/views
web.js
rest api 서비스 구조 (spring 프레임워크랑 비슷한거 같기도 하고 아닌거 같기도 하고)
src
│ app.js # App entry point 진입점
└───api # Express route controllers for all the endpoints of the app 엔드포인트에서 라우팅을 하는 부분
└───config # Environment variables and configuration related stuff 환경 변수등 저장하는 폴더
└───jobs # Jobs definitions for agenda.js agenda.js를 사용하는 경우에만
└───loaders # Split the startup process into modules 모듈의 시작점을 적어두는 부분
└───models # Database models DB 모델들
└───services # All the business logic is here 비즈니스 로직을 작성하는 부분
└───subscribers # Event handlers for async task async에 대한 이벤트 핸들러
└───types # Type declaration files (d.ts) for Typescript Typescript 사용하는 경우에만
모듈식 코드 구조
├───models
│ ├───user.model.js
├───routes
│ ├───user.route.js
├───services
│ ├───user.service.js
├───controllers
│ ├───user.controller.js
모델 - 모델 의 스키마 정의
경로 - API 경로가 컨트롤러에 매핑됩니다.
컨트롤러 - 컨트롤러는 요청 매개 변수 확인, 쿼리, 올바른 코드로 응답 보내기의 모든 로직을 처리합니다.
서비스 - 서비스에는 데이터베이스 쿼리와 반환 객체 또는 오류 발생이 포함됩니다.