Skip to content

Latest commit

 

History

History
384 lines (303 loc) · 13.1 KB

File metadata and controls

384 lines (303 loc) · 13.1 KB

Flixer Catalog API

.NET 6 MySQL RabbitMQ Docker

A REST API for video catalog management built with Clean Architecture and Domain-Driven Design (DDD). The project implements a complete catalog system with videos, categories, genres, and cast members, including media upload and video processing.

🎯 Overview

Flixer Catalog API is a video catalog management system that allows:

  • Video Management: Create, update, list, and delete videos with detailed information
  • Category Organization: Categorize videos for better organization
  • Genre Classification: Classify content using multiple genres
  • Cast Management: Register and associate directors and actors with videos
  • Media Upload: Upload videos, trailers, thumbnails, and banners
  • Video Processing: Asynchronous encoding system using messaging
  • Authentication and Authorization: Role-based access control using Keycloak

🏗 Architecture

The project follows Clean Architecture and Domain-Driven Design (DDD) principles, organizing code into well-defined layers:

┌─────────────────────────────────────────┐
│          Flixer.Catalog.Api             │  ← Controllers, Middlewares
│      (Presentation Layer)                │
└──────────────┬──────────────────────────┘
               │
┌──────────────▼──────────────────────────┐
│     Flixer.Catalog.Application          │  ← Use Cases, DTOs, Queries
│      (Application Layer)                 │
└──────────────┬──────────────────────────┘
               │
┌──────────────▼──────────────────────────┐
│       Flixer.Catalog.Domain              │  ← Entities, Value Objects
│      (Domain Layer)                      │     Business Rules
└──────────────▲──────────────────────────┘
               │
┌──────────────┴──────────────────────────┐
│    Flixer.Catalog.Infra.*                │  ← Repositories, Persistence
│      (Infrastructure Layer)              │     Storage, Messaging
└──────────────────────────────────────────┘

Layers

  • API: Controllers, configurations, filters, and middlewares
  • Application: Use cases (Commands/Queries), validations, service interfaces
  • Domain: Entities, aggregates, value objects, domain events, and business rules
  • Infrastructure: Repository implementations, data access (Entity Framework), storage (Google Cloud Storage), and messaging (RabbitMQ)

✨ Features

Video Management

  • Create video with metadata (title, description, year, duration, rating)
  • Update video information
  • Upload media files (video, trailer)
  • Upload images (thumbnail, thumbnail half, banner)
  • List videos with pagination and filters
  • Get video by ID
  • Delete video
  • Update video encoding status

Category Management

  • Create categories
  • Update categories
  • Activate/Deactivate categories
  • List categories with pagination and search
  • Get category by ID
  • Delete category

Genre Management

  • Create genres
  • Update genres
  • Associate categories with genres
  • Activate/Deactivate genres
  • List genres with pagination and search
  • Get genre by ID
  • Delete genre

Cast Member Management

  • Create cast members (actor/director)
  • Update cast members
  • List members with pagination and search
  • Get member by ID
  • Delete cast member

Advanced Features

  • JWT Authentication via Keycloak
  • Role-based authorization (admin, catalog-admin)
  • File Upload to Google Cloud Storage
  • Asynchronous processing of videos via RabbitMQ
  • Health Checks for MySQL, RabbitMQ, and Entity Framework
  • Structured logging with Serilog
  • OpenAPI/Swagger documentation

🛠 Technologies

Framework and Language

  • .NET 6: Main framework
  • C#: Programming language

Persistence

  • Entity Framework Core 6: ORM for data access
  • Pomelo.EntityFrameworkCore.MySql: MySQL provider for EF Core
  • MySQL 8: Relational database

Authentication and Authorization

  • Keycloak 20.0.3: Identity and access management system
  • Keycloak.AuthServices: Keycloak integration with .NET
  • IdentityModel.AspNetCore: OAuth2/OpenID Connect support

Messaging

  • RabbitMQ 3: Message broker for asynchronous communication
  • RabbitMQ.Client: .NET client for RabbitMQ

Storage

  • Google Cloud Storage: Video and image storage

Patterns and Libraries

  • MediatR: CQRS and mediator pattern implementation
  • FluentValidation: Entity and DTO validation
  • Serilog: Structured logging

Testing

  • xUnit: Testing framework
  • Fluent Assertions: Fluent assertions for tests
  • Moq: Mocking framework
  • Bogus: Fake data generation for tests

DevOps

  • Docker: Containerization
  • Docker Compose: Container orchestration
  • GitHub Actions: CI/CD pipeline

Observability

  • AspNetCore.HealthChecks: Health checks for MySQL, RabbitMQ, and EF Core
  • Serilog.AspNetCore: HTTP request logging

📦 Prerequisites

  • Docker and Docker Compose installed
  • .NET 6 SDK (for local development)
  • IDE/Editor: Visual Studio, Visual Studio Code, or JetBrains Rider

🚀 Installation and Execution

Using Docker Compose (Recommended)

  1. Clone the repository

    git clone https://github.com/jaugustodev/flixer.git
    cd flixer
  2. Verify Docker is installed

    docker --version
  3. Start the containers

    docker compose -f docker-compose.yml up -d
  4. Check container status

    docker compose ps
  5. Access the application

  6. To stop and remove containers

    docker compose -f docker-compose.yml down

