What you will have at the end
- A FastAPI service with OpenAPI docs
- Login, per-user data and rate limits
- Document upload → background ingestion → status
- A streaming /chat endpoint with structured logs and metrics
Step by step
- SkeletonFastAPI app, settings class, Docker Compose with Postgres and Redis, /health and /ready.
- Schemausers, documents, chunks, chats, messages with indexes on foreign keys and (chat_id, created_at).
- AuthRegister and login issuing short-lived JWTs; a current_user dependency on every protected route.
- Documents APIPresigned upload, complete endpoint, cursor-paginated list, per-user ownership checks, idempotency keys on create.
- WorkerIngestion job: download, parse, chunk, embed, insert in one transaction; status updates; retries with backoff.
- Streaming chatPOST /chat validates input, retrieves chunks, streams the answer via SSE with status and done events, records usage after.
- ProtectionRedis sliding-window rate limits per user and IP; cache for repeated embeddings.
- ObservabilityStructured JSON logs with request IDs, Prometheus metrics for latency, tokens and cost, Sentry for errors.
DONE WHEN
- A new user can sign up, upload a PDF, wait for "indexed" and chat with it
- Retrying an upload never creates duplicates
- Every log line for a request shares one request ID
Stretch goals
- Google login with OAuth
- WebSocket endpoint with cancel
- Row-level security per user