Skip to content

Latest commit

Β 

History

289 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎬 Online Cinema Platform

codecov Python FastAPI PostgreSQL Docker License

A modern, production-ready online cinema platform with comprehensive API, automated deployment, and microservices architecture built with Python/FastAPI.

πŸ“‹ Table of Contents

🎯 Project Overview

Online Cinema Platform is a comprehensive cinema management system built with modern Python technologies and microservices architecture. The platform provides complete functionality for managing movies, users, payments, and content delivery in a scalable, production-ready environment.

This project demonstrates enterprise-level software development practices including:

  • Clean Architecture with separation of concerns
  • Async/Await patterns for high performance
  • Microservices design with Docker containerization
  • CI/CD Pipeline with GitHub Actions
  • Comprehensive Testing strategy (Unit/Integration/E2E)
  • Production Deployment with automated monitoring

πŸŽ₯ Who is this project for?

  • Backend Developers - Learning modern Python/FastAPI architecture patterns
  • Startups - Ready-to-use foundation for online cinema platforms
  • Students - Enterprise-level application example with best practices
  • DevOps Engineers - Reference CI/CD pipeline implementation
  • Technical Leads - Microservices architecture blueprint

✨ Key Features

πŸ” Authentication & Authorization

  • JWT-based Authentication with access/refresh token rotation
  • Role-based Access Control (User, Admin, Moderator)
  • Secure Registration/Login with bcrypt password hashing
  • Email Verification system with MailHog integration
  • OAuth2 Bearer token scheme with automatic expiration

🎬 Content Management System

  • Full Movie Management with CRUD operations (30KB+ codebase)
  • Category & Genre Classification with hierarchical structure
  • Rating & Review System with aggregated scores
  • Advanced Search & Filtering with multiple criteria
  • File Upload System via MinIO S3-compatible storage
  • Content Metadata management with rich descriptions

πŸ›’ E-commerce Functionality

  • Shopping Cart System with session persistence (6.8KB implementation)
  • Order Management with status tracking (4.7KB codebase)
  • Stripe Payment Integration with webhooks (5.9KB implementation)
  • Purchase History and invoice generation
  • Digital Content Delivery after successful payment

πŸ‘€ User Profile Management

  • Personal User Profiles with customizable settings (5.2KB)
  • Watchlist & Favorites with collection management
  • Viewing History with progress tracking
  • User Preferences and notification settings
  • Account Management comprehensive system (31KB codebase)

πŸ”§ Advanced Technical Features

  • Asynchronous Task Processing via Celery + Redis
  • Real-time Notifications with email templates
  • Smart Pagination for large datasets with FastAPI-pagination
  • Rate Limiting & Security with request throttling
  • Comprehensive Logging with structured data
  • Health Monitoring with automated alerts

πŸ—οΈ Architecture

πŸ”§ Technology Stack

πŸ”₯ Backend Core

  • FastAPI 0.115+ - Modern async web framework with automatic API docs
  • Python 3.10+ - Typed Python with async/await support
  • SQLAlchemy 2.0 - Async ORM with declarative models
  • Alembic - Database schema migrations management
  • Pydantic 2.0 - Data validation and serialization

πŸ—„οΈ Databases & Storage

  • PostgreSQL 15+ - Primary relational database
  • Redis 6.2+ - Caching and Celery message broker
  • MinIO - S3-compatible object storage for files
  • SQLite - Alternative database for testing

πŸ”’ Security & Authentication

  • JWT (python-jose) - Stateless authentication tokens
  • bcrypt - Secure password hashing
  • OAuth2 Bearer - Token-based authorization
  • CORS middleware - Cross-origin request security

⚑ Async & Background Processing

  • Celery 5.5+ - Distributed task queue system
  • Redis - Message broker and result backend
  • HTTPX - Async HTTP client for external APIs
  • asyncio - Native Python asynchronous programming

πŸ§ͺ Testing & Quality Assurance

  • pytest 8.3+ - Test framework with async support
  • pytest-cov - Code coverage reporting
  • mypy - Static type checking
  • flake8 - Code style linting
  • codecov - Coverage tracking and reporting

🐳 DevOps & Infrastructure

  • Docker & Docker Compose - Containerization and orchestration
  • GitHub Actions - CI/CD pipeline automation
  • Nginx - Reverse proxy and static file serving
  • Gunicorn + Uvicorn - ASGI production server

