How rishabhporwal/rag-chat-storage works
Project Type and Purpose
• This is a backend microservice built with FastAPI, intended to store and manage chat sessions/messages for a Retrieval-Augmented Generation chatbot.
• It exposes RESTful HTTP endpoints for session/message CRUD, pagination, favoriting, and renaming.
File Structure
• Top-level: configuration files (.env.example, Dockerfile, docker-compose.yml), entrypoint script (wait-for-postgres.sh), and tests.
• app/api/routes: HTTP route handlers (chat_session.py, chat_message.py).
• app/core: cross-cutting concerns (config, logging, rate limiting, security).
• app/db: database setup (SQLAlchemy base, init_db script, async session factory) and ORM models.
• app/schemas: Pydantic request/response schemas.
• app/services: business logic for sessions and messages.
• scripts/init_db.py: one-off DB initialization.
• Tests verify service layer.
Extract Key Architectural Insights from README
• Async design: FastAPI + asyncpg + SQLAlchemy (async)
• Containerized with Docker Compose: app container, Postgres container, PG Admin
• Environment-driven config (DATABASE_URL, RATE_LIMIT, API_KEY, LOG_LEVEL)
Main Components & Boundaries
1) Client / External Caller
• Any frontend or other microservice making HTTP calls.
2) API Layer (FastAPI / uvicorn)
• app/main.py launches the server.
• Routers in app/api/routes handle HTTP requests.
3) Core Utilities
• Configuration loader
• Logging
• Security (API key auth)
• Rate limiter
4) Business Logic Layer
• session_service & message_service implement use cases.
5) Data Access Layer
• SQLAlchemy async Session factory
• ORM models (chat_session, chat_message)
• scripts/init_db / app/db/init_db.py for migrations/seed
6) PostgreSQL Database
• Separate container instance (docker-compose).
7) Supporting Tools
• PG Admin (GUI in its own container)
• wait-for-postgres.sh ensures DB readiness
Component Interactions & Data Flows
• Client → (HTTP+JSON) → FastAPI Router
• Router applies security & rate-limit (via core/security, core/rate_limiter).
• Router → Pydantic Schema validation (app/schemas)
• Router → Service Layer (session_service or message_service)
• Service → Data Access Layer
• Obtain async DB session → perform CRUD via SQLAlchemy models → commit/return results
• Service → Router → JSON Response → Client
Architectural Patterns & Principles
• Layered (API → Services → Data) ensuring separation of concerns.
• Async I/O throughout (FastAPI, asyncpg, SQLAlchemy).
• Configuration via environment variables for 12-factor compliance.
• Containerized deployment (Docker Compose) for isolation.
Technologies & Frameworks to Annotate
• FastAPI / uvicorn
• Pydantic Schemas
• SQLAlchemy (Async) + asyncpg
• PostgreSQL
• Docker & Docker Compose
• Python (3.11+)
Final Checklist
• [ ] Call out key frameworks (FastAPI, SQLAlchemy).
• [ ] Show Docker Compose container boundaries and network.
• [ ] Note the wait-for-postgres startup step as a small annotation.