# quangphu1310/paradisevilla architecture

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

- Interactive diagram: https://gitdiagram.com/quangphu1310/paradisevilla
- Repository: https://github.com/quangphu1310/paradisevilla

## Overview

##### Main Components
- API Layer (ParadiseVilla_API):
- Controllers organized by API version (v1 and v2) for managing villas, villa numbers, and user-related operations.
- Data layer with ApplicationDbContext and migration scripts to manage schema changes.
- Models including domain models and a set of DTOs used for data transfer.
- Repository implementations (and interfaces) that abstract data access.
- Configuration classes like MappingConfig that set up AutoMapper.
- Security components for authentication (JWT, Identity) and role-based access.

- Web Layer (ParadiseVilla_Web):
- MVC Controllers that control user interactions, managing views and calling backend services.
- Views and ViewModels to render the client-side UI.
- Service layer (with services like AuthService, VillaService, etc.) that act as a client to the API.
- Frontend assets including CSS, JavaScript, Bootstrap resources for improved UX.

- Utility Layer (ParadiseVilla_Utility):
- Shared library for common definitions such as static details or constants (see SD.cs).

- Database:
- A SQL Server database accessed via Entity Framework Core and handled through migrations.

##### Relationships and Interactions
- The MVC Web application acts as the presentation layer where users interact via web pages.
- Requests from users are processed in the Web layer and then forwarded to the API layer for business logic execution.
- The API layer (ParadiseVilla_API) accepts RESTful requests, applies authentication (JWT/Identity) and handles operations using the repository pattern.
- Domain models (and DTOs) are used within the API to map data between the business layer and the SQL Server database.
- The repository layer abstracts the data access (using EF Core) that interacts with the underlying database.
- AutoMapper is used to convert between Domain Models and DTOs across the layers.
- Multiple API versions are maintained (e.g., v1 and v2) – indicate branching in the controller components.

##### Architectural Patterns and Design Principles
- Layered Architecture: Separate presentation, API/business, and data access layers help in maintaining separation of concerns.
- Repository Pattern: The abstraction over data access operations keeps the data logic isolated.
- Dependency Injection: Utilized for service registration and management of dependencies among controllers, services, and repositories.
- DTOs and AutoMapper: Ensure safe and efficient data transfer between layers.
- Versioning of APIs: Shows attention to evolutionary design/redesign over time without breaking existing functionality.
- Security Implementation: Integration of Identity, JWT for secure authentication and role-based authorization.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client"
        User["User/Browser"]:::frontend
    end

    %% Web Layer (ParadiseVilla_Web – MVC Frontend)
    subgraph "ParadiseVilla_Web – MVC Frontend"
        WebController["MVC Controllers"]:::frontend
        WebViews["Views & ViewModels"]:::frontend
        WebService["Service Layer"]:::frontend
        WebAssets["Frontend Assets"]:::frontend
        User -->|"accesses"| WebController
        WebController -->|"renders"| WebViews
        WebController -->|"invokes"| WebService
    end

    %% API Layer (ParadiseVilla_API – RESTful API)
    subgraph "ParadiseVilla_API – RESTful API"
        ControllersV1["Controllers (v1)"]:::backend
        ControllersV2["Controllers (v2)"]:::backend
        APIRepo["Repository Layer"]:::backend
        APIData["Data Access (ApplicationDbContext + Migrations)"]:::backend
        APIModels["Models & DTOs"]:::backend
        APIMapping["MappingConfig (AutoMapper)"]:::backend
        APISecurity["Security Components (JWT/Identity)"]:::backend

        ControllersV1 -->|"calls"| APIRepo
        ControllersV2 -->|"calls"| APIRepo
        APIRepo -->|"uses"| APIData
        APIModels -->|"mapped by"| APIMapping
        ControllersV1 ---|"authenticates via"| APISecurity
        ControllersV2 ---|"authenticates via"| APISecurity
    end

    %% Utility Layer (ParadiseVilla_Utility – Shared Library)
    subgraph "ParadiseVilla_Utility – Shared Library"
        Utility["Shared Library (SD)"]:::utility
    end

    %% Database
    DB["SQL Server – Database"]:::database

    %% Interactions between layers
    WebService -->|"API-call"| ControllersV1
    WebService -->|"API-call"| ControllersV2
    APIData -->|"persists to"| DB

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#2471A3,stroke-width:2px;
    classDef backend fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef utility fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
    classDef database fill:#FADBD8,stroke:#C0392B,stroke-width:2px;

    %% Click Events - API Layer
    click ControllersV1 "https://github.com/quangphu1310/paradisevilla/tree/master/ParadiseVilla_API/Controllers/v1"
    click ControllersV2 "https://github.com/quangphu1310/paradisevilla/tree/master/ParadiseVilla_API/Controllers/v2"
    click APIData "https://github.com/quangphu1310/paradisevilla/tree/master/ParadiseVilla_API/Data"
    click APIModels "https://github.com/quangphu1310/paradisevilla/tree/master/ParadiseVilla_API/Models"
    click APIMapping "https://github.com/quangphu1310/paradisevilla/blob/master/ParadiseVilla_API/MappingConfig.cs"
    click APIRepo "https://github.com/quangphu1310/paradisevilla/tree/master/ParadiseVilla_API/Repository/"
    click APISecurity "https://github.com/quangphu1310/paradisevilla/tree/master/ParadiseVilla_API/Models"
    
    %% Click Events - Web Layer
    click WebController "https://github.com/quangphu1310/paradisevilla/tree/master/ParadiseVilla_Web/Controllers"
    click WebViews "https://github.com/quangphu1310/paradisevilla/tree/master/ParadiseVilla_Web/Views"
    click WebService "https://github.com/quangphu1310/paradisevilla/tree/master/ParadiseVilla_Web/Services"
    click WebAssets "https://github.com/quangphu1310/paradisevilla/tree/master/ParadiseVilla_Web/wwwroot"

    %% Click Event - Utility Layer
    click Utility "https://github.com/quangphu1310/paradisevilla/blob/master/ParadiseVilla_Utility/SD.cs"
```