πŸ’³ External Integrations

  • Stripe API - Payment processing and webhooks
  • MailHog - Email testing in development environment
  • boto3/aioboto3 - AWS S3 compatibility (MinIO integration)

πŸ“ Project Structure

Online-Cinema-Project/
β”œβ”€β”€ πŸš€ src/                              # Main application source code
β”‚   β”œβ”€β”€ πŸ“± main.py                       # FastAPI application entry point (126 lines)
β”‚   β”œβ”€β”€ βš™οΈ  config/                      # Application configuration
β”‚   β”‚   β”œβ”€β”€ settings.py                  # Environment-based settings
β”‚   β”‚   └── dependencies.py              # Dependency injection setup
β”‚   β”œβ”€β”€ πŸ—„οΈ  database/                    # Database layer
β”‚   β”‚   β”œβ”€β”€ __init__.py                  # Database initialization (996B)
β”‚   β”‚   β”œβ”€β”€ models/                      # SQLAlchemy ORM models
β”‚   β”‚   β”‚   β”œβ”€β”€ base.py                  # Base model class (149B)
β”‚   β”‚   β”‚   β”œβ”€β”€ accounts.py              # User & authentication models (7.9KB)
β”‚   β”‚   β”‚   β”œβ”€β”€ movies.py                # Movie catalog models (5.5KB)
β”‚   β”‚   β”‚   β”œβ”€β”€ orders.py                # Order management models (1.8KB)
β”‚   β”‚   β”‚   β”œβ”€β”€ payments.py              # Payment transaction models (2.2KB)
β”‚   β”‚   β”‚   β”œβ”€β”€ shopping_cart.py         # Shopping cart models (1.5KB)
β”‚   β”‚   β”‚   β”œβ”€β”€ comments.py              # Review & comment models (1.9KB)
β”‚   β”‚   β”‚   └── extra_functionality_movie.py # Extended movie features (2.0KB)
β”‚   β”‚   β”œβ”€β”€ migrations/                  # Alembic database migrations
β”‚   β”‚   β”‚   └── versions/                # Migration version files
β”‚   β”‚   β”œβ”€β”€ validators/                  # Database-level validators
β”‚   β”‚   β”œβ”€β”€ pagination/                  # Custom pagination logic
β”‚   β”‚   β”œβ”€β”€ seed_data/                   # Initial data for development
β”‚   β”‚   β”œβ”€β”€ source/                      # Data source utilities
β”‚   β”‚   β”œβ”€β”€ session_postgresql.py        # PostgreSQL session config (1.9KB)
β”‚   β”‚   β”œβ”€β”€ session_sqlite.py            # SQLite session config (2.0KB)
β”‚   β”‚   β”œβ”€β”€ db_sync.py                   # Sync database utilities (460B)
β”‚   β”‚   └── populate.py                  # Database seeding script (17KB)
β”‚   β”œβ”€β”€ 🌐 routes/                       # API endpoint definitions
β”‚   β”‚   β”œβ”€β”€ __init__.py                  # Router exports (475B)
β”‚   β”‚   β”œβ”€β”€ accounts.py                  # Authentication endpoints (31KB, 926 lines)
β”‚   β”‚   β”œβ”€β”€ movies.py                    # Movie management API (30KB, 1007 lines)
β”‚   β”‚   β”œβ”€β”€ extra_functionality_movie.py # Extended movie features (14KB, 454 lines)
β”‚   β”‚   β”œβ”€β”€ shopping_cart.py             # Shopping cart API (6.8KB, 224 lines)
β”‚   β”‚   β”œβ”€β”€ payments.py                  # Stripe payment endpoints (5.9KB, 188 lines)
β”‚   β”‚   β”œβ”€β”€ profiles.py                  # User profile management (5.2KB, 149 lines)
β”‚   β”‚   β”œβ”€β”€ orders.py                    # Order processing API (4.7KB, 123 lines)
β”‚   β”‚   └── comments.py                  # Comment & review API (2.8KB, 96 lines)
β”‚   β”œβ”€β”€ πŸ“‹ schemas/                      # Pydantic data validation schemas
β”‚   β”‚   β”œβ”€β”€ __init__.py                  # Schema exports (808B)
β”‚   β”‚   β”œβ”€β”€ movies.py                    # Movie data schemas (6.2KB, 251 lines)
β”‚   β”‚   β”œβ”€β”€ payments.py                  # Payment validation schemas (2.5KB, 99 lines)
β”‚   β”‚   β”œβ”€β”€ accounts.py                  # User account schemas (1.8KB, 86 lines)
β”‚   β”‚   β”œβ”€β”€ profiles.py                  # Profile management schemas (1.6KB, 66 lines)
β”‚   β”‚   β”œβ”€β”€ shopping_cart.py             # Cart validation schemas (1.3KB, 51 lines)
β”‚   β”‚   β”œβ”€β”€ orders.py                    # Order processing schemas (1.0KB, 43 lines)
β”‚   β”‚   β”œβ”€β”€ comments.py                  # Comment schemas (795B, 44 lines)
β”‚   β”‚   β”œβ”€β”€ extra_functionality_movie.py # Extended feature schemas (669B, 32 lines)
β”‚   β”‚   └── examples/                    # Schema example data
β”‚   β”œβ”€β”€ πŸ”’ security/                     # Authentication & authorization
β”‚   β”‚   β”œβ”€β”€ auth.py                      # JWT token management
β”‚   β”‚   β”œβ”€β”€ permissions.py               # Role-based access control
β”‚   β”‚   └── utils.py                     # Security utility functions
β”‚   β”œβ”€β”€ πŸ’Ύ storages/                     # External storage integrations
β”‚   β”‚   β”œβ”€β”€ minio_client.py              # MinIO S3-compatible storage
β”‚   β”‚   └── file_manager.py              # File upload/download logic
β”‚   β”œβ”€β”€ πŸ“§ notifications/                # Notification system
β”‚   β”‚   β”œβ”€β”€ email_service.py             # Email sending logic
β”‚   β”‚   └── templates/                   # Email HTML templates
β”‚   β”œβ”€β”€ ⚑ celery_config/                # Background task processing
β”‚   β”‚   β”œβ”€β”€ celery_worker.py             # Celery worker configuration
β”‚   β”‚   └── tasks.py                     # Async task definitions
β”‚   β”œβ”€β”€ πŸ” validation/                   # Business logic validation
β”‚   β”‚   └── business_rules.py            # Custom validation rules
β”‚   β”œβ”€β”€ 🚨 exceptions/                   # Custom exception handling
β”‚   β”‚   β”œβ”€β”€ base.py                      # Base exception classes
β”‚   β”‚   └── handlers.py                  # FastAPI exception handlers
β”‚   β”œβ”€β”€ πŸ§ͺ tests/                        # Application test suite
β”‚   β”‚   β”œβ”€β”€ conftest.py                  # Pytest configuration (11KB, 350 lines)
β”‚   β”‚   β”œβ”€β”€ unit/                        # Unit tests for individual components
β”‚   β”‚   β”œβ”€β”€ test_integration/            # Integration tests for services
β”‚   β”‚   β”œβ”€β”€ test_e2e/                    # End-to-end API tests
β”‚   β”‚   └── doubles/                     # Test doubles (mocks, stubs, fakes)
β”‚   β”‚       β”œβ”€β”€ fakes/                   # Fake implementations for testing
β”‚   β”‚       └── stubs/                   # Method stubs for isolation
β”‚   └── πŸ› οΈ  services/                    # Business logic layer
β”‚       β”œβ”€β”€ __init__.py                  # Service exports (59B)
β”‚       β”œβ”€β”€ shopping_cart.py             # Cart business logic (5.8KB, 163 lines)
β”‚       β”œβ”€β”€ orders.py                    # Order processing logic (4.3KB, 120 lines)
β”‚       └── payments/                    # Payment service modules
β”œβ”€β”€ 🐳 docker/                           # Docker configuration files
β”‚   β”œβ”€β”€ nginx/                           # Nginx reverse proxy setup
β”‚   β”‚   β”œβ”€β”€ Dockerfile                   # Nginx container build
β”‚   β”‚   └── .env                         # Nginx environment variables
β”‚   β”œβ”€β”€ mailhog/                         # Email testing service
β”‚   β”‚   └── Dockerfile                   # MailHog container setup
β”‚   β”œβ”€β”€ minio_mc/                        # MinIO client configuration
β”‚   β”‚   └── Dockerfile                   # MinIO management client
β”‚   └── tests/                           # Test environment containers
β”‚       └── Dockerfile                   # Test runner container
β”œβ”€β”€ βš™οΈ  configs/                         # External service configurations
β”‚   └── nginx/                           # Nginx configuration files
β”‚       └── nginx.conf                   # Production Nginx config
β”œβ”€β”€ πŸ› οΈ  commands/                        # Automation and deployment scripts
β”‚   β”œβ”€β”€ deploy.sh                        # Production deployment script
β”‚   β”œβ”€β”€ check-status.sh                  # Health check and monitoring
β”‚   β”œβ”€β”€ setup-server.sh                  # Initial server configuration
β”‚   β”œβ”€β”€ run_web_server_prod.sh           # Production server startup
β”‚   β”œβ”€β”€ run_migration.sh                 # Database migration runner
β”‚   └── setup_minio.sh                   # MinIO bucket initialization
β”œβ”€β”€ πŸ”„ .github/                          # GitHub Actions CI/CD
β”‚   └── workflows/                       # Automated workflows
β”‚       └── cd.yml                       # Continuous deployment pipeline
β”œβ”€β”€ πŸ“Š tests/                            # Additional test suites
β”‚   β”œβ”€β”€ conftest.py                      # Global test configuration
β”‚   └── unit/                            # Top-level unit tests
β”œβ”€β”€ πŸ“„ Configuration Files               # Project configuration
β”‚   β”œβ”€β”€ docker-compose-dev.yml           # Development environment (4.0KB)
β”‚   β”œβ”€β”€ docker-compose-prod.yml          # Production environment (4.8KB)
β”‚   β”œβ”€β”€ docker-compose-tests.yml         # Testing environment (2.4KB)
β”‚   β”œβ”€β”€ Dockerfile                       # Main application container (1.2KB)
β”‚   β”œβ”€β”€ alembic.ini                      # Database migration config (3.9KB)
β”‚   β”œβ”€β”€ pyproject.toml                   # Python dependencies & config (1.6KB)
β”‚   β”œβ”€β”€ poetry.lock                      # Locked dependency versions (311KB)
β”‚   β”œβ”€β”€ pytest.ini                       # Test runner configuration
β”‚   β”œβ”€β”€ .env.example                     # Environment variables template
β”‚   β”œβ”€β”€ .flake8                          # Code style configuration
β”‚   β”œβ”€β”€ .codecov.yml                     # Coverage reporting config
β”‚   β”œβ”€β”€ .gitignore                       # Git ignore patterns
β”‚   └── init.sql                         # Database initialization script
└── πŸ“š Documentation                     # Project documentation
    β”œβ”€β”€ README.md                        # This comprehensive guide
    └── DEPLOYMENT.md                    # Deployment documentation (if exists)

