# gcrsaldanha/codeflix-catalog-admin architecture

> Architecture diagram of the GitHub repository gcrsaldanha/codeflix-catalog-admin, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gcrsaldanha/codeflix-catalog-admin
- Repository: https://github.com/gcrsaldanha/codeflix-catalog-admin

## Overview

##### Project Type and Purpose
- This is a **full-stack backend application** (no separate JS frontend) built with **Python 3**, **Django REST Framework**, and a **Domain-Driven Design** (DDD) organization under `src/core`.
- It provides CRUD and media-upload APIs for Categories, Genres, Cast Members, and Videos, plus **asynchronous processing** via **RabbitMQ** and optional **Google Cloud Storage** or local storage for video files.

##### File Structure
- **`src/core/`**: Core DDD modules organized by domain (category, genre, cast_member, video) and cross-cutting shared code (authentication, event bus, storage).
- `domain/` holds entities, value objects, repository interfaces.
- `application/use_cases/` implements business logic.
- `infra/` contains in-memory repos, RabbitMQ consumers/producers, GCS/local storage.
- **`src/django_project/`**: The Django project wrapper with four “apps” (category_app, genre_app, cast_member_app, video_app). Each app maps REST endpoints to serializers, repositories, and use-cases.

##### Extract Key Points from the README
- The system relies on:
- **Django ORM** (models & migrations) for data persistence in a relational DB (assumed PostgreSQL or default SQLite).
- **RabbitMQ** for dispatching and consuming video-processing events.
- **JWT authentication** (pluggable via `core/_shared/infrastructure/auth`).
- **Commands**: `startconsumer` (to run the RabbitMQ listener) and `runserver` (to serve HTTP).
- The readme highlights an evolutionary, module-by-module approach—each domain feature follows the same layering (domain → use case → infra → Django app).

a. **Main Components**
- **Clients**: Web UI or Postman (external actors issuing HTTP requests).
- **Django REST API**:
- Four Django apps exposing endpoints (/categories, /genres, /cast_members, /videos).
- Controllers/Views → Serializers → “Repository” adapters → Use Cases → Domain Entities.
- **Domain & Application Layer** (`src/core`):
- Shared domain logic, events, notification, handlers.
- Use Cases for each aggregate.
- **Infrastructure Layer**:
- **Relational Database** (via Django ORM).
- **RabbitMQ** (message bus & consumer).
- **Storage Adapters**: GCS or Local (media files).
- **Auth Service** (JWT or external Keycloak).
- **Asynchronous Workers**:
- `video_converted_rabbitmq_consumer` listens for “video converted” events.
- Use Cases for processing audio/video or dispatching new events.

b. **Relationships & Interactions**
- **HTTP flow**: Client → Django REST endpoint → Use Case → DB → Response.
- **Upload flow**: Client uploads media → API writes to storage adapter → Use Case publishes “upload_video” event to RabbitMQ.
- **Consume flow**: RabbitMQ → `startconsumer` process → Domain event handler → updates DB or triggers further processes.
- **Auth flow**: HTTP request → JWT Auth middleware → Auth Service (validate/issue tokens).

c. **Architectural Patterns & Design Principles**
- **Layered Architecture**: Presentation (Django views) → Application (use cases) → Domain → Infrastructure.
- **DDD** aggregates and boundaries clearly separated.
- **Ports & Adapters** (Hexagonal): Domain code depends on interfaces; adapters in `infra` implement them.
- **Event-Driven** for asynchronous video processing.

