# thuha307/luna architecture

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

- Interactive diagram: https://gitdiagram.com/thuha307/luna
- Repository: https://github.com/thuha307/luna

## Overview

##### Project Type & Overall Purpose
- Luna is a full‐stack ASP.NET (likely Core) web application that employs an MVC design pattern, with clearly separated “Areas” such as Admin, Chat, Customer, Identity, and Staff.
- Although the README is brief (“# Luna”), the file tree reveals a multi–area hotel or service management system with customer-facing booking (e.g., Room, HotelOrder, WishList) and administrative functionalities along with real–time chat (via SignalR) and integrated payment processing (VNPay).

##### High-Level Components
- Presentation Layer:
– Client Side: HTML/CSS/JavaScript from the wwwroot folder. This includes the various UI assets (admin layout, custom JavaScript like chatbot, main.js, etc.), libraries (Bootstrap, jQuery, OwlCarousel) and third–party client plugins.
– Views organized by Areas (Admin, Customer, Staff, Chat, Identity).
- Application Layer:
– Controllers: Located in the “Areas” folders and the root Controllers folder (e.g., HomeController.cs).
– Areas: Separate modules for Admin, Customer, Chat, Identity, and Staff that encapsulate specific business processes.
– Hubs: The SignalR ChatHub for real–time communication.
- Service/Business Logic Layer:
– Services folder: Contains business services (e.g., GlobalService, HangfireJobs, JobService, SendMailService, SentimentAnalysisService).
– Domain Models: Under both root “Models” and Area-specific models.
- Data Access Layer:
– “Data/AppDbContext.cs” – the EF Core database context.
– Migrations folder: Handles database schema versioning.
- Integration / External Services:
– Payment gateway integration (VNPay controllers and library).
– Email services (e.g., SendMailService and email save folder).
– Real–time communication (SignalR via Hubs/ChatHub.cs).
– Background job processing (Hangfire jobs).
– ASP.NET Identity under Areas/Identity for authentication and authorization.
- Infrastructure/Configuration:
– Appsettings files for environment configuration.
– Configuration files like dotnet-tools.json, launchSettings.json.
– External client libraries (under wwwroot/lib and plugins).

##### Relationships and Flows
– From the client browser to the web server via HTTP/HTTPS calls (MVC controller actions).
– From the server’s controllers (in various Areas) to the service layer and then to the database via the EF Core context.
– Separate flows for authentication (using ASP.NET Identity) and payment (via VNPay integration).
– Background jobs (Hangfire) are triggered from the service layer and operate asynchronously, interacting with the database as needed.
- Dependency relationships:
– Controllers depend on services.
– Services depend on domain models and the data context.
– Third-party libraries support both UI (via wwwroot) and real–time or asynchronous operations.

##### Architectural Patterns & Design Principles
- MVC Pattern: Controllers handling HTTP requests, Views presenting data, Models representing business data.
- Layered Architecture: Clean division between presentation, business logic (services), and data access (repository/DbContext).
- Modularization: “Areas” are used to logically separate modules (Admin, Customer, Chat, etc.), ensuring that each module is self–contained.
- Asynchronous Processing: Use of SignalR for real-time communication and Hangfire for background jobs.
- Dependency Injection: Likely used within the Program.cs and Startup configurations (not detailed but inferred by convention).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        UI("Client Browser (UI)"):::ui
        Assets("Static Assets"):::ui
        AdminViews("Admin Views"):::ui
        CustViews("Customer Views"):::ui
        ChatViews("Chat Views"):::ui
        IdentityPages("Identity Pages"):::ui
        StaffViews("Staff Views"):::ui
    end

    %% Application Layer
    subgraph "Application Layer"
        HomeCtrl("Home Controller"):::controller
        AdminCtrl("Admin Controllers"):::controller
        CustCtrl("Customer Controllers"):::controller
        ChatCtrl("Chat Controllers"):::controller
        StaffCtrl("Staff Controllers"):::controller
        SignalRHub("SignalR Hub"):::controller
    end

    %% Service/Business Logic Layer
    subgraph "Service Layer"
        BusServices("Business Services"):::service
        SharedModels("Shared Models"):::service
        AdminModels("Admin Models"):::service
        ChatModels("Chat Models"):::service
        CustModels("Customer Models"):::service
        StaffModels("Staff Models"):::service
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        DbContext("EF Core (AppDbContext)"):::database
        Migrations("Migrations"):::database
    end

    %% External Integration / Services
    subgraph "External Integrations"
        VNPay("VNPay Integration"):::integration
        EmailService("Email Service"):::integration
        SignalRLib("SignalR Client Lib"):::integration
        Hangfire("Background Jobs (Hangfire)"):::integration
    end

    %% Infrastructure / Configuration
    subgraph "Infrastructure/Configuration"
        AppSettings("App Settings"):::infra
        LaunchSettings("Launch Settings"):::infra
        ProgramStart("Program Startup"):::infra
        ToolConfigs("Tool Configurations"):::infra
    end

    %% Flow Relationships
    %% From Presentation to Application Layer
    UI -->|"HTTP_Request"| HomeCtrl
    UI ---|"HTTP_Request"| AdminCtrl
    UI ---|"HTTP_Request"| CustCtrl
    UI ---|"HTTP_Request"| ChatCtrl
    UI ---|"HTTP_Request"| StaffCtrl

    %% UI and SignalR bi-directional communication
    UI <-->|"SignalR_Message"| SignalRHub

    %% Presentation Layer internal - assets and views (for context)
    Assets -->|"provides"| AdminViews
    Assets -->|"provides"| CustViews
    Assets -->|"provides"| ChatViews
    Assets -->|"provides"| IdentityPages
    Assets -->|"provides"| StaffViews
    UI -->|"loads"| Assets
    Assets -->|"loads"| SignalRLib

    %% Application Layer to Service Layer
    HomeCtrl -->|"Service_Call"| BusServices
    AdminCtrl -->|"Service_Call"| BusServices
    CustCtrl -->|"Service_Call"| BusServices
    ChatCtrl -->|"Service_Call"| BusServices
    StaffCtrl -->|"Service_Call"| BusServices

    %% Specific Customer Controller integration with VNPay
    CustCtrl -->|"Payment_Request"| VNPay

    %% Service Layer to Domain Models
    BusServices -->|"Uses"| SharedModels
    BusServices -->|"Uses"| AdminModels
    BusServices -->|"Uses"| ChatModels
    BusServices -->|"Uses"| CustModels
    BusServices -->|"Uses"| StaffModels

    %% Service Layer to Data Access
    BusServices -->|"DB_Query"| DbContext

    %% Service Layer triggering external integrations
    BusServices -->|"Send_Email"| EmailService
    BusServices -->|"Trigger_Job"| Hangfire

    %% Data Access internal dependency
    DbContext -->|"Schema_Info"| Migrations

    %% Infrastructure dependencies (not flow but configuration)
    ProgramStart -->|"Initializes"| HomeCtrl
    AppSettings -->|"Configures"| HomeCtrl
    ToolConfigs -->|"Provides_Tools"| ProgramStart
    LaunchSettings -->|"Defines_Env"| ProgramStart

    %% Click Events for Presentation Layer
    click Assets "https://github.com/thuha307/luna/tree/master/Luna/wwwroot"
    click AdminViews "https://github.com/thuha307/luna/tree/master/Luna/Areas/Admin/Views"
    click CustViews "https://github.com/thuha307/luna/tree/master/Luna/Areas/Customer/Views"
    click ChatViews "https://github.com/thuha307/luna/tree/master/Luna/Areas/Chat/Views"
    click IdentityPages "https://github.com/thuha307/luna/tree/master/Luna/Areas/Identity/Pages"
    click StaffViews "https://github.com/thuha307/luna/tree/master/Luna/Areas/Staff/Views"

    %% Click Events for Application Layer
    click HomeCtrl "https://github.com/thuha307/luna/blob/master/Luna/Controllers/HomeController.cs"
    click AdminCtrl "https://github.com/thuha307/luna/tree/master/Luna/Areas/Admin/Controllers"
    click CustCtrl "https://github.com/thuha307/luna/tree/master/Luna/Areas/Customer/Controllers"
    click ChatCtrl "https://github.com/thuha307/luna/tree/master/Luna/Areas/Chat/Controllers"
    click StaffCtrl "https://github.com/thuha307/luna/tree/master/Luna/Areas/Staff/Controllers"
    click SignalRHub "https://github.com/thuha307/luna/blob/master/Luna/Hubs/ChatHub.cs"

    %% Click Events for Service Layer
    click BusServices "https://github.com/thuha307/luna/tree/master/Luna/Services"
    click SharedModels "https://github.com/thuha307/luna/tree/master/Luna/Models"
    click AdminModels "https://github.com/thuha307/luna/tree/master/Luna/Areas/Admin/Models"
    click ChatModels "https://github.com/thuha307/luna/tree/master/Luna/Areas/Chat/Models"
    click CustModels "https://github.com/thuha307/luna/tree/master/Luna/Areas/Customer/Models"
    click StaffModels "https://github.com/thuha307/luna/tree/master/Luna/Areas/Staff/Models"

    %% Click Events for Data Access Layer
    click DbContext "https://github.com/thuha307/luna/blob/master/Luna/Data/AppDbContext.cs"
    click Migrations "https://github.com/thuha307/luna/tree/master/Luna/Migrations"

    %% Click Events for External Integrations
    click VNPay "https://github.com/thuha307/luna/blob/master/Luna/Areas/Customer/Controllers/VNPayController.cs"
    click EmailService "https://github.com/thuha307/luna/blob/master/Luna/Services/SendMailService.cs"
    click SignalRLib "https://github.com/thuha307/luna/tree/master/Luna/wwwroot/lib/microsoft/signalr"
    click Hangfire "https://github.com/thuha307/luna/blob/master/Luna/Services/HangfireJobs.cs"

    %% Click Events for Infrastructure/Configuration
    click AppSettings "https://github.com/thuha307/luna/blob/master/Luna/appsettings.json"
    click LaunchSettings "https://github.com/thuha307/luna/blob/master/Luna/Properties/launchSettings.json"
    click ProgramStart "https://github.com/thuha307/luna/blob/master/Luna/Program.cs"
    click ToolConfigs "https://github.com/thuha307/luna/blob/master/Luna/.config/dotnet-tools.json"

    %% Styling Classes
    classDef ui fill:#add8e6,stroke:#000,stroke-width:1px;
    classDef controller fill:#87cefa,stroke:#000,stroke-width:1px;
    classDef service fill:#98fb98,stroke:#000,stroke-width:1px;
    classDef database fill:#ffcc99,stroke:#000,stroke-width:1px;
    classDef integration fill:#dda0dd,stroke:#000,stroke-width:1px;
    classDef infra fill:#d3d3d3,stroke:#000,stroke-width:1px;
```