πŸ“Š Code Metrics Summary

Component Files Lines of Code Size Purpose
Routes 9 files ~3,500 lines ~120KB API endpoint definitions
Models 8 files ~650 lines ~23KB Database schema definitions
Schemas 9 files ~770 lines ~16KB Data validation & serialization
Services 3 files ~400 lines ~10KB Business logic implementation
Tests Multiple ~2,000+ lines ~50KB+ Comprehensive test coverage
Config 10+ files ~500 lines ~20KB Infrastructure & deployment

πŸš€ Quick Start

πŸ“‹ Prerequisites

  • Python 3.10+ installed on your system
  • Docker & Docker Compose for containerization
  • Poetry for Python dependency management
  • Git for version control
  • 8GB+ RAM recommended for full stack

πŸ”§ Local Development Setup

  1. Clone the Repository
git clone https://github.com/iSevenpwnz/Online-Cinema-Project.git
cd Online-Cinema-Project
  1. Environment Configuration
# Copy environment template
cp .env.example .env

# Edit environment variables
nano .env  # or use your preferred editor
  1. Install Dependencies
# Using Poetry (recommended)
poetry install
poetry shell

# Or using pip
pip install -r requirements.txt
  1. Start Development Environment
# Launch all services with Docker Compose
docker-compose -f docker-compose-dev.yml up -d

