# 공유는 추출보다 소비 계약이 먼저

> DB·UI·types·config 패키지와 turbo task·hash·env

- Canonical: https://learning.reopt.ai/en/courses/enterprise-monorepo/lessons/em-m2-concept
- Language: en
- HTML: https://learning.reopt.ai/en/courses/enterprise-monorepo/lessons/em-m2-concept

---

[Enterprise monorepo architecture](/en/courses/enterprise-monorepo) 2. 공유 패키지·캐시 파이프라인 3 / 9

# 공유는 추출보다 소비 계약이 먼저

DB·UI·types·config 패키지와 turbo task·hash·env
Concept 45 XP 9 min

DB·UI·types·config는 빌드와 exports 전략이 다릅니다. UI는 컴포넌트별 subpath, DB는 연결 수명을 통제한 함수 API, types/config는 얇은 기반 패키지가 적합합니다. Turborepo는 소스·의존성·task·env를 hash해 실행을 재사용합니다.
캐시는 숨은 입력까지 선언해야 안전하다 빌드 결과에 영향을 주는 env와 global dependency를 task inputs에 넣지 않으면 잘못된 결과를 재사용하는 cache poisoning이 생깁니다.

| 패키지 | Export 전략 | 운영 주의 |
| DB | getDb()·schema subpath | lazy init·global cache·migration 분리 |
| UI | component subpath | tree-shaking·CSS sideEffects |
| Types | source export | runtime dependency 금지 |
| Config | preset subpath | extends 방향·버전 영향 |

- 1 소비자 확인 중복보다 실제 app별 소비 계약을 먼저 봅니다.

- 2 Public API 제한 subpath export와 내부 구현 경계를 정합니다.

- 3 Task graph ^dependsOn과 package-local dependency를 구분합니다.

- 4 Hash 입력 env·lockfile·config·generated schema를 선언합니다.

실무에 남길 기준

- 공유 패키지는 코드 양보다 변경 책임과 소비 계약으로 만든다
- sideEffects:false 사용 시 global CSS 같은 필수 부작용을 예외로 보존한다
- cache hit는 빠름보다 동일 입력에 동일 결과라는 신뢰가 먼저다

[Previous](/en/courses/enterprise-monorepo/lessons/em-m1-quiz) Got it · Continue

---

Site guide for agents: https://learning.reopt.ai/llms.txt · Sitemap: https://learning.reopt.ai/sitemap.xml · Contact: https://learning.reopt.ai/contact
