Backend — 핵심 구조 - xxriny/KNU-PROJECT GitHub Wiki

1. backend/version.py

라인 코드 설명
3 APP_VERSION = "2.2.0" 앱 버전
5 DEFAULT_MODEL = "gemini-2.5-flash" 기본 LLM 모델
6 DEFAULT_TEMPERATURE = 0.3 기본 temperature
7 MAX_LLM_RETRIES = 3 LLM 호출 최대 재시도

2. backend/requirements.txt

라인 패키지 역할
1–2 fastapi>=0.104.0, uvicorn[standard]>=0.24.0 HTTP 서버
3 websockets>=12.0 WS 통신
4 python-dotenv>=1.0.0 .env 로드
5 pydantic>=2.5.0 데이터 검증
6–8 langchain-google-genai, langgraph, google-genai LLM 파이프라인
9 networkx>=3.0 그래프 알고리즘
10 chromadb>=0.3.21 벡터 DB
11–12 structlog>=24.0.0, prometheus_client>=0.20.0 관측성

3. backend/pytest.ini

라인 코드 설명
1–4 testpaths, markers 테스트 디렉토리 test, regression 마커 정의

4. backend/main.py

라인 코드 설명
1–14 docstring 모듈 설명 — 계층 구조(transport/orchestration/result_shaping/observability), usage: python main.py --port 8765
16–23 import os, sys, argparse, asynccontextmanager, FastAPI, CORSMiddleware, APP_VERSION
26–28 경로 설정 ROOT 자동 감지, sys.path 등록
31–34 dotenv .env UTF-8 로드(ImportError 시 무시)
37–41 계층 임포트 rest_router, websocket_pipeline, make_metrics_app, get_logger
43 ALLOWED_ORIGIN_REGEX ^(null|https?://(127\.0\.0\.1|localhost)(:\d+)?)$ — CORS 정규식
47–49 lifespan asynccontextmanager — startup/shutdown 로그만 출력(DB 초기화 없음)
53–67 FastAPI 앱 app = FastAPI(title, version, lifespan), CORS(allow_origins=[], allow_origin_regex로 localhost만 허용)
70 라우터 등록 app.include_router(rest_router)
71 WS 라우트 app.add_api_websocket_route("/ws/pipeline", websocket_pipeline) — 경로 /ws/pipeline
74–76 Prometheus make_metrics_app()/metrics 마운트(설치 시 활성)
80–87 __main__ argparse--port(기본 8765)/--host(기본 127.0.0.1) 파싱, uvicorn.run()