# Check service status
docker-compose -f docker-compose-dev.yml ps
  1. Initialize Database
# Run database migrations
docker-compose -f docker-compose-dev.yml exec web alembic upgrade head

# Seed initial data (optional)
docker-compose -f docker-compose-dev.yml exec web python -m database.populate
  1. Access the Services
Service URL Purpose
API Documentation http://localhost:8000/api/v1/docs Interactive Swagger UI
Main Application http://localhost:8000 FastAPI backend
PgAdmin http://localhost:3333 Database management
MailHog http://localhost:8025 Email testing interface
MinIO Console http://localhost:9001 Object storage management
RedisInsight http://localhost:5540 Redis database viewer

πŸ”§ Configuration

🌍 Environment Variables

Create a .env file based on .env.example with the following configuration:

# Database Configuration
POSTGRES_DB=movies_db
POSTGRES_USER=admin
POSTGRES_PASSWORD=your_secure_password_here
POSTGRES_HOST=postgres_theater
POSTGRES_DB_PORT=5432

# JWT Security Configuration
SECRET_KEY_ACCESS=your_access_secret_key_minimum_32_characters
SECRET_KEY_REFRESH=your_refresh_secret_key_minimum_32_characters
JWT_SIGNING_ALGORITHM=HS256

# Email Configuration (MailHog for development)
EMAIL_HOST=mailhog_theater
EMAIL_PORT=1025
EMAIL_HOST_USER=testuser
EMAIL_HOST_PASSWORD=test_password
EMAIL_USE_TLS=False

