진짜 제품으로 scale 하는 end-to-end
조각 합치기: aiosqlite 쓰는 진짜 FastAPI 서비스가 명확한 5 레이어로 끝남.
- Lifespan — startup 에 store open, shutdown 에 close.
- Store — aiosqlite wrap CRUD class. SQL 사는 유일한 자리.
- Routes — FastAPI endpoint. Depends 로 store inject, method 호출, Pydantic model 반환.
- Models — request/response shape Pydantic schema.
- Background task — long-running (embedding 생성, 인덱싱) 은
asyncio.create_task또는 job queue, request/response path X.
Self-reference: 피파 backend 가 정확히 이 모양:
main.py 가 lifespan, store/conversations.py 가 store, routes/chat.py 가 route, routes/models.py-style 파일이 Pydantic schema, heartbeat scheduler 가 long-lived 백그라운드 task.