# trhiep/license-key-shop architecture

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

- Interactive diagram: https://gitdiagram.com/trhiep/license-key-shop
- Repository: https://github.com/trhiep/license-key-shop

## Overview

##### Project Type and Purpose
- The project is a web application built using ASP.NET (MVC/Razor Pages) as seen by folders like Controllers, Models, Views, and Pages.
- Its purpose—as per the assignment context (PRN211 Assignment Fall23) and use of a website template—is to serve as an online license key shop with functionalities such as product management, user registration/login, order history, and payment/deposit processing.

##### Main Architectural Components
A. Client/Browser:
- End-users accessing the shop through a web browser.
B. Web Server (Application Layer):
- Controllers: Handle incoming HTTP requests (e.g., AdminController, CartController, ProductManagementController, etc.).
- Models: Define data structures and business objects (e.g., User, Product, OrderHistory) including ORM context (LicenseShopDBContext) hinting at Entity Framework usage.
- Views & Pages: Render the UI using Razor templates (found under Views, Pages, and Shared folders). Separate layouts for admin and customer areas are available.
C. Data Access Layer:
- The ADO folder (with files like OrderHistoryADO.cs) and LicenseShopDBContext in Models provide the database integration layer.
- Underlying database (e.g., SQL Server) that stores user, product, order, and payment data.
D. Utilities and External Integration:
- The Utils folder contains helper classes (CloudinaryUploader, EmailSender, EncryptionMethods, Payment models, and VnPayService) that integrate with external services (cloud storage, email, payment gateway).
- MyInterface defines contracts like IEmailSender and IVnPayService, outlining the abstraction for external services.
E. Static Assets:
- The wwwroot folder holds CSS, JavaScript, images, and third-party libraries (Bootstrap, jQuery, TinyMCE, etc.) needed for the front-end presentation.

##### Relationships and Interactions
- The client initiates requests via the browser, which hit the web server.
- The Controllers process these requests, potentially using the Models for business logic and data.
- When persistent data is needed, controllers interact with the Data Access Layer (using LicenseShopDBContext/ADO classes) to communicate with the database.
- The Utilities layer provides additional services such as emailing, file uploads (Cloudinary), and payment processing (VnPay), which may be invoked by controllers or business logic.
- Views and Pages are used to render the results back to the client.

##### Architectural Patterns and Principles
- MVC (Model-View-Controller) is the primary pattern used. This enforces separation of concerns between the UI (Views/Pages), the business logic (Controllers/Models), and data access.
- There is also a layering principle, with clear boundaries between presentation, business logic, data access, and utility/integration layers.
- Abstraction via interfaces (e.g., IEmailSender, IVnPayService) allows for flexibility and easier testing.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Client Layer
    ClientBrowser["Client Browser"]:::client

    %% Web Server Layer
    subgraph "Web Server"
        Controllers["Controllers"]:::web
        Models["Models & DB Context"]:::web
        Views["Views"]:::web
        Pages["Pages"]:::web
    end

    %% Data Access Layer
    ADO["Data Access (ADO)"]:::data

    %% Database
    DB["Database (SQL Server)"]:::database

    %% Utilities & External Integration
    subgraph "Utilities & External Integration"
        Helper["Helper Classes"]:::utils
        Interfaces["Service Interfaces"]:::utils
    end

    %% Connections
    ClientBrowser -->|"HTTP_Request"| Controllers
    Controllers -->|"Uses_logic"| Models
    Models -->|"ORM_Query"| DB
    Controllers -->|"Direct_DB"| ADO
    ADO -->|"Data_Manipulation"| DB
    Controllers -->|"Invokes_API"| Helper
    Controllers -->|"Uses_Interface"| Interfaces
    Controllers -->|"Renders_View"| Views
    Controllers -->|"Renders_Page"| Pages
    Views -->|"Delivers_UI"| ClientBrowser
    Pages -->|"Delivers_UI"| ClientBrowser

    %% Click Events
    click ClientBrowser "https://github.com/trhiep/license-key-shop/tree/master/License-Key-Shop-Web/wwwroot"
    click Controllers "https://github.com/trhiep/license-key-shop/tree/master/License-Key-Shop-Web/Controllers"
    click Models "https://github.com/trhiep/license-key-shop/tree/master/License-Key-Shop-Web/Models"
    click Views "https://github.com/trhiep/license-key-shop/tree/master/License-Key-Shop-Web/Views"
    click Pages "https://github.com/trhiep/license-key-shop/tree/master/License-Key-Shop-Web/Pages"
    click ADO "https://github.com/trhiep/license-key-shop/tree/master/License-Key-Shop-Web/ADO"
    click Helper "https://github.com/trhiep/license-key-shop/tree/master/License-Key-Shop-Web/Utils"
    click Interfaces "https://github.com/trhiep/license-key-shop/tree/master/License-Key-Shop-Web/MyInterface"

    %% Styles
    classDef client fill:#F8CECC,stroke:#B85450,stroke-width:2px;
    classDef web fill:#D5E8D4,stroke:#82B366,stroke-width:2px;
    classDef data fill:#cfe2f3,stroke:#6fa8dc,stroke-width:2px;
    classDef database fill:#d9ead3,stroke:#6aa84f,stroke-width:2px;
    classDef utils fill:#fff2cc,stroke:#f1c232,stroke-width:2px;
```