# Object Storage Configuration (MinIO)
MINIO_ROOT_USER=minioadmin
MINIO_ROOT_PASSWORD=your_minio_password_here
MINIO_HOST=minio-theater
MINIO_PORT=9000
MINIO_STORAGE=theater-storage

# Payment Integration (Stripe)
STRIPE_SECRET_KEY=sk_test_your_stripe_secret_key
STRIPE_PUBLISHABLE_KEY=pk_test_your_stripe_publishable_key

# Redis Configuration
REDIS_HOST=redis_theater
REDIS_PORT=6379
REDIS_DB=0

# Application Settings
LOG_LEVEL=debug
ENVIRONMENT=development
API_V1_PREFIX=/api/v1

πŸ”’ Security Configuration

JWT Token Settings

# Token expiration times
ACCESS_TOKEN_EXPIRE_MINUTES = 30
REFRESH_TOKEN_EXPIRE_DAYS = 7

# Algorithm and key requirements
JWT_ALGORITHM = "HS256"
SECRET_KEY_LENGTH_MINIMUM = 32  # characters

CORS Configuration

# Allowed origins for CORS
BACKEND_CORS_ORIGINS = [
    "http://localhost:3000",  # React frontend
    "http://localhost:8080",  # Vue frontend
    "https://yourdomain.com"  # Production domain
]

πŸ“š API Documentation

πŸ”— Interactive Documentation

The API provides comprehensive interactive documentation:

🎯 Core API Endpoints

πŸ” Authentication System (/api/v1/accounts/)

Method Endpoint Description Auth Required
POST /register/ Create new user account ❌
POST /login/ Login and get JWT tokens ❌
POST /refresh/ Refresh access token ❌
POST /logout/ Logout current user βœ…
GET /profile/ Get current user profile βœ…
PUT /profile/ Update user profile βœ…
POST /verify-email/ Verify email address ❌
POST /forgot-password/ Request password reset ❌
POST /reset-password/ Reset password with token ❌

🎬 Movie Management (/api/v1/theater/)

Method Endpoint Description Auth Required Admin Only
GET /movies/ List movies with filters ❌ ❌
POST /movies/ Create new movie βœ… βœ…
GET /movies/{id}/ Get movie details ❌ ❌
PUT /movies/{id}/ Update movie βœ… βœ…
DELETE /movies/{id}/ Delete movie βœ… βœ…
GET /genres/ List all genres ❌ ❌
GET /categories/ List all categories ❌ ❌
POST /movies/{id}/upload-poster/ Upload movie poster βœ… βœ…

πŸ›’ Shopping Cart (/shopping-cart/)

Method Endpoint Description Auth Required
GET /cart/ Get current cart βœ…
POST /cart/add/ Add movie to cart βœ…
PUT /cart/update/{item_id}/ Update cart item βœ…
DELETE /cart/remove/{item_id}/ Remove from cart βœ…
POST /cart/checkout/ Proceed to checkout βœ…
DELETE /cart/clear/ Clear entire cart βœ…

πŸ’³ Payment Processing (/api/v1/payments/)

Method Endpoint Description Auth Required
POST /create-intent/ Create Stripe payment intent βœ…
POST /confirm/ Confirm payment βœ…
GET /history/ Get payment history βœ…
POST /webhook/ Stripe webhook handler ❌
GET /receipt/{payment_id}/ Get payment receipt βœ…

