-
⚡ FastAPI for the Python backend API.
- 🧰 SQLAlchemy for Python SQL Toolkit and Object Relational Mapper (ORM).
- 🔍 Pydantic for data validation and settings management.
- 💾 PostgreSQL as the SQL database.
- ⛁ Redis for in-memory caching and as a message broker for Celery.
- 🐍 Celery for background processing and task management.
- ⛃ SQLElectron - A simple and lightweight SQL client desktop/terminal with cross-database and platform support.
- 👮♂️ Postman for API testing and management.
- 🔁 Alembic as a lightweight database migration tool for SQLAlchemy.
-
🐋 Docker Compose for development and production.
-
🔒 Secure password hashing by default.
-
🔑 JWT (JSON Web Token) authentication.
-
📫 Email-based password recovery and verification.
-
📧 Email Authentication System: Users must verify their email addresses upon registration. An email containing a verification link is sent to the user's registered email address. The user must click the link to activate their account before logging in.
-
✅ Tests with Pytest.
- Middleware: Custom middleware is implemented for logging request and response details, helping to monitor the API's performance and usage.
- CORS: Cross-Origin Resource Sharing (CORS) is enabled to allow requests from various origins, ensuring that the API can be accessed from different client applications.
- A robust error handling mechanism is in place, providing meaningful error messages and status codes for various application-specific exceptions. This includes:
- User-related errors (e.g., user already exists, user not found).
- Token-related errors (e.g., invalid or revoked tokens).
- Permission-related errors (e.g., insufficient permissions).
- Resource-related errors (e.g., book or tag not found).
Celery is integrated into the Readify-Backend to handle asynchronous tasks and background processing. This allows the API to offload time-consuming operations, improving response times and overall user experience.
- Asynchronous Task Queue: Celery enables the execution of tasks in the background, freeing up the main thread to handle incoming requests.
- Task Scheduling: You can schedule tasks to run at specific intervals or times, making it ideal for repetitive jobs.
- Redis as Broker: Redis is used as the message broker, facilitating communication between the FastAPI app and Celery workers.
To set up Celery, ensure you have Redis running and then install the necessary dependencies:
pip install celery
Unit testing and mocking are essential for ensuring the reliability and correctness of your application. This project uses Pytest for testing.
- Install Dependencies:
Make sure you have the necessary testing libraries installed:
pip install pytest pytest-mock
To ensure consistent code formatting, this project uses Black. Install Black using pip:
pip install black
This project uses SQLAlchemy with connection pooling to manage database connections efficiently. The connection pooling parameters are configured in src/db/main.py
.
pool_size
: Number of connections to keep open inside the connection pool (default: 20).max_overflow
: Number of connections to allow in overflow (default: 10).pool_timeout
: Maximum number of seconds to wait for a connection to become available (default: 30).pool_recycle
: Number of seconds after which a connection is automatically recycled (default: 1800).
These parameters can be adjusted based on application's requirements and the database server's capacity.
This project uses aiocache for in-memory caching. To install aiocache
, run:
pip install aiocache
To avoid the N+1 query problem, this project uses eager loading with SQLAlchemy. Eager loading can be achieved using selectinload
or joinedload
options in your queries.
In src/books/routes.py
, the get_all_books
endpoint uses selectinload
to eagerly load the related Author
objects:
from sqlalchemy.future import select
from sqlalchemy.orm import selectinload
The Dockerfile sets up the environment for the Readify-Backend application. It utilizes a lightweight Python image and includes all necessary dependencies.
docker build -t fastapi-app .
docker run -p 8000:8000 fastapi-app