# khuongvo2105/movieapp architecture

> Architecture diagram of the GitHub repository khuongvo2105/movieapp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/khuongvo2105/movieapp
- Repository: https://github.com/khuongvo2105/movieapp

## Overview

##### Main Components and Their Roles
- API / Presentation Layer: Represented by the Controllers directory (CommentController.cs, EpisodeController.cs, GenreController.cs, MoviesController.cs, NewsController.cs, RatingController.cs, UserController.cs). These controllers expose HTTP endpoints and handle incoming requests.
- Business / Mapping Layer: The Mapper directory contains profile classes (e.g., MovieProfile.cs, CommentProfile.cs) used to map between domain entities and DTOs. This indicates usage of a mapping tool (likely AutoMapper) to convert data across layers.
- Data Access Layer: The Repository directory holds repositories and their abstractions (interfaces like IMovieRepository, IUserRepository, etc.). These implement data persistence and retrieval logic cooperating with the DbContext.
- Database / Persistence: The Data directory (MovieDbContext.cs) and extensive Migrations directory illustrate an Entity Framework (EF) Code-First approach with multiple migrations managing the database schema.
- Domain Models: In the Model folder (DomainModel subdirectory) are entity definitions (Movies, Actors, Comment, etc.) which represent the core business objects.
- DTO Layer: The Model/Dto directory holds various data transfer objects used for request/response transformations between the API and clients.
- Middleware: Custom middleware components (e.g., HandleToken.cs and SessionRequirementAttribute.cs) manage authentication or session control.
- Configuration & Application Bootstrapping: The Program.cs file and launchSettings.json define the server startup and configuration, while appsettings.json (and its development variant) configure the application environment.
- Secondary Project: ReadingVideoFileSolutions (with its own Program.cs, App.config, and project file) should be diagrammed as a utility or supporting service, likely dealing with video processing operations.

##### Relationships and Data Flow
- Controllers then invoke repository methods to interact with the database via MovieDbContext.
- Mapping profiles are used to translate between Domain Models (the entities) and DTOs before sending data back or processing incoming data.
- Middleware components intercept requests for token validation and session requirements before the requests reach controllers.
- The database schema is defined and evolved via EF Core’s Migrations.
- The ReadingVideoFileSolutions module (if integrated as part of the overall system) may work independently or could be triggered by the main API (for example, to process video inputs).

##### Important Architectural Patterns and Technologies
- Layered Architecture: Presentation (controllers) → Business Logic (Mappings, possible service methods in repositories) → Data Access (Repository + DbContext) → Persistence (relational database with EF migrations).
- Repository Pattern: Isolate data access by using interface-backed repository implementations.
- AutoMapper or Custom Mapping: Abstract the conversion between domain models and DTOs.
- Middleware: Custom processing for token and session management.
- Entity Framework Core for data persistence and migrations.
- ASP .NET 8 for hosting APIs and managing the server logic.

##### Putting It All Together
- Controllers to the Repository layer (with interfaces and implementation classes) to show how requests are processed.
- Below the repository, add the Data Access component (MovieDbContext and migrations) to represent the database layer (Relational DB).
- Off to the side (or below) include the Mapping Profiles that link DTOs and Domain Models, showing bidirectional mapping.
- Finally, include the ReadingVideoFileSolutions module with its associated configuration, marking it as a utility service.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    subgraph "External"
        client["External Client"]:::client
    end

    %% Middleware Layer
    subgraph "Middleware Layer"
        middleware["Middleware: HandleToken, SessionRequirement"]:::middleware
    end

    %% API Controllers Layer
    subgraph "API Layer"
        controllers["API Controllers (Comment, Episode, Genre, Movies, News, Rating, User)"]:::controller
    end

    %% Configuration & Bootstrapping
    subgraph "Configuration"
        prog["Program (Bootstrapping)"]:::config
        appSetting["appsettings.json"]:::config
        devSetting["appsettings.Development.json"]:::config
        launch["launchSettings.json"]:::config
    end

    %% Business/Mapping and Domain Models
    subgraph "Business & Domain Layer"
        mapper["Mapping Profiles (CommentProfile, EpisodeProfile, GenreProfile, MovieProfile, NewsProfile, RatingProfile, UserProfile)"]:::mapping
        domainModels["Domain Models (Entities)"]:::mapping
        dto["DTOs"]:::mapping
    end

    %% Repositories / Data Access Layer
    subgraph "Repository Layer"
        repository["Repositories (IComment, IEpisode, IGenre, IMovie, INews, IRating, IUser) & Implementations"]:::repository
    end

    %% Database/Persistence Layer
    subgraph "Database Layer"
        dbContext["EF Core DbContext"]:::db
        migrations["Migrations (EF Core Schema)"]:::db
    end

    %% Utility Project
    subgraph "Utility Service"
        utility["ReadingVideoFileSolutions"]:::utility
    end

    %% Connections
    client --> middleware
    middleware --> controllers
    prog --> middleware
    prog --> controllers
    appSetting --> prog
    devSetting --> prog
    launch --> prog
    controllers --> repository
    repository --> dbContext
    dbContext --> migrations
    controllers --> mapper
    mapper <--> domainModels
    mapper <--> dto
    controllers -.-> utility

    %% Styles
    classDef client fill:#f9f,stroke:#333,stroke-width:2px;
    classDef middleware fill:#ffcccc,stroke:#333,stroke-width:2px;
    classDef controller fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef repository fill:#ffffcc,stroke:#333,stroke-width:2px;
    classDef db fill:#d1e7dd,stroke:#333,stroke-width:2px;
    classDef mapping fill:#e2e3e5,stroke:#333,stroke-width:2px;
    classDef config fill:#f8d7da,stroke:#333,stroke-width:2px;
    classDef utility fill:#d6d8db,stroke:#333,stroke-width:2px;

    %% Click Events for Component Mapping
    click controllers "https://github.com/khuongvo2105/movieapp/tree/master/MovieApi/Controllers"
    click mapper "https://github.com/khuongvo2105/movieapp/tree/master/MovieApi/Mapper"
    click repository "https://github.com/khuongvo2105/movieapp/tree/master/MovieApi/Repository"
    click dbContext "https://github.com/khuongvo2105/movieapp/blob/master/MovieApi/Data/MovieDbContext.cs"
    click migrations "https://github.com/khuongvo2105/movieapp/tree/master/MovieApi/Migrations"
    click domainModels "https://github.com/khuongvo2105/movieapp/tree/master/MovieApi/Model/DomainModel"
    click dto "https://github.com/khuongvo2105/movieapp/tree/master/MovieApi/Model/Dto"
    click middleware "https://github.com/khuongvo2105/movieapp/tree/master/MovieApi/Middlewares"
    click prog "https://github.com/khuongvo2105/movieapp/blob/master/MovieApi/Program.cs"
    click appSetting "https://github.com/khuongvo2105/movieapp/blob/master/MovieApi/appsettings.json"
    click devSetting "https://github.com/khuongvo2105/movieapp/blob/master/MovieApi/appsettings.Development.json"
    click launch "https://github.com/khuongvo2105/movieapp/blob/master/MovieApi/Properties/launchSettings.json"
    click utility "https://github.com/khuongvo2105/movieapp/tree/master/ReadingVideoFileSolutions"
```
