Skip to content

Repository files navigation

Learning Platform API

Python FastAPI Pydantic SQLAlchemy Alembic PostgreSQL structlog secure CI uv Ruff Vercel

A learning platform API built with FastAPI. Supports courses, enrollments, ratings, and role-based access (student, instructor, admin).

Tech Stack

  • Framework: FastAPI
  • Database: PostgreSQL (async via asyncpg)
  • ORM: SQLAlchemy 2.0 (async)
  • Auth: fastapi-users (JWT)
  • Rate limiting: slowapi
  • Logging: structlog
  • Security headers: secure

Features

  • Auth: Register, login (JWT), password update
  • Users: GET/PATCH /me; admin CRUD for users
  • Courses: CRUD, list with pagination and filters (published, q for 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

Project Setup

uv sync

Copy .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 .env

Run With Docker

Only PostgreSQL

Starts just the database, so the app runs on the host with uv run uvicorn app.main:app --reload.

docker compose up -d postgres

App and PostgreSQL Together

docker compose up

Stop the Containers

docker compose down

Database Migrations

alembic upgrade head

Run the App

uv run uvicorn app.main:app --reload

API: http://localhost:8000 Docs: http://localhost:8000/docs

API Overview

API endpoints overview

Run Tests

Tests use a separate database ({postgres_db}_test), created and migrated automatically.

pytest -v

# Parallel execution
pytest -n auto

Commands

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.

Documentation

System Diagram

system-diagram.svg

Generated with Excalidraw

Component Map

component-map.png

Generated with GitDiagram

Wiki

Explore the detailed documentation for this project.

wiki.png

Generated with DeepWiki

About

Learning platform API with FastAPI, PostgreSQL, and JWT auth. Courses, enrollments, ratings, and role-based access (student, instructor, admin).

Topics

Resources

Stars

39 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages