# Church API Project Overview

## Purpose
The Church API is a Rust-based web service designed for church media management and streaming. The primary functionality includes:

- **Media Management**: Upload, organize, and manage church sermons and media content
- **Video Streaming**: Provide intelligent video streaming with adaptive codec support (AV1, HEVC, H.264)
- **User Authentication**: JWT-based authentication system
- **Database Integration**: PostgreSQL database with SQLx for data persistence
- **Email Services**: Automated email functionality for church communications

## Tech Stack
- **Language**: Rust (2021 edition)
- **Web Framework**: Axum 0.7 with async/await (Tokio runtime)
- **Database**: PostgreSQL with SQLx 0.7
- **Media Processing**: 
  - GStreamer bindings (0.22) for high-performance streaming
  - FFmpeg bindings (ffmpeg-next 7.0) - being replaced with GStreamer
- **Authentication**: JWT (jsonwebtoken) + bcrypt for password hashing
- **Logging**: tracing + tracing-subscriber for structured logging
- **Testing**: Built-in Rust testing framework

## Key Features
1. **Smart Video Streaming**: Detects client capabilities and serves optimal codec (AV1 direct, HEVC, or H.264 with transcoding)
2. **Hardware Acceleration**: Uses Intel QSV and VA-API for efficient video processing
3. **Chunk-based Streaming**: Netflix-style 10-second segments for smooth playback
4. **Caching System**: Intelligent caching of transcoded video segments
5. **HLS Support**: HTTP Live Streaming for maximum compatibility

## Architecture
- **Services Layer**: Business logic for transcoding, streaming, media scanning
- **Handlers Layer**: HTTP request handlers using Axum
- **Models Layer**: Data models and database entities
- **Utils Layer**: Shared utilities (codec detection, validation, etc.)

## Current Performance Focus
The project is actively migrating from FFmpeg CLI calls to native GStreamer bindings to:
- Eliminate subprocess overhead
- Reduce buffering and latency
- Improve hardware acceleration utilization
- Enable better error handling and resource management