An open API service indexing awesome lists of open source software.

https://github.com/jaugustodev/flixer

REST API for video catalog management built with Clean Architecture and DDD in .NET 6, featuring JWT authentication, Google Cloud Storage media upload, and asynchronous processing with RabbitMQ
https://github.com/jaugustodev/flixer

ci-cd clean-architecture csharp ddd docker docker-compose github-actions jwt keycloak kubernetes meaditr mysql pipeline rabbitmq serilog

Last synced: 16 days ago
JSON representation

REST API for video catalog management built with Clean Architecture and DDD in .NET 6, featuring JWT authentication, Google Cloud Storage media upload, and asynchronous processing with RabbitMQ

Awesome Lists containing this project

README

          

# Flixer Catalog API

![.NET 6](https://img.shields.io/badge/.NET-6.0-512BD4?logo=dotnet)
![MySQL](https://img.shields.io/badge/MySQL-8.0-4479A1?logo=mysql&logoColor=white)
![RabbitMQ](https://img.shields.io/badge/RabbitMQ-3.0-FF6600?logo=rabbitmq&logoColor=white)
![Docker](https://img.shields.io/badge/Docker-Enabled-2496ED?logo=docker&logoColor=white)

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**
```bash
git clone https://github.com/jaugustodev/flixer.git
cd flixer
```

2. **Verify Docker is installed**
```bash
docker --version
```

3. **Start the containers**
```bash
docker compose -f docker-compose.yml up -d
```

4. **Check container status**
```bash
docker compose ps
```

5. **Access the application**
- API Swagger: [http://localhost:5000/swagger/index.html](http://localhost:5000/swagger/index.html)
- RabbitMQ Management: [http://localhost:15672](http://localhost:15672)
- Username: `adm_videos`
- Password: `123456`
- Keycloak Admin: [http://localhost:8443](http://localhost:8443)
- Username: `admin`
- Password: `admin`

6. **To stop and remove containers**
```bash
docker compose -f docker-compose.yml down
```

### Running Locally (Development)

1. **Start only dependencies (MySQL, RabbitMQ, Keycloak)**
```bash
docker compose up flixer_db rabbitmq keycloak -d
```

2. **Restore dependencies**
```bash
dotnet restore
```

3. **Run database migrations**
```bash
dotnet ef database update --project src/Flixer.Catalog.Infra.Data.EF
```

4. **Run the application**
```bash
dotnet run --project src/Flixer.Catalog.Api
```

## ๐Ÿงช Running Tests

The project includes a complete test suite:

### Unit Tests
```bash
dotnet test tests/Flixer.Catalog.UnitTest
```

### Integration Tests

1. **Start test containers**
```bash
docker compose -f docker-compose-integration.yml up -d
```

2. **Run tests**
```bash
dotnet test tests/Flixer.Catalog.IntegrationTests
```

3. **Stop test containers**
```bash
docker compose -f docker-compose-integration.yml down
```

### End-to-End Tests
```bash
dotnet test tests/Flixer.Catalog.EndToEndTests
```

### Run all tests
```bash
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

- [GitHub Actions Documentation](https://docs.github.com/en/actions)
- [DockerHub Documentation](https://docs.docker.com/docker-hub/)

## ๐Ÿ›  Development Tools

### Recommended IDEs and Editors

| Name | Type | Download |
|------------------------|--------|----------|
| Visual Studio Code | Editor | [Download](https://code.visualstudio.com/download) |
| Visual Studio Community| IDE | [Download](https://visualstudio.microsoft.com/vs/community/) |
| JetBrains Rider | IDE | [Download](https://www.jetbrains.com/rider/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](https://www.sonarlint.org/)

## ๐Ÿค 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

- [.NET 6 Documentation](https://docs.microsoft.com/en-us/aspnet/core/?view=aspnetcore-6.0)
- [MediatR Documentation](https://github.com/jbogard/MediatR)
- [Entity Framework Core](https://docs.microsoft.com/en-us/ef/core/)
- [FluentValidation](https://docs.fluentvalidation.net/en/latest/start.html)
- [Serilog](https://serilog.net)
- [RabbitMQ Tutorials](https://www.rabbitmq.com/getstarted.html)
- [Keycloak Documentation](https://www.keycloak.org/documentation)