πŸ“¦ Order Management (/api/v1/orders/)

Method Endpoint Description Auth Required
GET / List user orders βœ…
POST / Create new order βœ…
GET /{order_id}/ Get order details βœ…
PUT /{order_id}/status/ Update order status βœ…
GET /{order_id}/invoice/ Download invoice βœ…

πŸ“ Comments & Reviews (/api/v1/comments/)

Method Endpoint Description Auth Required
GET /movie/{movie_id}/ Get movie comments ❌
POST /movie/{movie_id}/ Add comment/review βœ…
PUT /{comment_id}/ Edit comment βœ…
DELETE /{comment_id}/ Delete comment βœ…
POST /{comment_id}/like/ Like/unlike comment βœ…

πŸ”’ Authentication Usage

Most endpoints require JWT authentication. Here's how to use it:

  1. Register or Login
# Register new user
curl -X POST "http://localhost:8000/api/v1/accounts/register/" \
     -H "Content-Type: application/json" \
     -d '{
       "email": "user@example.com",
       "password": "secure_password123",
       "username": "moviefan"
     }'

# Login to get tokens
curl -X POST "http://localhost:8000/api/v1/accounts/login/" \
     -H "Content-Type: application/json" \
     -d '{
       "email": "user@example.com",
       "password": "secure_password123"
     }'
  1. Use Access Token
# Include token in Authorization header
curl -X GET "http://localhost:8000/api/v1/theater/movies/" \
     -H "Authorization: Bearer YOUR_ACCESS_TOKEN"
  1. Refresh Token When Expired
curl -X POST "http://localhost:8000/api/v1/accounts/refresh/" \
     -H "Content-Type: application/json" \
     -d '{"refresh_token": "YOUR_REFRESH_TOKEN"}'

πŸ’» Usage Guide

🎬 Complete Movie Management Workflow

  1. Admin: Add New Movie
curl -X POST "http://localhost:8000/api/v1/theater/movies/" \
     -H "Authorization: Bearer ADMIN_TOKEN" \
     -H "Content-Type: application/json" \
     -d '{
       "title": "The Matrix",
       "description": "A computer hacker learns from mysterious rebels about the true nature of his reality.",
       "genre": "Sci-Fi",
       "duration": 136,
       "price": 12.99,
       "release_date": "1999-03-31"
     }'
  1. User: Browse Movies
# Get movies with filters
curl "http://localhost:8000/api/v1/theater/movies/?genre=Sci-Fi&min_price=5&max_price=20&page=1&size=10"
  1. User: Add to Cart
curl -X POST "http://localhost:8000/shopping-cart/cart/add/" \
     -H "Authorization: Bearer USER_TOKEN" \
     -H "Content-Type: application/json" \
     -d '{
       "movie_id": 1,
       "quantity": 1
     }'
  1. User: Checkout Process
# Create payment intent
curl -X POST "http://localhost:8000/api/v1/payments/create-intent/" \
     -H "Authorization: Bearer USER_TOKEN" \
     -H "Content-Type: application/json" \
     -d '{
       "amount": 1299,
       "currency": "usd"
     }'

# Confirm payment (after Stripe processing)
curl -X POST "http://localhost:8000/api/v1/payments/confirm/" \
     -H "Authorization: Bearer USER_TOKEN" \
     -H "Content-Type: application/json" \
     -d '{
       "payment_intent_id": "pi_1234567890"
     }'

πŸ› οΈ Development Workflow

  1. Running Tests During Development
# Run specific test categories
pytest src/tests/unit/ -v                    # Unit tests only
pytest src/tests/test_integration/ -v        # Integration tests
pytest src/tests/test_e2e/ -v               # End-to-end tests

# Run with coverage
pytest --cov=src --cov-report=html

# Run tests in parallel
pytest -n auto
  1. Database Management
# Create new migration
docker-compose -f docker-compose-dev.yml exec web alembic revision --autogenerate -m "Add new feature"

# Apply migrations
docker-compose -f docker-compose-dev.yml exec web alembic upgrade head

# Rollback migration
docker-compose -f docker-compose-dev.yml exec web alembic downgrade -1
  1. Monitoring Logs
# View application logs
docker-compose -f docker-compose-dev.yml logs -f web

