A learning platform API built with FastAPI. Supports courses, enrollments, ratings, and role-based access (student, instructor, admin).
- Framework: FastAPI
- Database: PostgreSQL (async via asyncpg)
- ORM: SQLAlchemy 2.0 (async)
- Auth: fastapi-users (JWT)
- Rate limiting: slowapi
- Logging: structlog
- Security headers: secure
- Auth: Register, login (JWT), password update
- Users:
GET/PATCH /me; admin CRUD for users - Courses: CRUD, list with pagination and filters (
published,qfor title search) - Enrollments: Enroll/unenroll in courses
- Ratings: Rate courses (1-5); aggregate recomputed asynchronously
- Visibility: Unauthenticated: published only; instructor: published + own unpublished; admin: all
uv syncCopy .env.example to .env and set POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_DB, JWT_SECRET_KEY, AUTH_RESET_PASSWORD_TOKEN_SECRET, and AUTH_VERIFICATION_TOKEN_SECRET. Generate secrets with openssl rand -hex 32.
cp .env.example .envStarts just the database, so the app runs on the host with uv run uvicorn app.main:app --reload.
docker compose up -d postgresdocker compose updocker compose downalembic upgrade headuv run uvicorn app.main:app --reloadAPI: http://localhost:8000 Docs: http://localhost:8000/docs
Tests use a separate database ({postgres_db}_test), created and migrated automatically.
pytest -v
# Parallel execution
pytest -n auto| Description | Command |
|---|---|
| Install dependencies (from pyproject.toml) | uv sync |
| Run API (dev) | uv run uvicorn app.main:app --reload |
| Apply migrations | alembic upgrade head |
| Create migration | alembic revision --autogenerate -m "message" |
| Run tests | pytest |
| Run tests in parallel (pytest-xdist) | pytest -n auto |
| Run tests and drop test DB after | pytest --drop-test-db |
| Lint | ruff check . |
| Format | ruff format . |
See docs/commands.md for Docker, pre-commit, and more.
- Commands: Docker, Alembic, pytest, ruff
- DB setup: Async SQLAlchemy and Alembic
- Auth options: Why fastapi-users
- Test types: Unit, integration, E2E
- Test speed: pytest performance notes
- Troubleshoot DB: Connection issues
- Steps: Project build order
Generated with Excalidraw
Generated with GitDiagram
Explore the detailed documentation for this project.
Generated with DeepWiki


