How igorbenav/sqlmodel-boilerplate works
Main components
• API Web Server – The core FastAPI application is defined under the “src/app” directory. It includes:
• The main entry point (src/app/main.py) that creates and configures the FastAPI app.
• API routes grouped by version (src/app/api/v1) such as login, logout, posts, users, rate limits, tasks, and tiers.
• Middleware and security (JWT authentication, refresh token handling, client-side cache middleware).
• Business Logic & Data Access – The project follows a clear separation of concerns:
• CRUD operations (in src/app/crud) that encapsulate database operations.
• Database models and SQLModel definitions (in src/app/models and src/app/core/db) that define schema and ORM behaviors.
• Pydantic validation models and exception handling (in src/app/core/schemas and src/app/core/exceptions).
• Database Layer – PostgreSQL is the relational database in use:
• Connection details and migrations (using Alembic in src/migrations) are specified.
• Caching & Rate Limiting – Redis is used in dual roles:
• Caching endpoints and client-side caching (modules in src/app/core/utils/cache and related settings in the .env).
• Rate limiter dependencies provided in the API endpoints (with corresponding models and utilities).
• Background Processing – ARQ is configured for running asynchronous background tasks:
• Worker functions and settings reside in src/app/core/worker.
• Deployment & Containerization – Docker is central:
• A Dockerfile, docker-compose.yml, and NGINX configuration (default.conf) illustrate containerization and reverse-proxy options.
• Testing – There is a separate tests directory for unit and integration tests.
Relationships and Interactions
• The FastAPI server makes database calls through the CRUD modules using SQLModel and async sessions (depicted between the API and PostgreSQL).
• When needed (such as caching responses or implementing rate limits), the API server interacts with Redis.
• When handling tasks (e.g., longer processes that run asynchronously), the API enqueues jobs via ARQ; the background worker (illustrated as a separate worker component) picks up these tasks.
• Optionally, include external routing by an NGINX reverse proxy as a façade in front of the API layer.
Architectural Patterns and Key Technologies
• That the project is fully asynchronous and relies on modern Python frameworks and libraries (FastAPI, SQLModel, Redis, ARQ).
• Client → FastAPI API server
• API server → PostgreSQL (via async DB sessions)
• API server → Redis (for caching, rate limiting)
• API server → ARQ worker (for enqueueing background tasks)
• ARQ worker → (optional) Database or external services if background tasks require further processing
• That the application runs inside Docker containers managed by Docker Compose.