From b94e60d87b2c49d782596e8895d705a2332ed4c1 Mon Sep 17 00:00:00 2001 From: Claude-51124 Date: Tue, 23 Dec 2025 21:53:42 +0900 Subject: [PATCH] =?UTF-8?q?docs:=20router=20=ED=8C=8C=EC=9D=BC=20=EC=9D=98?= =?UTF-8?q?=EC=A1=B4=EC=84=B1=20=EC=A3=BC=EC=9E=85=20=ED=8C=A8=ED=84=B4=20?= =?UTF-8?q?=EC=9B=90=EC=B9=99=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- book/300_architecture/311_FastAPI_구조_원칙.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/book/300_architecture/311_FastAPI_구조_원칙.md b/book/300_architecture/311_FastAPI_구조_원칙.md index eef06cb..d454309 100644 --- a/book/300_architecture/311_FastAPI_구조_원칙.md +++ b/book/300_architecture/311_FastAPI_구조_원칙.md @@ -41,6 +41,13 @@ └── tests/ ``` +### main.py 역할 +- **앱 실행, 라우터 등록만** 담당 +- 엔드포인트 직접 정의 금지 (`@app.post()`, `@app.get()` 등) +- router 파일에서 main.py의 인스턴스(router, scheduler 등) 사용 시 의존성 주입 패턴 사용 + - 예: `set_router_instance()`, `set_scheduler()` 함수로 주입 + - router 파일에서 직접 import하지 않음 + ### 폴더 명명 규칙 - `router/` 또는 `api/`: HTTP 처리 - `services/`: 비즈니스 로직 @@ -132,6 +139,8 @@ utils ### 연결 방식 - **권장**: `db/database.py`에서 DB 세션 중앙 관리 (의존성 주입) +- **router 파일에서 main.py 인스턴스 사용**: `set_router_instance()`, `set_scheduler()` 같은 함수로 주입 + - 예: `system_endpoint.py`에서 router 인스턴스, `schedule_endpoint.py`에서 scheduler 인스턴스 - **간단한 경우**: `state/database.py`에서 직접 연결 ### Supabase 쿼리 컬럼명 충돌 처리