d. **Key Technologies & Frameworks**
- Python 3, Django, Django REST Framework
- RabbitMQ (pika or kombu via `rabbitmq_dispatcher`)
- Google Cloud Storage (via `gcs_storage.py`) or Local FS
- PyTest for unit & integration tests, pytest-django for e2e
- JWT authentication layer (pluggable)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        Client["Clients (Web UI/Postman)"]:::external
    end

    %% API Layer
    subgraph "API Layer"
        direction TB
        CategoryView["CategoryApp View"]:::api
        GenreView["GenreApp View"]:::api
        CastMemberView["CastMemberApp View"]:::api
        VideoView["VideoApp View"]:::api
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        CategoryUC["Category Use Cases"]:::domain-layer
        GenreUC["Genre Use Cases"]:::domain-layer
        CastMemberUC["CastMember Use Cases"]:::domain-layer
        VideoUC["Video Use Cases & Events"]:::domain-layer
    end

    %% Domain Layer
    subgraph "Domain Layer"
        direction TB
        CategoryEntity["Category Entity"]:::domain
        GenreEntity["Genre Entity"]:::domain
        CastMemberEntity["CastMember Entity"]:::domain
        VideoEntity["Video Entity & Value Objects"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        direction TB
        DB["Relational Database"]:::infra-external
        RabbitMQ["RabbitMQ Broker"]:::infra-external
        StorageLocal["Local Storage Adapter"]:::infra
        StorageGCS["GCS Storage Adapter"]:::infra
        Consumer["VideoConverted Consumer"]:::infra
    end

    %% Shared Services
    subgraph "Shared Services"
        direction TB
        AuthService["JWT Auth Service"]:::infra
        EventBus["RabbitMQ Dispatcher"]:::infra
    end

    %% Connections - HTTP Flow
    Client -->|HTTP| CategoryView
    Client -->|HTTP| GenreView
    Client -->|HTTP| CastMemberView
    Client -->|HTTP| VideoView

    CategoryView -->|calls| CategoryUC
    GenreView -->|calls| GenreUC
    CastMemberView -->|calls| CastMemberUC
    VideoView -->|calls| VideoUC

    %% Use Cases to Domain & Persistence
    CategoryUC -->|uses| CategoryEntity
    GenreUC -->|uses| GenreEntity
    CastMemberUC -->|uses| CastMemberEntity
    VideoUC -->|uses| VideoEntity

    CategoryUC -->|persists| DB
    GenreUC -->|persists| DB
    CastMemberUC -->|persists| DB
    VideoUC -->|persists| DB

    %% Upload Flow - Media & Events
    VideoUC -->|stores media| StorageLocal
    VideoUC -->|stores media| StorageGCS
    VideoUC -->|publishes upload_video| RabbitMQ

    %% Consume Flow
    RabbitMQ -.->|event| Consumer
    Consumer -->|handles event| VideoUC
    VideoUC -->|updates| DB

    %% Auth Flow
    CategoryView -->|auth| AuthService
    GenreView -->|auth| AuthService
    CastMemberView -->|auth| AuthService
    VideoView -->|auth| AuthService

    %% Shared Event Bus
    VideoUC -->|dispatches| EventBus
    CategoryUC -->|dispatches| EventBus

    %% Click Events
    click CategoryEntity "https://github.com/gcrsaldanha/codeflix-catalog-admin/blob/main/src/core/category/domain/category.py"
    click CategoryUC "https://github.com/gcrsaldanha/codeflix-catalog-admin/tree/main/src/core/category/application/use_cases/"
    click CategoryView "https://github.com/gcrsaldanha/codeflix-catalog-admin/tree/main/src/django_project/category_app/"
    click GenreEntity "https://github.com/gcrsaldanha/codeflix-catalog-admin/blob/main/src/core/genre/domain/genre.py"
    click GenreUC "https://github.com/gcrsaldanha/codeflix-catalog-admin/tree/main/src/core/genre/application/use_cases/"
    click GenreView "https://github.com/gcrsaldanha/codeflix-catalog-admin/tree/main/src/django_project/genre_app/"
    click CastMemberEntity "https://github.com/gcrsaldanha/codeflix-catalog-admin/blob/main/src/core/cast_member/domain/cast_member.py"
    click CastMemberUC "https://github.com/gcrsaldanha/codeflix-catalog-admin/tree/main/src/core/cast_member/application/use_cases/"
    click CastMemberView "https://github.com/gcrsaldanha/codeflix-catalog-admin/tree/main/src/django_project/cast_member_app/"
    click VideoEntity "https://github.com/gcrsaldanha/codeflix-catalog-admin/blob/main/src/core/video/domain/video.py"
    click VideoUC "https://github.com/gcrsaldanha/codeflix-catalog-admin/tree/main/src/core/video/application/use_cases/"
    click Consumer "https://github.com/gcrsaldanha/codeflix-catalog-admin/blob/main/src/core/video/infra/video_converted_rabbitmq_consumer.py"
    click VideoView "https://github.com/gcrsaldanha/codeflix-catalog-admin/tree/main/src/django_project/video_app/"
    click AuthService "https://github.com/gcrsaldanha/codeflix-catalog-admin/blob/main/src/core/_shared/infrastructure/auth/jwt_auth_service.py"
    click EventBus "https://github.com/gcrsaldanha/codeflix-catalog-admin/blob/main/src/core/_shared/infrastructure/events/rabbitmq_dispatcher.py"
    click StorageLocal "https://github.com/gcrsaldanha/codeflix-catalog-admin/blob/main/src/core/_shared/infrastructure/storage/local_storage.py"
    click StorageGCS "https://github.com/gcrsaldanha/codeflix-catalog-admin/blob/main/src/core/_shared/infrastructure/storage/gcs_storage.py"

    %% Styles
    classDef api fill:#D6EFFF,stroke:#333,stroke-width:1px
    classDef domain-layer fill:#BBDEFB,stroke:#333,stroke-width:1px
    classDef domain fill:#90CAF9,stroke:#333,stroke-width:1px
    classDef infra fill:#C8E6C9,stroke:#333,stroke-width:1px
    classDef infra-external fill:#A5D6A7,stroke:#333,stroke-width:1px
    classDef external fill:#FFD54F,stroke:#333,stroke-width:1px
```
