진짜 제품까지 가는 전체 그림
조각을 다 맞춰보자. aiosqlite를 쓰는 진짜 FastAPI 서비스는 결국 다섯 층으로 정리돼.
- Lifespan — 뜰 때 store를 열고 내려갈 때 닫아.
- Store — aiosqlite를 감싼 CRUD class야. SQL이 사는 유일한 자리지.
- Routes — FastAPI endpoint야. Depends로 store를 받아 메서드를 부르고 Pydantic model을 돌려줘.
- Models — request와 response 모양을 잡는 Pydantic schema야.
- Background task — 오래 걸리는 일, 예를 들어 embedding을 만들거나 인덱싱하는 건
asyncio.create_task나 작업 큐로 빼. request와 response 경로에는 두지 마.
Self-reference: 피파 backend가 딱 이 모양이야.
main.py가 lifespan을 맡고, store/conversations.py가 store를, routes/chat.py가 route를, routes/models.py 계열 파일이 Pydantic schema를, heartbeat scheduler가 오래 사는 백그라운드 task를 맡아.