How jonra1993/fastapi-alembic-sqlmodel-async works
Project Type and Purpose
• This is a backend-focused, full-stack microservice template.
• It provides an async FastAPI REST API with JWT auth, role-based access control, SQLModel (SQLAlchemy) migrations (Alembic), object storage (Minio), a reverse proxy (Caddy), a task queue (Celery + Redis), and Docker Compose orchestration.
• It also includes testing, static analysis (SonarQube), and code-style tooling.
Key Components to Model
a. Reverse Proxy & Static Server
• Caddy container (Caddyfile)
• Serves /docs, /static, WebSocket endpoints
b. FastAPI Application
• API routers (app/api/v1/endpoints)
• Core modules (authz, security, config)
• CRUD layer, Pydantic/SQLModel schemas & SQLModel models
• Dependency injections
c. Persistence Layer
• PostgreSQL database (docker-compose, create-dbs.sql)
• Alembic migrations (alembic/versions)
d. Object Storage
• Minio container (S3-compatible buckets)
e. Async Tasks
• Celery workers + Celery Beat
• Redis broker & result backend
• Task definitions (celery_task.py, periodic_tasks endpoints)
f. Auxiliary Services
• pgAdmin (database GUI)
• SonarQube (static analysis)
• Local host environment variables (.env.example)
• Docker Compose files for dev, test, prod
Relationships & Data Flows
• Caddy ← HTTP/HTTPS → FastAPI
• FastAPI ←→ Postgres (SQLModel ORM)
• FastAPI ←→ Minio (via presigned URLs)
• FastAPI → Redis broker (enqueue tasks)
• Celery workers ← Redis broker & → Postgres (for task results via celery-sqlalchemy-scheduler)
• Celery Beat ← schedules tasks → Celery workers
• External clients ↔ WebSocket endpoint on FastAPI
Architectural Patterns & Design Principles
• Separation of Concerns: API, auth, data access, background tasks
• Dependency Injection: FastAPI Depends in deps.py modules
• Async Programming: Async SQLModel engine + async def endpoints
• Containerization: Each major component runs in a separate Docker container
• Infrastructure as Code: Docker Compose, Makefile, Caddyfile
• Environment variable dependency (.env) feeding into FastAPI & Celery
• Static hosting path (/static) on Caddy
• Alembic migrations interacting with Postgres
• Testing and CI/CD flows if desired (SonarQube, GitHub Actions)