# View specific service logs
docker-compose -f docker-compose-dev.yml logs -f postgres_theater
docker-compose -f docker-compose-dev.yml logs -f redis_theater
docker-compose -f docker-compose-dev.yml logs -f celery_worker_theater

πŸ”„ Background Tasks with Celery

The platform uses Celery for handling asynchronous tasks:

  1. Email Notifications
# Send welcome email (triggered automatically)
from celery_config.tasks import send_welcome_email
send_welcome_email.delay(user_id=123)
  1. Order Processing
# Process order after payment (automatic)
from celery_config.tasks import process_order
process_order.delay(order_id=456)
  1. Monitor Celery Workers
# Check worker status
docker-compose -f docker-compose-dev.yml exec celery_worker celery -A celery_config.celery_worker.celery_app status

# Monitor tasks
docker-compose -f docker-compose-dev.yml exec celery_worker celery -A celery_config.celery_worker.celery_app events

πŸ§ͺ Testing

πŸƒβ€β™‚οΈ Running Tests

# Run all tests
pytest

# Run with coverage report
pytest --cov=src --cov-report=html --cov-report=term

# Run specific test types
pytest src/tests/unit/                    # Unit tests
pytest src/tests/test_integration/        # Integration tests
pytest src/tests/test_e2e/               # End-to-end tests

# Run tests in parallel (faster)
pytest -n auto

# Run specific test file
pytest src/tests/unit/test_accounts.py -v

# Run tests matching pattern
pytest -k "test_login" -v

πŸ“Š Test Coverage

The project maintains comprehensive test coverage:

  • Unit Tests: Individual functions and methods
  • Integration Tests: Service interactions and database operations
  • End-to-End Tests: Complete API workflows
  • Mock Tests: External service integrations
# Generate detailed HTML coverage report
pytest --cov=src --cov-report=html
open htmlcov/index.html  # View in browser

🐳 Testing in Docker Environment

# Run tests in isolated container
docker-compose -f docker-compose-tests.yml up --build test_runner

# Run specific test suite in container
docker-compose -f docker-compose-tests.yml exec test_runner pytest src/tests/unit/ -v

βœ… Test Categories

Test Type Location Purpose Coverage
Unit src/tests/unit/ Individual component testing Functions, methods, utilities
Integration src/tests/test_integration/ Service interaction testing Database, external APIs
E2E src/tests/test_e2e/ Complete workflow testing User journeys, API flows
Contract src/tests/doubles/ Mock and stub testing External dependencies

🚒 Deployment

πŸ”„ Automated CI/CD Pipeline

The project includes a fully automated deployment pipeline using GitHub Actions:

Triggers:

  • Push to develop or cd-setting branches
  • Pull request merges to these branches
  • Manual workflow dispatch

Pipeline Features:

  • βœ… Concurrency Control - Prevents simultaneous deployments
  • βœ… Deployment Locks - Server-side conflict prevention
  • βœ… Health Checks - Post-deployment verification
  • βœ… Rollback Support - Automatic failure recovery
  • βœ… Timeout Protection - 30-minute deployment limit

πŸ”§ GitHub Secrets Configuration

Configure these secrets in your GitHub repository:

  1. Go to Settings β†’ Secrets and variables β†’ Actions
  2. Add the following Repository secrets:
EC2_HOST=your.server.ip.address          # Production server IP
EC2_USER=ubuntu                          # SSH username
EC2_SSH_KEY=-----BEGIN RSA PRIVATE KEY----- # SSH private key

πŸ–₯️ Manual Deployment

For manual deployment to production server:

# SSH to production server
ssh ubuntu@your-server-ip

# Navigate to project directory
cd /home/ubuntu/src/online-cinema-project

# Deploy specific branch
bash commands/deploy.sh develop

# Check deployment status
bash commands/check-status.sh

πŸ—οΈ Initial Server Setup

For first-time server configuration:

# Run automated setup script
ssh ubuntu@your-server-ip
bash /home/ubuntu/src/online-cinema-project/commands/setup-server.sh

This script will:

  • Install Docker and Docker Compose
  • Configure firewall rules
  • Set up project directory structure
  • Install system dependencies
  • Configure environment variables

πŸ“‹ Production Deployment Checklist

Before deploying to production:

  • SSL Certificates configured and valid
  • Firewall Rules properly configured
  • Database Backups strategy implemented
  • Environment Variables secured and verified
  • Domain Configuration with proper DNS
  • Monitoring System active and alerting
  • Log Rotation configured for disk management
  • Security Updates applied to server
  • Performance Testing completed
  • Backup Recovery procedure tested

