Skip to content

Repository files navigation

πŸŽ“ Learning Platform API

Django CI Python Version Django Version DRF Version License

A comprehensive REST API for an online learning platform built with Django REST Framework. Features include course management, student enrollments, quizzes, progress tracking, and course ratings.

✨ Features

  • πŸ” Authentication: JWT-based authentication with role-based access (Students & Instructors)
  • πŸ“š Course Management: Create, update, and manage courses with categories and levels
  • πŸ“ Lessons: Organize course content with ordered lessons supporting video and text content
  • πŸ“Š Quizzes: Interactive quizzes with multiple choice and true/false questions
  • 🎯 Enrollments: Student enrollment system with progress tracking
  • ⭐ Ratings: Course rating and review system with average rating calculation
  • πŸš€ Throttling: Rate limiting to prevent API abuse
  • πŸ“– API Documentation: Interactive Swagger/OpenAPI documentation

πŸ› οΈ Tech Stack

  • Backend: Django 5.2.8 + Django REST Framework 3.16.1
  • Database: PostgreSQL 15
  • Authentication: JWT (djangorestframework-simplejwt)
  • API Documentation: drf-spectacular (Swagger/OpenAPI)
  • Web Server: Nginx (reverse proxy)
  • Containerization: Docker & Docker Compose
  • Testing: pytest + pytest-django
  • Code Quality: Black, Flake8

πŸ“‹ Prerequisites

  • Docker & Docker Compose
  • Git

πŸš€ Quick Start

1. Clone the repository

git clone https://github.com/snushev/learning-platform.git
cd learning-platform

2. Create environment file

cp .env.example .env

Edit .env and set your environment variables.

3. Build and run with Docker

docker-compose up --build

4. Create superuser

docker-compose exec web python manage.py createsuperuser

5. Access the application

πŸ“š API Endpoints

Authentication

  • POST /api/users/register/ - Register new user
  • POST /api/users/login/ - Login and get JWT tokens
  • POST /api/token/ - Get JWT token
  • POST /api/token/refresh/ - Refresh JWT token

Users

  • GET /api/users/profile/ - Get current user profile
  • PUT /api/users/profile/update/ - Update user profile

Courses

  • GET /api/courses/ - List all courses (with filtering & search)
  • POST /api/courses/ - Create course (instructors only)
  • GET /api/courses/{id}/ - Get course details
  • PUT /api/courses/{id}/ - Update course (owner only)
  • DELETE /api/courses/{id}/ - Delete course (owner only)

Categories

  • GET /api/categories/ - List all categories
  • POST /api/categories/ - Create category (admin only)

Lessons

  • GET /api/lessons/ - List lessons
  • GET /api/lessons/?course={id} - Filter lessons by course
  • POST /api/lessons/ - Create lesson (instructor only)
  • GET /api/lessons/{id}/ - Get lesson details
  • PUT /api/lessons/{id}/ - Update lesson
  • DELETE /api/lessons/{id}/ - Delete lesson

Enrollments

  • GET /api/enrollments/ - List my enrollments
  • POST /api/enrollments/ - Enroll in a course
  • GET /api/enrollments/{id}/ - Get enrollment details with progress
  • DELETE /api/enrollments/{id}/ - Unenroll from course
  • POST /api/enrollments/{id}/mark-lesson-viewed/ - Mark lesson as viewed

Quizzes

  • GET /api/quizzes/ - List quizzes
  • GET /api/quizzes/?course={id} - Filter quizzes by course
  • POST /api/quizzes/ - Create quiz (instructor only)
  • GET /api/quizzes/{id}/ - Get quiz details with questions

Quiz Attempts

  • GET /api/quiz-attempts/ - List my attempts
  • POST /api/quiz-attempts/ - Start quiz attempt
  • GET /api/quiz-attempts/{id}/ - Get attempt details
  • POST /api/quiz-attempts/{id}/submit/ - Submit quiz answers

Ratings

  • GET /api/ratings/ - List all ratings
  • GET /api/ratings/?course={id} - Filter ratings by course
  • POST /api/ratings/ - Rate a course (enrolled students only)
  • PUT /api/ratings/{id}/ - Update rating (owner only)
  • DELETE /api/ratings/{id}/ - Delete rating (owner only)

πŸ§ͺ Running Tests

# Run all tests
docker-compose exec web pytest

# Run with verbose output
docker-compose exec web pytest -v

# Run specific test file
docker-compose exec web pytest users/tests.py

# Run with coverage
docker-compose exec web pytest --cov=. --cov-report=html

πŸ”§ Development

Run locally (without Docker)

  1. Create virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  1. Install dependencies
pip install -r requirements.txt
  1. Set up database
# Start only PostgreSQL container
docker-compose up db

# Run migrations
python manage.py migrate
  1. Run development server
python manage.py runserver

Code Quality

# Format code with Black
black .

# Lint with Flake8
flake8 .

πŸ”’ Security Features

  • JWT token authentication
  • Role-based access control (Students & Instructors)
  • Rate limiting (100 requests/day for anonymous, 1000/day for authenticated)
  • Permission checks on all endpoints
  • Unique constraints to prevent duplicate enrollments/ratings

πŸ“Š Project Structure

learning-platform/
β”œβ”€β”€ config/              # Project settings
β”œβ”€β”€ users/               # User authentication & profiles
β”œβ”€β”€ courses/             # Course management
β”œβ”€β”€ lessons/             # Lesson content
β”œβ”€β”€ enrollments/         # Student enrollments & progress
β”œβ”€β”€ quizzes/             # Quiz system
β”œβ”€β”€ ratings/             # Course ratings & reviews
β”œβ”€β”€ nginx/               # Nginx configuration
β”œβ”€β”€ .github/workflows/   # CI/CD pipelines
β”œβ”€β”€ docker-compose.yml   # Docker services
β”œβ”€β”€ Dockerfile           # Django container
β”œβ”€β”€ requirements.txt     # Python dependencies
└── README.md

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License.

πŸ‘€ Author

Simeon Nushev

πŸ™ Acknowledgments

  • Built with Django REST Framework
  • API documentation powered by drf-spectacular
  • Containerized with Docker

Made with ❀️ by Simeon Nushev

About

Learning platform DRF backend project

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages