# phuhoang07/swd_group05_be architecture

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

- Interactive diagram: https://gitdiagram.com/phuhoang07/swd_group05_be
- Repository: https://github.com/phuhoang07/swd_group05_be

## Overview

##### Main Components
- Presentation Layer:
- The “GoodsExchangeAtFUManagement” project contains Controllers (e.g., AuthenticationController, CampusController, etc.) that expose Web API endpoints.
- A ChatHub for real-time communications hints at SignalR usage.
- Middlewares (AuthorizeMiddleware, GlobalExceptionMiddleware) that handle security and error handling.

- Service Layer:
- The “GoodsExchangeAtFUManagement.Service” project includes many domain-specific services (AuthenticationService, CampusService, CategoryService, CoinPackService, etc.) that encapsulate business logic.
- Utility classes (JwtGenerator, PasswordHasher, CustomException, etc.) support cross-cutting concerns.

- Repository/Data Access Layer:
- The “GoodsExchangeAtFUManagement.Repository” implements repository patterns for each domain (e.g., ICampusRepository, ICategoryRepository) with direct mappings in the “GoodsExchangeAtFUManagement.DAO”.
- The “GoodsExchangeAtFUManagement.DAO” includes the DB context (GoodsExchangeAtFuContext) and generic data access methods.

- Business Objects/Domain Models:
- The “BusinessObjects” folder contains DTOs, models, enums, and custom data annotations that define the domain structure and data transfer contracts across layers.

- Database:
- The SQL script file (ScriptDB_v1.0.sql) suggests an underlying database where the entities are stored.

##### Relationships and Data Flow
- UI/API (Controllers) makes calls to Services.
- Services handle business logic then interact with the Repository layer using the repository interfaces.
- The Repository accesses the database via the Data Access (DAO) layer.
- Communication between layers is facilitated using DTOs defined in the BusinessObjects.
- The SignalR Hub (ChatHub) in the presentation layer is used for facilitating real-time client-server communication.
- Utility classes (found in the “Ultis” folder) are leveraged across layers for tasks like JWT token generation, password hashing, and email handling.
- External interactions include payment integrations via VnPay and email functionality.

##### Architectural Patterns and Design Principles
- Layered (n-tier) Architecture separating presentation, service, repository, and data access.
- Repository Pattern to abstract and encapsulate data access logic.
- Dependency Injection is likely used, as indicated by the use of interfaces (e.g., IUserService, ICategoryRepository).
- Use of DTOs and custom annotations to clearly define contracts and validation.
- SignalR integration provides a dedicated component for handling real-time communications.

##### Essential Architectural Elements
- Clearly delineate the flow from the front-end (API controllers and SignalR hubs) through the service layer to the repository/DAO and finally to the database.
- Cross-layer utilities (JWT generation, email handling) separately to show how they support the main workflow.
- Use of interfaces and dependency injection by noting the “IService” and “IRepository” naming conventions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        Controllers["Controllers (Web API)"]
        ChatHub["SignalR Hub (ChatHub)"]
        Middlewares["Middlewares (Security & Exception)"]
    end

    %% Service Layer
    subgraph "Service Layer"
        Services["Domain Services (AuthenticationService, CampusService, etc.)"]
        Utilities["Utility Classes (JwtGenerator, PasswordHasher, etc.)"]
    end

    %% Repository/Data Access Layer
    subgraph "Repository/Data Access Layer"
        Repositories["Repositories (IRepository implementations)"]
        DAO["Data Access (GoodsExchangeAtFuContext & GenericDAO)"]
    end

    %% Business Objects / Domain Models
    subgraph "Business Objects / Domain Models"
        Business["Business Objects & DTOs"]
    end

    %% Database
    subgraph "Database"
        Database["SQL Database (ScriptDB_v1.0.sql)"]
    end

    %% External Integrations
    subgraph "External Integrations"
        ExternalSystems["VnPay & Email Services"]
    end

    %% Relationships
    Controllers -->|"RequestResponse"| Services
    ChatHub -->|"RealTimeUpdates"| Services
    Middlewares --- Controllers
    Services -->|"BusinessLogic"| Repositories
    Repositories -->|"DataQuerying"| DAO
    DAO -->|"DatabaseAccess"| Database
    Services -->|"Uses"| Utilities
    Services ---|"DataContracts"| Business
    Repositories ---|"Uses"| Business
    Services -->|"Integrates"| ExternalSystems

    %% Click Events
    click Controllers "https://github.com/phuhoang07/swd_group05_be/tree/master/GoodsExchangeAtFUManagement/Controllers"
    click ChatHub "https://github.com/phuhoang07/swd_group05_be/blob/master/GoodsExchangeAtFUManagement/Hubs/ChatHub.cs"
    click Middlewares "https://github.com/phuhoang07/swd_group05_be/tree/master/GoodsExchangeAtFUManagement/Middlewares"
    click Services "https://github.com/phuhoang07/swd_group05_be/tree/master/GoodsExchangeAtFUManagement.Service/Services"
    click Utilities "https://github.com/phuhoang07/swd_group05_be/tree/master/GoodsExchangeAtFUManagement.Service/Ultis"
    click Repositories "https://github.com/phuhoang07/swd_group05_be/tree/master/GoodsExchangeAtFUManagement.Repository/Repositories"
    click DAO "https://github.com/phuhoang07/swd_group05_be/blob/master/GoodsExchangeAtFUManagement.DAO"
    click Business "https://github.com/phuhoang07/swd_group05_be/tree/master/BusinessObjects"
    click Database "https://github.com/phuhoang07/swd_group05_be/blob/master/ScriptDB_v1.0.sql"

    %% Styles
    class Controllers,ChatHub,Middlewares presentation
    class Services,Utilities service
    class Repositories,DAO repo
    class Business domain
    class Database db
    class ExternalSystems external

    %% Class Definitions with Colors
    classDef presentation fill:#FAD7A0,stroke:#C0392B,stroke-width:2px;
    classDef service fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
    classDef repo fill:#AED6F1,stroke:#2874A6,stroke-width:2px;
    classDef domain fill:#A9DFBF,stroke:#229954,stroke-width:2px;
    classDef db fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef external fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
```