πŸ”§ Production Environment Variables

Additional variables for production:

# Production-specific settings
ENVIRONMENT=production
DEBUG=False
LOG_LEVEL=info

# Database connection pooling
DATABASE_POOL_SIZE=20
DATABASE_MAX_OVERFLOW=30
DATABASE_POOL_TIMEOUT=30

# Security settings
SECURE_COOKIES=True
HTTPS_ONLY=True
CORS_ORIGINS=["https://yourdomain.com"]

# Performance settings
WORKERS=4
MAX_CONNECTIONS=1000
KEEPALIVE_TIMEOUT=2

πŸ“Š Monitoring

πŸ” Health Monitoring

The platform includes comprehensive health monitoring:

# Run complete health check
bash commands/check-status.sh

This script monitors:

  • βœ… Deployment Lock Status - No conflicting deployments
  • βœ… Docker Container Health - All services running
  • βœ… Database Connectivity - PostgreSQL connection
  • βœ… Redis Availability - Cache and message broker
  • βœ… External Services - MinIO, MailHog, Nginx
  • βœ… System Resources - CPU, Memory, Disk usage
  • βœ… Application Logs - Error detection

πŸ“ˆ Service Monitoring Dashboards

Service URL Purpose
PgAdmin http://localhost:3333 Database monitoring and management
RedisInsight http://localhost:5540 Redis monitoring and debugging
MinIO Console http://localhost:9001 Object storage monitoring
MailHog http://localhost:8025 Email delivery monitoring

🚨 Log Management

# Application logs
docker-compose logs -f web

# Database logs
docker-compose logs -f postgres_theater

# Background task logs
docker-compose logs -f celery_worker_theater

# Reverse proxy logs
docker-compose logs -f nginx

# All service logs
docker-compose logs -f

πŸ“Š Performance Metrics

Monitor key performance indicators:

  • Response Times - API endpoint performance
  • Database Queries - Query execution time
  • Memory Usage - Container resource consumption
  • Disk Space - Database and file storage
  • Network Traffic - Request/response volumes
  • Error Rates - Application and system errors

🀝 Contributing

πŸ”„ Development Workflow

  1. Fork the Repository
git clone https://github.com/YOUR_USERNAME/Online-Cinema-Project.git
cd Online-Cinema-Project
  1. Create Feature Branch
git checkout -b feature/amazing-new-feature
  1. Set Up Development Environment
poetry install
docker-compose -f docker-compose-dev.yml up -d
  1. Make Changes and Test
# Run tests
pytest --cov=src

# Check code style
flake8 src/
mypy src/

# Format code (if using)
black src/
isort src/
  1. Commit and Push
git add .
git commit -m "feat: add amazing new feature"
git push origin feature/amazing-new-feature
  1. Create Pull Request
  • Open PR against develop branch
  • Include description of changes
  • Ensure all tests pass
  • Request code review

πŸ“ Code Standards

  • Type Hints: Use Python type hints throughout
  • Docstrings: Document all public functions and classes
  • Testing: Write tests for new functionality
  • Coverage: Maintain >80% test coverage
  • Style: Follow PEP 8 with flake8 configuration
  • Async: Use async/await patterns for I/O operations

πŸ§ͺ Testing Requirements

  • Write unit tests for business logic
  • Include integration tests for database operations
  • Add E2E tests for API endpoints
  • Mock external service dependencies
  • Test error conditions and edge cases

πŸ“‹ Pull Request Guidelines

  • Clear Description: Explain what and why
  • Small Changes: Keep PRs focused and reviewable
  • Tests Included: All new code must have tests
  • Documentation: Update README/docs if needed
  • No Breaking Changes: Maintain backward compatibility

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

MIT License

Copyright (c) 2024 Online Cinema Project Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

πŸ‘₯ Authors & Contributors

πŸ™ Acknowledgments

  • FastAPI for the excellent async web framework
  • SQLAlchemy for the powerful ORM capabilities
  • Pydantic for data validation excellence
  • Docker for containerization simplicity
  • PostgreSQL for robust database foundation
  • Redis for caching and message broker capabilities
  • Python Community for continuous innovation and support

🎬 Built with ❀️ for the Developer Community πŸš€

Star ⭐ this repository if you find it helpful!

⬆ Back to Top

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages