o2o-negosium-original/lps/README.md
민헌 c4b8692f3a chore(lps): 시크릿용 .env 도입 — API 키(NAVER/OpenAI/Azure) 주입 경로
키는 코드/커밋이 아닌 환경변수로 주입한다(감사: 시크릿 하드코딩 금지).
config.local.toml=비-시크릿 설정, .env=시크릿으로 분리.

- .env.example(템플릿, 커밋) + .env(로컬, 미추적)로 키 슬롯 제공
  · NAVER_CLIENT_ID/SECRET(+로테이션 _2..), OPENAI_API_KEY, AZURE_OPENAI_*
- server_configs 가 기동 시 lps/.env 를 load_dotenv 로 환경변수 주입
- requirements: python-dotenv 추가
- README: .env 셋업 단계 안내

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-08 17:14:34 +09:00

60 lines
3.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# LPS (Lowest Price Search)
인터넷 최저가를 찾는 솔루션. **프레임워크는 `backend` 와 동일**하게 구성한 골격이며,
구체적인 도메인 로직(크롤링/오픈API 연동/최저가 산정 등)은 아직 정해지지 않았다.
## 스택 / 아키텍처 (backend 미러링)
- **FastAPI** 앱 (`router/router.py`) + `web_main.py` 부트스트랩
- **설정**: `config/` — TOML 로더(`config.local.toml`) + pydantic 모델, `APP_ENV`(기본 local)
- **DB**: `common/database/db_session_manager.py` — 논리 DB × Read/Write 엔진, service→람다 위임 패턴
- 엔진은 lazy 생성이라 **DB 없이도 부팅/healthz 동작**한다. 테이블·crud 가 생기면 그때 실제 접속.
- **공통 응답 규약**: `common/models/gmodel.py` — `Res_WebPacketProtocol.result`(성공/코드/설명)
- **결과 코드**: `common/enums.py` — `ErrorType`, `DBType`, `DBWRType`
- 계층 컨벤션: `router`(컨트롤러) → `services`(비즈니스) → `crud`(DB 접근)
## 폴더 구조
```
lps/
├── web_main.py # 진입점
├── requirements.txt / Dockerfile / .dockerignore
├── run_local_server.sh # 로컬 실행(대화형), 포트 9600
├── pytest.ini / conftest.py
├── config/
│ ├── config_loader.py / config_models.py / server_configs.py
│ └── config.local.toml.example # cp 해서 config.local.toml 로 사용(시크릿, 미커밋)
├── common/
│ ├── enums.py / logger.py / singleton.py
│ ├── utils/gtime.py
│ ├── models/gmodel.py # 프로토콜 base
│ └── database/{db_session_manager.py, model/models.py(MAIN_BASE)}
├── router/
│ ├── router.py # app + /healthz (도메인 라우터 미등록)
│ └── v1/validator/dependencies.py# RemoveNoneResponse
├── services/ # (비어있음) 도메인 서비스 추가 위치
├── crud/ # (비어있음) DB 접근 계층 추가 위치
└── tests/test_health.py # 스모크 테스트
```
## 로컬 실행
```bash
cp config/config.local.toml.example config/config.local.toml # DB 등 비-시크릿 설정
cp .env.example .env # 시크릿(API 키) — NAVER/OPENAI 등
./run_local_server.sh # → http://localhost:9600/docs
```
> `config.local.toml` = 비밀 아닌 설정(포트/DB), `.env` = 시크릿(API 키). 둘 다 git 미추적.
> 워커는 별도 프로세스: `python worker_main.py`
## 테스트
```bash
python -m pytest # tests/ (기본 healthz 스모크)
```
## 포트
- backend 9300 / negodata 9400 / agent 9500 과 겹치지 않도록 **LPS 는 9600** 사용.
## 새 도메인 추가 순서 (backend 컨벤션)
1. `common/database/model/models.py` 에 테이블 정의(+ `DBType`)
2. `crud/<domain>_crud.py` (ABC 인터페이스 + 구현)
3. `services/<domain>_service.py` (비즈니스 로직)
4. `router/v1/<domain>/{protocol.py, <domain>.py}` 작성 후 `router/router.py` 에서 `include_router`