# nttung2k3k/diamondluxurywebapp architecture

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

- Interactive diagram: https://gitdiagram.com/nttung2k3k/diamondluxurywebapp
- Repository: https://github.com/nttung2k3k/diamondluxurywebapp

## Overview

##### Main Components (Containers)
- Presentation Layer:
- The Admin Web Application (DiamondLuxurySolution.AdminCrewApp): An ASP.NET MVC application used by administrators to manage products, orders, customers, etc.
- The Customer Web Application (DiamondLuxurySolution.WebApp): An ASP.NET MVC application for customers to browse, explore product details, and complete purchases.
- API Layer:
- Backend API (DiamondLuxurySolution.BackendApi): An ASP.NET API project that provides data services for the applications. It exposes endpoints used internally and possibly by other systems.
- Business Logic & Data Access:
- Application Layer (DiamondLuxurySolution.Application): Contains business logic and repository implementations to abstract data operations.
- Data Layer (DiamondLuxurySolution.Data): Contains the Entity Framework context, configurations, and entity definitions. This module wires up the database (in this case Azure DB or a local DB via a connection string).
- Cross-cutting / Supporting Libraries:
- Utilities (DiamondLuxurySolution.Utilities): Contains constants, helper methods, and other shared resources.
- View Models (DiamondLuxurySolution.ViewModel): Holds the DTOs and view model classes which structure data communication between layers.
- Background Services:
- BackgroundServiceHost (DiamondLuxurySolution.BackgroundServiceHost): Provides worker services that run automated tasks like price crawling or other scheduled operations.

##### Relationships and Data Flow
- Both web applications (admin and customer) interact with the API Layer or directly with the Application Layer where business rules and data repository calls are implemented.
- The API layer itself acts as a gateway to the Application and Data layers; it encapsulates the business logic and ensures secure data access.
- The Application Layer abstracts and coordinates repository calls to the Data Layer, which in turn handles database interactions.
- The Background Service runs independently and uses the same Application/Data layers to perform scheduled tasks (like automated price crawling).
- Common cross-cutting utilities (like logging, error handling, or constants) are used across all layers by referencing the Utilities and ViewModel projects.
- External integrations such as Firebase (for image storage and OTP for authentication), VNPay Sandbox, PayPal, and OAuth (Facebook and Google) are connected to the Presentation/Authentication parts of the Admin and Web applications.

##### Architectural Patterns and Design Principles
- The system follows a layered (or n-tier) architecture with clear separation of concerns (presentation, business, data access, and infrastructure).
- It implements the repository pattern in the Application layer and the use of Dependency Injection (as suggested by the many interface/service implementations) for modularity, testability, and loose coupling.
- The MVC pattern is in use in both the admin and customer web applications (with controllers, views, and models clearly separated).
- The API project follows RESTful principles providing stateless communication to the client side.
- Background processing is separated as a worker service to run asynchronous, scheduled tasks.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        AdminApp("Admin Web Application (MVC)"):::presentation
        CustomerApp("Customer Web Application (MVC)"):::presentation
    end

    %% API Layer
    subgraph "API Layer"
        API("Backend API"):::api
    end

    %% Business Logic & Data Access
    subgraph "Business Logic & Data Access"
        AppLayer("Application Layer"):::business
        DataLayer("Data Access Layer"):::business
        Database("Database (Azure DB)"):::data
    end

    %% Background Services
    subgraph "Background Services"
        BgService("Background Service Worker"):::background
    end

    %% Shared Libraries
    subgraph "Shared Libraries"
        Utils("Utilities"):::shared
        ViewModels("View Models"):::shared
    end

    %% External Integrations
    subgraph "External Integrations"
        Firebase("Firebase"):::external
        VNPay("VNPay Sandbox"):::external
        PayPal("PayPal"):::external
        OAuth("OAuth"):::external
    end

    %% Connections from Presentation Layer to API and Business Layer
    AdminApp -->|"HTTP_Request"| API
    CustomerApp -->|"HTTP_Request"| API

    AdminApp -->|"Direct_Call"| AppLayer
    CustomerApp -->|"Direct_Call"| AppLayer

    %% API calls Business Logic
    API -->|"Calls_BusinessLogic"| AppLayer

    %% Business Logic to Data Access and Database
    AppLayer -->|"Repository_Call"| DataLayer
    DataLayer -->|"Database_Query"| Database

    %% Background Service interaction
    BgService -->|"Background_Task"| AppLayer

    %% External Integrations feeding into Presentation Layer
    Firebase -->|"Authentication/Payment"| AdminApp
    Firebase -->|"Authentication/Payment"| CustomerApp

    VNPay -->|"Authentication/Payment"| AdminApp
    VNPay -->|"Authentication/Payment"| CustomerApp

    PayPal -->|"Authentication/Payment"| AdminApp
    PayPal -->|"Authentication/Payment"| CustomerApp

    OAuth -->|"Authentication/Payment"| AdminApp
    OAuth -->|"Authentication/Payment"| CustomerApp

    %% Shared Libraries used by multiple components (dashed connectors)
    AdminApp -.->|"Uses"| Utils
    AdminApp -.->|"Uses"| ViewModels

    CustomerApp -.->|"Uses"| Utils
    CustomerApp -.->|"Uses"| ViewModels

    API -.->|"Uses"| Utils
    API -.->|"Uses"| ViewModels

    AppLayer -.->|"Uses"| Utils
    AppLayer -.->|"Uses"| ViewModels

    BgService -.->|"Uses"| Utils
    BgService -.->|"Uses"| ViewModels

    %% Click Events
    click AdminApp "https://github.com/nttung2k3k/diamondluxurywebapp/blob/main/DiamondLuxurySolution/DiamondLuxurySolution.AdminCrewApp"
    click CustomerApp "https://github.com/nttung2k3k/diamondluxurywebapp/blob/main/DiamondLuxurySolution/DiamondLuxurySolution.WebApp"
    click API "https://github.com/nttung2k3k/diamondluxurywebapp/blob/main/DiamondLuxurySolution/DiamondLuxurySolution.BackendApi"
    click AppLayer "https://github.com/nttung2k3k/diamondluxurywebapp/blob/main/DiamondLuxurySolution/DiamondLuxurySolution.Application"
    click DataLayer "https://github.com/nttung2k3k/diamondluxurywebapp/blob/main/DiamondLuxurySolution/DiamondLuxurySolution.Data"
    click Utils "https://github.com/nttung2k3k/diamondluxurywebapp/blob/main/DiamondLuxurySolution/DiamondLuxurySolution.Utilities"
    click ViewModels "https://github.com/nttung2k3k/diamondluxurywebapp/blob/main/DiamondLuxurySolution/DiamondLuxurySolution.ViewModel"
    click BgService "https://github.com/nttung2k3k/diamondluxurywebapp/blob/main/DiamondLuxurySolution/DiamondLuxurySolution.BackgroundServiceHost"

    %% Styles
    classDef presentation fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef api fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef business fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef data fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef background fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef shared fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef external fill:#fdfd96,stroke:#ffcc00,stroke-width:2px;
```
