Express + TypeScript + Sequelize 기반 Node.js 백엔드 애플리케이션
- Runtime: Node.js (LTS >=18)
- Framework: Express.js
- Language: TypeScript
- ORM: Sequelize
- Database: MySQL
- Code Quality: ESLint + Prettier
BE/
├── src/
│ ├── controllers/ # Request handlers
│ ├── services/ # Business logic
│ ├── repositories/ # Data access layer
│ ├── routes/ # Route definitions
│ ├── middleware/ # Express middleware
│ ├── utils/ # Utility functions
│ └── index.ts # Application entry point
├── dist/ # Compiled JavaScript (generated)
├── .env # Environment variables (not in git)
├── .env.example # Environment variables template
├── tsconfig.json # TypeScript configuration
├── .eslintrc.json # ESLint configuration
├── .prettierrc.json # Prettier configuration
└── package.json
- Node.js >= 18.0.0
- MySQL (running locally or remote)
- npm or yarn
-
Clone the repository
git clone https://github.com/ChoiTheCreator/Eternal-BE.git cd Eternal-BE -
Install dependencies
npm install
-
Setup environment variables
cp .env.example .env
Edit
.envand configure:DB_NAME: MySQL database nameDB_USER: MySQL usernameDB_PASSWORD: MySQL passwordDB_HOST: MySQL host (default: localhost)DB_PORT: MySQL port (default: 3306)PORT: Server port (default: 3000)NODE_ENV: Environment (development/production)JWT_SECRET: JWT secret keyJWT_REFRESH_SECRET: JWT refresh secret key
-
Setup Database
# MySQL 데이터베이스 생성 (수동으로) mysql -u root -p CREATE DATABASE eternal_db; # Run migrations (creates database tables) npm run db:migrate # Seed database with initial data (optional) npm run db:seed
기본 어드민 계정:
- Email:
admin@example.com - Password:
admin123
- Email:
-
Start development server
npm run dev
Server will start at
http://localhost:3000- API Documentation:
http://localhost:3000/api-docs
- API Documentation:
npm run dev- Start development server with hot-reload (tsx watch)npm run build- Build TypeScript to JavaScriptnpm run start- Start production server (requires build first)npm run type-check- Type check without emitting files
npm run lint- Run ESLintnpm run lint:fix- Fix ESLint errors automaticallynpm run format- Format code with Prettiernpm run format:check- Check code formatting
npm run db:migrate- Run pending migrationsnpm run db:migrate:undo- Undo last migrationnpm run db:migrate:undo:all- Undo all migrationsnpm run db:seed- Run seedersnpm run db:seed:undo- Undo seedersnpm run db:reset- Reset database (undo all, migrate, seed)
Swagger UI: 서버 실행 후 http://localhost:3000/api-docs 에서 API 문서를 확인할 수 있습니다.
모든 API 엔드포인트는 Swagger를 통해 자동 문서화되어 있으며, 직접 테스트할 수 있습니다.
프로젝트 디버깅을 위한 상세한 가이드:
# .env 파일에 추가
DEBUG=true
NODE_ENV=development
# 서버 재시작
npm run dev이제 모든 API 요청, SQL 쿼리, 에러가 자동으로 로깅됩니다.
GET /health- Check server and database health status
POST /api/auth/login- 어드민 로그인GET /api/auth/me- 현재 로그인된 어드민 정보
GET /api/columns- 칼럼 목록 조회GET /api/columns/:id- 칼럼 상세 조회POST /api/columns- 칼럼 생성 (어드민)PUT /api/columns/:id- 칼럼 수정 (어드민)DELETE /api/columns/:id- 칼럼 삭제 (어드민)
GET /api/categories- 카테고리 목록POST /api/categories- 카테고리 생성 (어드민)
GET /api/tags- 태그 목록POST /api/tags- 태그 생성 (어드민)
GET /api/page-content- 컨텐츠 목록GET /api/page-content/:key- 컨텐츠 조회PUT /api/page-content/:key- 컨텐츠 수정 (어드민)
POST /api/media/upload- 파일 업로드 (어드민)GET /api/media- 미디어 목록
상세한 API 문서: API_GUIDE.md
This project follows a layered architecture:
- Routes (
src/routes/) - Define API endpoints - Controllers (
src/controllers/) - Handle HTTP requests/responses - Services (
src/services/) - Business logic - Repositories (
src/repositories/) - Database operations (optional layer) - Middleware (
src/middleware/) - Express middleware (auth, error handling, etc.)
Configuration in tsconfig.json - strict mode enabled, path aliases configured (@/*)
Database schema defined in src/models/. Run migrations to update database structure.
Create a .env file in the root directory:
DB_NAME=eternal_db
DB_USER=root
DB_PASSWORD=your_password
DB_HOST=localhost
DB_PORT=3306
PORT=3000
NODE_ENV=development
JWT_SECRET=your-secret-key-change-in-production
JWT_REFRESH_SECRET=your-refresh-secret-key-change-in-production
UPLOAD_DIR=uploads
BASE_URL=http://localhost:3000Required variables:
DB_NAME- MySQL database nameDB_USER- MySQL usernameDB_PASSWORD- MySQL passwordJWT_SECRET- JWT 토큰 비밀키 (프로덕션에서는 반드시 변경!)JWT_REFRESH_SECRET- JWT 리프레시 토큰 비밀키
Optional variables:
DB_HOST- MySQL host (default: localhost)DB_PORT- MySQL port (default: 3306)PORT- Server port (default: 3000)NODE_ENV- Environment (development/production)UPLOAD_DIR- 파일 업로드 디렉토리 (default: uploads)BASE_URL- 기본 URL (default: http://localhost:3000)
- Make changes to TypeScript files in
src/ - Development server auto-reloads on file changes
- Use
npm run lintandnpm run formatbefore committing - Create Sequelize migrations when schema changes:
npm run db:migrate
All scripts are cross-platform compatible (Windows/macOS/Linux):
- Uses
tsxfor TypeScript execution (no compilation step needed for dev) - Path separators handled correctly
- No OS-specific commands in scripts
# Build TypeScript
npm run build
# Apply database migrations
npm run db:migrate
# Start production server
npm start- Verify MySQL is running
- Check database credentials in
.env(DB_NAME, DB_USER, DB_PASSWORD, DB_HOST, DB_PORT) - Ensure database exists (create manually before running migrations)
- Change
PORTin.envor kill the process using the port
- Ensure database exists before running migrations
- Check Sequelize migration files in
src/db/migrations/
ISC
- DEV_LOG.md - 백엔드 작업 내용을 기획자 관점에서 쉽게 이해할 수 있도록 기록한 개발 일지 (날짜별, 단계별 설명)
- CODE_ARCHITECTURE.md - 프로젝트의 코드 설계 원칙, 레이어 구조, 각 컴포넌트의 역할과 책임에 대한 상세 가이드
- QUICK_REFERENCE.md - 바이브코딩 세션 중 빠르게 참고할 수 있는 코드 템플릿과 패턴 모음
- Create a feature branch
- Make your changes
- Run
npm run lintandnpm run format - Test your changes
- Submit a pull request