# capstone-rhcqs/rhcqs_be architecture

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

- Interactive diagram: https://gitdiagram.com/capstone-rhcqs/rhcqs_be
- Repository: https://github.com/capstone-rhcqs/rhcqs_be

## Overview

##### Main Components
- API Controllers (found in the “RHCQS_BE/Controllers” folder): These serve as entry points for the various functionalities such as account handling, quotation processing, chat, notifications, file uploads, etc.
- Middleware Components (e.g., ExceptionHandlingMiddleware, AuthorizationHandlingMiddleware): These are crucial for handling cross-cutting concerns like authentication and error management.
- SignalR Hub (RHCQS_BE/Hubs): Particularly the ChatHub that manages real-time chat features.
- Business Objects (RHCQS_BusinessObject): Houses domain objects, payloads (both request and response DTOs), helpers, and pagination utilities.
- Data Access Layer (RHCQS_DataAccessObjects): Consists of database context (RhcqsContext) and model classes that map to SQL Server entities.
- Repository Layer (RHCQS_Repositories): Implements the repository and unit-of-work patterns to provide a decoupled data access API.
- Service Layer (RHCQS_Services): Contains business logic implementations for managing accounts, tasks, quotations, projects, chat, and integrations with external services like Cloudinary and Firebase.
- External Integrations: Third-party libraries and integrations (Cloudinary, Firebase, Mail) that are used to support features like file uploading, notifications, or real-time messaging.

##### Relationships and Interactions
- Clients (web or mobile) send requests to API Controllers.
- Controllers call Service interfaces to process business logic.
- Services use Repository interfaces to interact with the Data Access Layer and perform CRUD operations on the SQL Server.
- The Repository layer interacts with Entity Framework (as suggested by the use of models and context) to communicate with the database.
- Middleware components intercept incoming requests to handle errors, authentication, and authorization.
- SignalR Hubs manage real-time communications, particularly for chat functions.
- External services are integrated within the service layer (e.g., GmailSenderService for emails, FirebaseService for notifications) to handle external communication needs.

##### Architectural Patterns and Design Principles Highlighted
- Layered Architecture / N-tier: Clear separations among Controller (presentation), Service (business logic), Repository (data access), and Data Models.
- MVC / API-based Design: The Controllers are dedicated to handling HTTP routes, likely following RESTful API standards.
- Dependency Injection: Evident from the extensive separation of interfaces and implementation (e.g., in Services and Repositories).
- Use of Repository and Unit of Work patterns ensures data consistency and decoupling of the data access logic from business logic.

## Diagram (Mermaid)

```mermaid
graph TD
    Client["Clients (Web/Mobile)"]:::external

    subgraph "RHCQS_BE (API Layer)"
        APIC["API Controllers"]:::controllers
        Middleware["Middlewares"]:::middlewares
        ChatHub["SignalR ChatHub"]:::hubs
    end

    subgraph "Service Layer (RHCQS_Services)"
        Services["Service Layer"]:::services
        ExternalInt["External Integrations"]:::external
        FirebaseConfig["Firebase Admin Config"]:::external
    end

    subgraph "Repository Layer (RHCQS_Repositories)"
        Repos["Repository Layer"]:::repos
    end

    subgraph "Business Objects"
        BO["Business Objects"]:::business
    end

    subgraph "Data Access Layer (RHCQS_DataAccessObjects)"
        Context["DbContext (RhcqsContext)"]:::data
        DataModels["Data Models"]:::data
    end

    SQL["SQL Server DB"]:::data

    Client -->|"Request"| Middleware
    Middleware -->|"Passes"| APIC
    APIC -->|"Handles"| Services
    APIC -->|"RealTime"| ChatHub
    APIC -->|"UsesDTOs"| BO
    Services -->|"Utilizes"| BO
    Services -->|"Calls"| Repos
    Services -->|"IntegratesWith"| ExternalInt
    ExternalInt -->|"UsesConfig"| FirebaseConfig
    Repos -->|"Accesses"| Context
    Repos -->|"Accesses"| DataModels
    Context -->|"CRUD"| SQL
    DataModels -->|"MapsTo"| SQL

    click APIC "https://github.com/capstone-rhcqs/rhcqs_be/tree/main/RHCQS_BE/Controllers"
    click Middleware "https://github.com/capstone-rhcqs/rhcqs_be/tree/main/RHCQS_BE/Middlewares"
    click ChatHub "https://github.com/capstone-rhcqs/rhcqs_be/blob/main/RHCQS_BE/Hubs/ChatHub.cs"
    click BO "https://github.com/capstone-rhcqs/rhcqs_be/tree/main/RHCQS_BusinessObject"
    click Context "https://github.com/capstone-rhcqs/rhcqs_be/tree/main/RHCQS_DataAccessObjects/Context"
    click DataModels "https://github.com/capstone-rhcqs/rhcqs_be/tree/main/RHCQS_DataAccessObjects/Models"
    click Repos "https://github.com/capstone-rhcqs/rhcqs_be/tree/main/RHCQS_Repositories"
    click Services "https://github.com/capstone-rhcqs/rhcqs_be/tree/main/RHCQS_Services"
    click ExternalInt "https://github.com/capstone-rhcqs/rhcqs_be/tree/main/RHCQS_Services/Implement"
    click FirebaseConfig "https://github.com/capstone-rhcqs/rhcqs_be/blob/main/RHCQS_BE/sep490-101ee-firebase-adminsdk-fs18n-9a7ec2e22b.json"

    classDef controllers fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef middlewares fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef hubs fill:#FFC0CB,stroke:#000,stroke-width:2px;
    classDef services fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef repos fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef data fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef business fill:#EEEEEE,stroke:#000,stroke-width:2px;
    classDef external fill:#FFA500,stroke:#000,stroke-width:2px;
```