Running Locally (Development)

  1. Start only dependencies (MySQL, RabbitMQ, Keycloak)

    docker compose up flixer_db rabbitmq keycloak -d
  2. Restore dependencies

    dotnet restore
  3. Run database migrations

    dotnet ef database update --project src/Flixer.Catalog.Infra.Data.EF
  4. Run the application

    dotnet run --project src/Flixer.Catalog.Api

🧪 Running Tests

The project includes a complete test suite:

Unit Tests

dotnet test tests/Flixer.Catalog.UnitTest

Integration Tests

  1. Start test containers

    docker compose -f docker-compose-integration.yml up -d
  2. Run tests

    dotnet test tests/Flixer.Catalog.IntegrationTests
  3. Stop test containers

    docker compose -f docker-compose-integration.yml down

End-to-End Tests

dotnet test tests/Flixer.Catalog.EndToEndTests

Run all tests

dotnet test

📁 Project Structure

flixer/
├── src/
│   ├── Flixer.Catalog.Api/              # Presentation layer (Controllers, Middlewares)
│   ├── Flixer.Catalog.Application/       # Use cases and application logic
│   ├── Flixer.Catalog.Domain/            # Entities, Value Objects, business rules
│   ├── Flixer.Catalog.Infra.Data.EF/     # Repositories and data access (EF Core)
│   ├── Flixer.Catalog.Infra.Storage/     # Google Cloud Storage integration
│   └── Flixer.Catalog.Infra.Messaging/   # RabbitMQ integration
├── tests/
│   ├── Flixer.Catalog.UnitTest/          # Unit tests
│   ├── Flixer.Catalog.IntegrationTests/  # Integration tests
│   ├── Flixer.Catalog.EndToEndTests/     # End-to-end tests
│   └── Flixer.Catalog.Tests.Shared/      # Shared code between tests
├── docker-compose.yml                     # Docker configuration for production
├── docker-compose-integration.yml         # Docker configuration for tests
└── Flixer.Catalog.sln                    # Project solution

Domain - Main Entities

  • Video: Main aggregate representing a video with all its metadata
  • Category: Categories for video organization
  • Genre: Genres that can be associated with videos
  • CastMember: Cast members (actors/directors)
  • Media: Value object representing media files (video/trailer)
  • Image: Value object representing images (thumb/banner)

🔌 API Endpoints

Videos

  • POST /api/videos - Create new video
  • GET /api/videos - List videos (with pagination)
  • GET /api/videos/{id} - Get video by ID
  • PUT /api/videos/{id} - Update video
  • DELETE /api/videos/{id} - Delete video
  • POST /api/videos/{id}/upload-media - Upload media

Categories

  • POST /api/categories - Create category
  • GET /api/categories - List categories (with pagination)
  • GET /api/categories/{id} - Get category by ID
  • PUT /api/categories/{id} - Update category
  • DELETE /api/categories/{id} - Delete category

Genres

  • POST /api/genres - Create genre
  • GET /api/genres - List genres (with pagination)
  • GET /api/genres/{id} - Get genre by ID
  • PUT /api/genres/{id} - Update genre
  • DELETE /api/genres/{id} - Delete genre

Cast Members

  • POST /api/cast-members - Create cast member
  • GET /api/cast-members - List members (with pagination)
  • GET /api/cast-members/{id} - Get member by ID
  • PUT /api/cast-members/{id} - Update member
  • DELETE /api/cast-members/{id} - Delete member

Health Checks

  • GET /health - Check application and dependencies health

🔄 Continuous Integration

The project uses GitHub Actions for automated CI/CD.

CI Workflow

Triggered on:

  • Push to main branch
  • Pull requests to main branch

Pipeline Steps

  1. Repository Checkout: Clone source code
  2. .NET Core Setup: Prepare environment with .NET 6.x
  3. Start Containers: Bring up test containers via docker-compose-integration.yml
  4. Restore Dependencies: Execute dotnet restore
  5. Build Project: Compile the code
  6. Run Tests: Execute entire test suite and generate reports
  7. DockerHub Login: Authenticate to DockerHub
  8. Build and Push Docker Image: Build and push image to DockerHub

Resources

🛠 Development Tools

Recommended IDEs and Editors

Name Type Download
Visual Studio Code Editor Download
Visual Studio Community IDE Download
JetBrains Rider IDE Download

Useful Extensions

Visual Studio Code

  • C# Dev Kit: Complete support for C# and .NET
  • Docker: Container management
  • SonarLint: Real-time bug and code smell detection
  • GitLens: Advanced Git features
  • REST Client: Test APIs directly from VS Code

All IDEs

  • SonarLint: Flags potential bugs and code smells - More info

🤝 Contributing

Contributions are welcome! Please follow these guidelines:

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

Code Standards

  • Follow SOLID principles
  • Write tests for new features
  • Maintain high test coverage
  • Use descriptive names for variables and methods
  • Document complex code

📚 Additional Documentation