Skip to content

thehimel/learning-platform-api

Repository files navigation

Learning Platform API

Python FastAPI Pydantic SQLAlchemy Alembic PostgreSQL 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

Features

  • Auth — Register, login (JWT), password update
  • UsersGET/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

Prerequisites

  • Python 3.14+
  • PostgreSQL
  • Docker (optional, for running PostgreSQL)

Quick Start

1. Clone and install

uv sync

2. Configure environment

Copy .env.example to .env and set required variables:

cp .env.example .env

Required: POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_DB, JWT_SECRET_KEY, AUTH_RESET_PASSWORD_TOKEN_SECRET, AUTH_VERIFICATION_TOKEN_SECRET. Generate secrets with openssl rand -hex 32.

3. Start PostgreSQL

docker compose up -d

4. Run migrations

alembic upgrade head

5. Start the API

uv run uvicorn app.main:app --reload

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

Commands

Command Purpose
uv sync Install dependencies (from pyproject.toml)
uv run uvicorn app.main:app --reload Run API (dev)
alembic upgrade head Apply migrations
alembic revision --autogenerate -m "message" Create migration
pytest Run tests
pytest -n auto Run tests in parallel (pytest-xdist)
pytest --drop-test-db Run tests and drop test DB after
ruff check . Lint
ruff format . Format

See docs/commands.md for Docker, pre-commit, and more.

API Overview

API endpoints overview

Interactive API docs: http://localhost:8000/docs

Testing

Tests use a separate DB ({postgres_db}_test). Migrations run automatically before tests.

pytest -v
pytest -n auto   # Parallel execution (pytest-xdist)

Unit, integration, E2E, security, and smoke tests. See docs/questions/test-types.md.

Documentation

System Diagram

diagram.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

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages