# tnjkl/websitebanmohinh architecture

> Architecture diagram of the GitHub repository tnjkl/websitebanmohinh, 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/tnjkl/websitebanmohinh
- Repository: https://github.com/tnjkl/websitebanmohinh

## Overview

##### Main Components
- Frontend / Public Site: Represented by the “Controllers” (e.g., HomeController, ProductController, CartController, etc.), “Views” (located in Views folders for Account, Home, Product, etc.) and the static content in “wwwroot” (including CSS, JavaScript, images, and media). This forms the user-facing part of the application.
- Admin Area: Located under “Areas/Admin” with its own Controllers, Views, and Repository, dedicated to managing products, orders, roles, users, etc.
- Business Logic & Services Layer: Consisting of Helpers, Services (e.g., Momo and Vnpay payment services), and Repository components that encapsulate data access and business logic.
- Data Access Layer: The “Repository” folder and DataContext, along with the “Migrations” folder, indicate the use of Entity Framework for interacting with a SQL database.
- Models: All the domain models (ProductModel, CategoryModel, OrderModel, etc.) representing the data structures used throughout the application.
- External Integrations: Payment integration libraries are present (VnPayLibrary, Momo service components), and Identity management is used (e.g., roles, users seeded in SeedData) which might use a third-party OAuth (per the README’s instructions to set up Google OAuth keys).
- Real-Time Communication: The “Hubs” folder with the ChatHub indicates support for real-time chat features (using SignalR).

