🛒 쇼핑몰 API 서버 구축 가이드

📁 프로젝트 파일 구조

shopping-mall-api/
├── src/
│   ├── main/
│   │   ├── java/
│   │   │   └── com/
│   │   │       └── example/
│   │   │           └── shoppingmall/
│   │   │               ├── ShoppingMallApplication.java
│   │   │               ├── config/
│   │   │               │   ├── SecurityConfig.java
│   │   │               │   ├── SwaggerConfig.java
│   │   │               │   └── JwtConfig.java
│   │   │               ├── controller/
│   │   │               │   ├── AuthController.java
│   │   │               │   ├── UserController.java
│   │   │               │   ├── ProductController.java
│   │   │               │   ├── CartController.java
│   │   │               │   └── OrderController.java
│   │   │               ├── service/
│   │   │               │   ├── AuthService.java
│   │   │               │   ├── UserService.java
│   │   │               │   ├── ProductService.java
│   │   │               │   ├── CartService.java
│   │   │               │   └── OrderService.java
│   │   │               ├── repository/
│   │   │               │   ├── UserRepository.java
│   │   │               │   ├── ProductRepository.java
│   │   │               │   ├── CartRepository.java
│   │   │               │   └── OrderRepository.java
│   │   │               ├── entity/
│   │   │               │   ├── User.java
│   │   │               │   ├── Product.java
│   │   │               │   ├── Cart.java
│   │   │               │   ├── CartItem.java
│   │   │               │   ├── Order.java
│   │   │               │   └── OrderItem.java
│   │   │               ├── dto/
│   │   │               │   ├── request/
│   │   │               │   │   ├── LoginRequest.java
│   │   │               │   │   ├── RegisterRequest.java
│   │   │               │   │   ├── ProductRequest.java
│   │   │               │   │   ├── CartItemRequest.java
│   │   │               │   │   └── OrderRequest.java
│   │   │               │   └── response/
│   │   │               │       ├── ApiResponse.java
│   │   │               │       ├── AuthResponse.java
│   │   │               │       ├── ProductResponse.java
│   │   │               │       ├── CartResponse.java
│   │   │               │       └── OrderResponse.java
│   │   │               ├── security/
│   │   │               │   ├── JwtTokenProvider.java
│   │   │               │   ├── JwtAuthenticationFilter.java
│   │   │               │   └── CustomUserDetailsService.java
│   │   │               ├── exception/
│   │   │               │   ├── GlobalExceptionHandler.java
│   │   │               │   ├── CustomException.java
│   │   │               │   └── ErrorCode.java
│   │   │               └── util/
│   │   │                   └── ResponseUtil.java
│   │   └── resources/
│   │       ├── application.yml
│   │       ├── application-dev.yml
│   │       ├── application-prod.yml
│   │       └── data.sql
│   └── test/
│       └── java/
│           └── com/
│               └── example/
│                   └── shoppingmall/
│                       ├── controller/
│                       ├── service/
│                       └── repository/
├── build.gradle
├── README.md
└── docs/
    ├── api-docs.md
    └── postman/
        └── shopping-mall-api.postman_collection.json

🗄️ 데이터베이스 설계

ERD (Entity Relationship Diagram)

┌─────────────┐     ┌─────────────┐     ┌─────────────┐
│    User     │     │   Product   │     │    Cart     │
├─────────────┤     ├─────────────┤     ├─────────────┤
│ id (PK)     │     │ id (PK)     │     │ id (PK)     │
│ email       │     │ name        │     │ user_id(FK) │
│ password    │     │ description │     │ created_at  │
│ name        │     │ price       │     └─────────────┘
│ phone       │     │ stock       │           │
│ role        │     │ category    │           │
│ created_at  │     │ image_url   │           │
│ updated_at  │     │ created_at  │           │
└─────────────┘     │ updated_at  │           │
       │            └─────────────┘           │
       │                   │                 │
       │                   │                 │
       └───────┐           │     ┌───────────┘
               │           │     │
        ┌─────────────┐    │     │    ┌─────────────┐
        │    Order    │    │     │    │  CartItem   │
        ├─────────────┤    │     │    ├─────────────┤
        │ id (PK)     │    │     │    │ id (PK)     │
        │ user_id(FK) │────┘     │    │ cart_id(FK) │
        │ total_price │          │    │ product_id  │
        │ status      │          │    │ quantity    │
        │ order_date  │          │    │ created_at  │
        └─────────────┘          │    └─────────────┘
               │                 │           │
               │                 └───────────┘
               │
        ┌─────────────┐
        │  OrderItem  │
        ├─────────────┤
        │ id (PK)     │
        │ order_id(FK)│
        │ product_id  │
        │ quantity    │
        │ price       │
        └─────────────┘

🚀 개발 순서 (단계별 진행)

1단계: 프로젝트 초기 설정

2단계: 데이터베이스 & 엔티티 설계

3단계: 보안 & 인증 구현

4단계: 상품 관리 API

5단계: 장바구니 기능

6단계: 주문 관리

7단계: API 문서화 & 최종 테스트

📋 주요 의존성 (build.gradle)

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-validation'

    // JWT
    implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
    implementation 'io.jsonwebtoken:jjwt-impl:0.11.5'
    implementation 'io.jsonwebtoken:jjwt-jackson:0.11.5'

    // MySQL
    implementation 'mysql:mysql-connector-java'

    // Swagger
    implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'

    // Test
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.springframework.security:spring-security-test'
}

🔥 핵심 구현 포인트

1. JWT 토큰 기반 인증

2. RESTful API 설계

3. 예외 처리

4. 테스트 코드

📚 학습 리소스

  1. Spring Boot 공식 문서
  2. Spring Security Reference
  3. JWT 공식 문서
  4. Swagger/OpenAPI 문서
  5. JPA/Hibernate 가이드

Error

shopping_mall_api.pdf

openapi.json