A microservices-based media streaming platform built with Rust, PostgreSQL, and Redis.
Joy Kunga Stream is a modern media streaming platform that provides authentication, media management, and API services. The platform is built using a microservices architecture with Rust as the primary language for all services.
The platform consists of three main services:
- Auth Service (
services/auth) - Handles user authentication, registration, and session management - API Service (
services/api) - Provides the main API endpoints for user and media management - Media Service (
services/media) - Manages media ingestion, processing, and storage
- Common Library (
libs/common) - Shared utilities and database connection logic - Database - PostgreSQL for persistent storage
- Cache - Redis for session management and caching
The authentication service handles all user authentication-related functionality:
- User registration and login
- JWT token generation and validation
- Session management with Redis
- OAuth integration (Google, Apple)
- Rate limiting
- Password hashing with Argon2
Endpoints:
POST /auth/register- User registrationPOST /auth/login- User loginPOST /auth/refresh- Token refreshPOST /auth/logout- User logoutPOST /auth/logout-all- Logout from all devicesPOST /auth/oauth/authorize- OAuth authorizationPOST /auth/oauth/callback- OAuth callbackGET /health- Health checkGET /health/redis- Redis health check
The API service provides the main application endpoints:
- User management
- Media item management
- Session management
- Protected routes requiring authentication
Endpoints:
GET /health- Health checkPOST /users- Create userGET /users- Get all usersGET /users/:id- Get user by IDGET /sessions- Get user sessionsDELETE /sessions/:id- Delete sessionGET /media- Get media items (protected)GET /media/:id- Get media item by ID (protected)POST /media/refresh- Refresh media library (protected)GET /protected- Protected test route (protected)
The media service handles media ingestion and processing:
- S3 bucket polling for new media files
- Metadata extraction using FFmpeg
- Thumbnail generation
- Media item database management
The platform uses PostgreSQL with the following main tables:
id- UUID primary keyusername- Unique usernameemail- Unique emailpassword_hash- Hashed password- Timestamps for creation and updates
id- UUID primary keytype- Media type (video, audio, image)metadata- JSONB metadatas3_key- S3 object keystatus- Processing statususer_id- Foreign key to users- Extended metadata (duration, width, height, codecs, etc.)
- Timestamps for creation and updates
id- UUID primary keyuser_id- Foreign key to userstoken_hash- Hashed session tokenexpires_at- Expiration timestamp- Timestamps for creation and updates
roles- Role definitions with permissionsuser_roles- Junction table for user-role relationships
id- UUID primary keys3_key- S3 object keyetag- S3 object ETag- Timestamps for processing and creation/updates
- Language: Rust
- Web Framework: Axum
- Database: PostgreSQL
- Cache: Redis
- Authentication: JWT
- Media Processing: FFmpeg
- Cloud Storage: AWS S3
- Serialization: Serde, Serde JSON
- Database ORM: SQLx
- Password Hashing: Argon2
- OAuth: OAuth2 crate
- AWS SDK: AWS SDK for Rust
- Task Scheduling: Tokio Cron Scheduler
- Rust and Cargo (latest stable version)
- Docker and Docker Compose
- PostgreSQL client
- FFmpeg (for media processing)
-
Clone the repository:
git clone <repository-url> cd joy-kunga.stream
-
Start the database and cache services:
docker-compose up -d
-
Set up environment variables:
cp .env.example .env # Edit .env with your configuration -
Run database migrations for each service:
# Auth service migrations cd services/auth # Run your migration tool here # Media service migrations cd services/media # Run your migration tool here
-
Build and run each service:
# Auth service cd services/auth cargo run # API service cd services/api cargo run # Media service cd services/media cargo run
The following environment variables are required:
- Database connection strings for each service
- Redis connection string
- JWT secret keys
- AWS credentials for S3 access
- OAuth client credentials (if using OAuth)
See .env.example for a complete list of required environment variables.
joy-kunga.stream/
├── libs/
│ └── common/ # Shared library
├── services/
│ ├── api/ # API service
│ ├── auth/ # Authentication service
│ └── media/ # Media processing service
├── migrations/ # Database migrations
├── docker-compose.yml # Development infrastructure
├── Cargo.toml # Workspace configuration
└── .env.example # Environment variable examples
To build all services:
cargo buildTo build a specific service:
cd services/<service-name>
cargo buildTo run tests for all services:
cargo testTo run tests for a specific service:
cd services/<service-name>
cargo testThe services are designed to be deployed independently:
- Deploy the database and cache infrastructure
- Configure environment variables for each service
- Deploy each service to its respective environment
- Set up load balancing and reverse proxy as needed
- Passwords are hashed using Argon2
- JWT tokens are used for authentication
- Sessions are managed with Redis
- Rate limiting is implemented for authentication endpoints
- OAuth 2.0 is supported for external authentication
- Fork the repository
- Create a feature branch
- Make your changes
- Write tests if applicable
- Commit your changes
- Push to the branch
- Create a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
Stephane SEGNING LAMBOU [email protected]