##### Relationships and Interactions
- The Client Layer (User's Browser) sends HTTP requests to the Web Server.
- The Controllers (both in the Public area and Admin area) handle incoming requests, interact with the Services and Repositories to process business logic, and then render Views (via the MVC pattern).
- The Data Access layer (using DataContext and Entity Framework) interfaces with the SQL Database. This includes typical CRUD operations and data seeding (SeedData).
- External payment services (Momo and VnPay) are connected via dedicated Service layers and Libraries, which the PaymentController and payment services in views use to process transactions.
- SignalR’s ChatHub enables real-time messaging, which is used by the Messages components.

##### Architectural Patterns and Design Principles
- MVC (Model-View-Controller): The structure clearly separates Presentation (Views), Business Logic (Controllers and Services), and Data Access (Models and Repositories).
- Separation of Concerns: The Admin area is separated into its own folder and uses its version of Controllers, Views, and Repositories.
- Integration of External Services: Payment processing and OAuth authentication are integrated modules.

##### Relevant Technologies and Frameworks
- ASP.NET MVC and Entity Framework for the web application and data persistence.
- SignalR for real-time chat support.
- Identity Framework for user and role management.
- Frontend libraries such as Bootstrap, jQuery, and additional libraries for validation and other UI enhancements.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Browser("Browser Client"):::client

    subgraph "Web Server - Public Site"
        direction TB
        PublicControllers("Public Controllers"):::controller
        PublicViews("Public Views"):::view
        PublicAssets("Static Assets"):::static
    end

    subgraph "Web Server - Admin Area"
        direction TB
        AdminControllers("Admin Controllers"):::controller
        AdminViews("Admin Views"):::view
        AdminRepository("Admin Repository"):::repository
    end

    subgraph "Business Logic & Services"
        direction TB
        Helpers("Helpers"):::service
        MomoService("Momo Payment Service"):::payment
        VnPayService("VnPay Payment Service"):::payment
    end

    subgraph "Data Access Layer"
        direction TB
        Repository("Main Repository & DataContext"):::repository
        Migrations("Migrations"):::database
    end

    subgraph "Models"
        direction TB
        DomainModels("Domain Models"):::model
        ViewModels("View Models"):::model
    end

    subgraph "External Integrations"
        direction TB
        VnPayLibrary("VnPay Library"):::external
        MomoPaymentModels("Momo Payment Models"):::external
        OAuth("OAuth/Identity"):::external
    end

    subgraph "Real-Time Communication"
        direction TB
        SignalRHub("SignalR ChatHub"):::realtime
    end

    SQLDB(("SQL Database")):::sql

    %% Data Flow Connections
    Browser -->|"HTTP_Request"| PublicControllers
    Browser -->|"HTTP_Request"| AdminControllers
    Browser -->|"real-time"| SignalRHub

    PublicControllers -->|"RenderView"| PublicViews
    AdminControllers -->|"RenderView"| AdminViews

    PublicControllers -->|"Calls"| Helpers
    PublicControllers -->|"Calls"| MomoService
    PublicControllers -->|"Calls"| VnPayService

    AdminControllers -->|"Uses"| AdminRepository

    Helpers -->|"Accesses"| Repository
    MomoService -->|"Accesses"| Repository
    VnPayService -->|"Accesses"| Repository

    Repository -->|"CRUD"| SQLDB

    PublicControllers -->|"Uses"| DomainModels
    AdminControllers -->|"Uses"| DomainModels
    PublicViews -->|"Binds"| ViewModels
    AdminViews -->|"Binds"| ViewModels

    MomoService -->|"Integrates"| MomoPaymentModels
    VnPayService -->|"Integrates"| VnPayLibrary

    %% External OAuth used by Controllers (implicit relationship)
    PublicControllers -->|"AuthChecks"| OAuth
    AdminControllers -->|"AuthChecks"| OAuth

    %% Real-Time Communication response
    SignalRHub -->|"PushUpdates"| Browser

    %% Click Events
    click PublicControllers "https://github.com/tnjkl/websitebanmohinh/tree/master/WebSiteBanMoHinh/Controllers"
    click PublicViews "https://github.com/tnjkl/websitebanmohinh/tree/master/WebSiteBanMoHinh/Views"
    click PublicAssets "https://github.com/tnjkl/websitebanmohinh/tree/master/WebSiteBanMoHinh/wwwroot"
    click AdminControllers "https://github.com/tnjkl/websitebanmohinh/tree/master/WebSiteBanMoHinh/Areas/Admin/Controllers"
    click AdminViews "https://github.com/tnjkl/websitebanmohinh/tree/master/WebSiteBanMoHinh/Areas/Admin/Views"
    click AdminRepository "https://github.com/tnjkl/websitebanmohinh/tree/master/WebSiteBanMoHinh/Areas/Admin/Repository"
    click Helpers "https://github.com/tnjkl/websitebanmohinh/tree/master/WebSiteBanMoHinh/Helpers"
    click MomoService "https://github.com/tnjkl/websitebanmohinh/tree/master/WebSiteBanMoHinh/Services/Momo"
    click VnPayService "https://github.com/tnjkl/websitebanmohinh/tree/master/WebSiteBanMoHinh/Services/Vnpay"
    click Repository "https://github.com/tnjkl/websitebanmohinh/tree/master/WebSiteBanMoHinh/Repository"
    click Migrations "https://github.com/tnjkl/websitebanmohinh/tree/master/WebSiteBanMoHinh/Migrations"
    click DomainModels "https://github.com/tnjkl/websitebanmohinh/tree/master/WebSiteBanMoHinh/Models"
    click ViewModels "https://github.com/tnjkl/websitebanmohinh/tree/master/WebSiteBanMoHinh/Models/ViewModels"
    click VnPayLibrary "https://github.com/tnjkl/websitebanmohinh/blob/master/WebSiteBanMoHinh/Libraries/VnPayLibrary.cs"
    click MomoPaymentModels "https://github.com/tnjkl/websitebanmohinh/tree/master/WebSiteBanMoHinh/Models/Momo"
    click SignalRHub "https://github.com/tnjkl/websitebanmohinh/blob/master/WebSiteBanMoHinh/Hubs/ChatHub.cs"

    %% Styles
    classDef client fill:#f9f,stroke:#333,stroke-width:2px;
    classDef controller fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef view fill:#ffe6cc,stroke:#ff6600,stroke-width:2px;
    classDef static fill:#ffffcc,stroke:#cccc00,stroke-width:2px;
    classDef repository fill:#ccffcc,stroke:#006600,stroke-width:2px;
    classDef service fill:#cce5ff,stroke:#0033cc,stroke-width:2px;
    classDef payment fill:#d1cfdc,stroke:#665588,stroke-width:2px;
    classDef database fill:#f2d7d5,stroke:#a93226,stroke-width:2px;
    classDef sql fill:#fadbd8,stroke:#d35400,stroke-width:2px;
    classDef model fill:#d5f5e3,stroke:#27ae60,stroke-width:2px;
    classDef external fill:#e8daef,stroke:#8e44ad,stroke-width:2px;
    classDef realtime fill:#d6eaf8,stroke:#3498db,stroke-width:2px;
```
