1.4 KiB
1.4 KiB
Test Task CRM
FastAPI backend template that follows the architecture described in the system prompt: async SQLAlchemy ORM, Alembic-ready models, service/repository layers, JWT auth helpers, and Pydantic v2 schemas.
Quick start
- Create a
.envfile based on variables inapp/core/config.py. - Install dependencies:
uv sync - Run the development server:
uv run python main.py
Project layout
app/
api/ # FastAPI routers and dependencies
core/ # Settings, database, security helpers
models/ # SQLAlchemy models and Pydantic schemas
repositories/ # Data access layer (SQLAlchemy ORM usage)
services/ # Business logic (auth, users, etc.)
Add new routers under app/api/v1, repositories under app/repositories, and keep business rules inside app/services.
Redis analytics cache
Analytics endpoints can use a Redis cache (TTL 120 seconds). The cache is disabled by default, so the service falls back to the database.
- Start Redis and set the following variables:
REDIS_ENABLED=trueREDIS_URL=redis://localhost:6379/0ANALYTICS_CACHE_TTL_SECONDS(optional, defaults to 120)ANALYTICS_CACHE_BACKOFF_MS(max delay for write/delete retries, defaults to 200)
- When Redis becomes unavailable, middleware logs the degradation and responses transparently fall back to database queries until connectivity is restored.