|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Build & Run Commands |
| 6 | + |
| 7 | +```bash |
| 8 | +# 인프라 실행 (MySQL 3307, Redis 6379/6380, Kafka 19092, Kafka UI 9099) |
| 9 | +docker compose -f ./docker/infra-compose.yml up |
| 10 | + |
| 11 | +# 모니터링 실행 (Prometheus 9090, Grafana 3000) |
| 12 | +docker compose -f ./docker/monitoring-compose.yml up |
| 13 | + |
| 14 | +# 전체 빌드 |
| 15 | +./gradlew build |
| 16 | + |
| 17 | +# 특정 모듈 빌드 |
| 18 | +./gradlew :apps:commerce-api:build |
| 19 | + |
| 20 | +# 전체 테스트 |
| 21 | +./gradlew test |
| 22 | + |
| 23 | +# 특정 테스트 클래스 실행 |
| 24 | +./gradlew :apps:commerce-api:test --tests ExampleV1ApiE2ETest |
| 25 | + |
| 26 | +# 코드 커버리지 리포트 |
| 27 | +./gradlew jacoco |
| 28 | + |
| 29 | +# Swagger UI: http://localhost:8080/swagger-ui.html |
| 30 | +``` |
| 31 | + |
| 32 | +## Architecture |
| 33 | + |
| 34 | +Java 21 / Spring Boot 3.4.4 멀티모듈 Gradle 프로젝트. |
| 35 | + |
| 36 | +### Module Structure |
| 37 | + |
| 38 | +- **apps/** — 실행 가능한 Spring Boot 애플리케이션 (BootJar) |
| 39 | + - `commerce-api` — REST API 서버 (Web, JPA, Redis, Swagger) |
| 40 | + - `commerce-batch` — 배치 처리 (web-application-type: none) |
| 41 | + - `commerce-streamer` — Kafka 컨슈머 스트리밍 |
| 42 | +- **modules/** — 재사용 가능한 인프라 설정 (java-library, test-fixtures 제공) |
| 43 | + - `jpa` — JPA/Hibernate, QueryDSL, HikariCP, BaseEntity(soft delete, audit) |
| 44 | + - `redis` — Master-Replica 구성, Lettuce, 읽기/쓰기 분리 |
| 45 | + - `kafka` — 배치 리스너(3000건), Manual ACK, JsonSerializer |
| 46 | +- **supports/** — 부가 기능 모듈 |
| 47 | + - `jackson` — JSR310 직렬화 설정 |
| 48 | + - `logging` — 프로파일별 logback (local: 텍스트, dev+: JSON + Slack) |
| 49 | + - `monitoring` — Prometheus/Micrometer, 관리 포트 8081 |
| 50 | + |
| 51 | +### Layered Architecture (commerce-api 기준) |
| 52 | + |
| 53 | +``` |
| 54 | +interfaces/api/ → Controller, DTO, ApiResponse, ApiControllerAdvice |
| 55 | +application/ → Facade (유스케이스 조합), Info (응답 DTO) |
| 56 | +domain/ → Model (JPA Entity), Repository (인터페이스), Service |
| 57 | +infrastructure/ → JpaRepository 구현체 |
| 58 | +support/error/ → CoreException, ErrorType (에러 코드 enum) |
| 59 | +``` |
| 60 | + |
| 61 | +- Repository 패턴: domain에 인터페이스, infrastructure에 구현체 |
| 62 | +- Facade 패턴: application 레이어에서 여러 도메인 서비스 조합 |
| 63 | +- API 버전닝: `/api/v1/` 경로 기반 |
| 64 | +- 글로벌 예외 처리: `ApiControllerAdvice`에서 `CoreException` → `ApiResponse` 변환 |
| 65 | + |
| 66 | +### BaseEntity (modules/jpa) |
| 67 | + |
| 68 | +모든 엔티티의 부모 클래스. Auto-increment ID, `createdAt`/`updatedAt`/`deletedAt` 자동 관리, `delete()`/`restore()` 소프트 삭제 지원. |
| 69 | + |
| 70 | +## Testing |
| 71 | + |
| 72 | +- 테스트는 `spring.profiles.active=test`, timezone `Asia/Seoul`, `maxParallelForks=1`로 실행 |
| 73 | +- **Testcontainers** 사용: MySQL, Redis, Kafka (각 모듈의 `testFixtures`에 설정 클래스 제공) |
| 74 | +- `DatabaseCleanUp` / `RedisCleanUp`: 테스트 후 데이터 정리 유틸리티 |
| 75 | +- 테스트 종류: 단위(Model/DTO), 통합(Service+Repository), E2E(TestRestTemplate) |
| 76 | +- 개발 완료된 API 의 경우, `.http/**.http` 에 분류해 작성 |
| 77 | + |
| 78 | +## Configuration |
| 79 | + |
| 80 | +- 프로파일: `local`, `test`, `dev`, `qa`, `prd` |
| 81 | +- 모듈별 설정 파일을 `spring.config.import`로 가져옴 (jpa.yml, redis.yml, kafka.yml, logging.yml, monitoring.yml) |
| 82 | +- 로컬 DB: `localhost:3307`, 계정 `application/application`, DB명 `loopers` |
| 83 | +- `.editorconfig`: 최대 줄 길이 130자 (테스트 파일은 제한 없음) |
| 84 | + |
| 85 | +## Rule |
| 86 | + |
| 87 | +### Code Writing |
| 88 | + |
| 89 | +- 내가 코드 작성하라고 명령하기 전에 코드 작성 절대 금지 |
| 90 | +- Example이 들어가는 파일들은 수정 금지 (참고만) |
| 91 | + |
| 92 | +### Feedback |
| 93 | + |
| 94 | +- 내 코드/아이디어에 무작정 동의하지 말고 객관적으로 피드백 ("이건 생각해봤어?" 식으로 유도) |
| 95 | +- 요구사항이 광범위하면 한 단계씩 점진적으로 진행 |
| 96 | + |
| 97 | +### Code Quality |
| 98 | + |
| 99 | +- 테스트 코드 작성하기 좋은 구조로 설계 |
| 100 | +- 테스트 코드가 필요한 곳이 있다면 알려줘 |
| 101 | +- null-safety: Optional 적극 활용 |
| 102 | +- 로그: println 금지, @Slf4j 사용 |
| 103 | + |
| 104 | +### TDD Workflow (Red > Green > Refactor) |
| 105 | + |
| 106 | +#### 1. Red Phase |
| 107 | + |
| 108 | +- 실패하는 테스트 먼저 작성 |
| 109 | +- 요구사항을 만족하는 기능 테스트 케이스 작성 |
| 110 | + |
| 111 | +#### 2. Green Phase |
| 112 | + |
| 113 | +- 테스트가 통과하는 최소한의 코드 작성 |
| 114 | +- 오버엔지니어링 금지 |
| 115 | + |
| 116 | +#### 3. Refactor Phase |
| 117 | + |
| 118 | +- 불필요한 코드 제거 및 품질 개선 |
| 119 | +- 객체지향적 코드 작성, 성능 최적화 |
| 120 | +- 모든 테스트 케이스가 통과해야 함 |
0 commit comments