# osama1010c/rentmateapi architecture

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

- Interactive diagram: https://gitdiagram.com/osama1010c/rentmateapi
- Repository: https://github.com/osama1010c/rentmateapi

## Overview

##### Project Type and Purpose
- This is an ASP .NET Core Web API (“RentMateAPI”) serving as the backend for a property-rental application.
- It exposes REST endpoints for user management, property listings, messaging, rental requests, saved posts, search, admin tasks, and real-time chat (via SignalR).

##### High-Level Layered Structure
- Presentation/API Layer
- Controllers (Controllers/)
- SignalR Hub (Hub/ChatHub.cs)
- Application/Business Layer
- Services (Services/Interfaces & Implementations)
- DTOs (DTOModels/)
- Data Access Layer
- Repositories (Repositories/Interfaces & Implementations)
- Unit of Work (UOF/)
- EF Core DbContext & Entities (Data/)
- Infrastructure/Cross-Cutting
- JWT Authentication Extension (Extensions/CustomJwtAuthExtention.cs)
- Dependency-Injection Extensions (Extensions/ServiceCollectionExtensions.cs)
- Configuration (appsettings*.json)

##### Main Components
A. External Clients
- Web App, Mobile App, Third-party services → consume REST endpoints and SignalR hub
B. API Gateway / HTTP Interface
- Kestrel/Web Host (Program.cs)
- Middleware pipeline (Auth, Logging, CORS, etc.)
C. Controllers & Hub
- Controllers/AdminController, UserController, PropertyController, etc.
- ChatHub for real-time messaging
D. Services
- Business-logic layer classes (IUserService, PropertyService, etc.)
- Accept DTOs, enforce validation/business rules
E. Repositories & UnitOfWork
- Generic IRepository<T> + concrete Repository<T>
- UnitOfWork committing transactions across multiple repositories
F. EF Core & Database
- AppDbContext exposing DbSets for Models/Entities
- Underlying SQL Server (or other RDBMS)

##### Relationships and Data-Flow
- Controller methods call into Service interfaces → implement business logic → call into UnitOfWork or Repository methods
- Repositories use AppDbContext to query/persist Data/Models → Database
- SignalR Hub sits at the API boundary: clients open WebSocket connections → ChatHub → inject IMessageService → persists messages
- DTOModels sit between Controller and Service layers; Data/Models sit between Repository and DbContext

##### Architectural Patterns & Design Principles
- Layered (N-Tier) architecture separating concerns
- Dependency Injection for Controllers, Services, Repositories, DbContext
- Repository + Unit of Work for atomic DB operations
- DTO pattern to decouple domain models from API contracts
- SignalR for real-time communication
- Extension methods to register services and authentication schemes

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Clients
    subgraph "External Consumers" 
        direction TB
        Clients["Web App<br/>Mobile App<br/>3rd-party Services"]:::external
    end

    %% API Layer
    subgraph "API Layer" 
        direction TB
        APIHost["Program.cs<br/>ASP .NET Core Web API"]:::api
        Middleware["Middleware Pipeline<br/>JWT Auth, Logging, CORS"]:::api
        subgraph "Controllers (REST Endpoints)" 
            direction TB
            AdminCtrl["AdminController"]:::api
            CommentCtrl["CommentController"]:::api
            LandlordCtrl["LandlordController"]:::api
            MessageCtrl["MessageController"]:::api
            PropertyCtrl["PropertyController"]:::api
            RentalRequestCtrl["RentalRequestController"]:::api
            SaveCtrl["SaveController"]:::api
            SearchCtrl["SearchController"]:::api
            UserCtrl["UserController"]:::api
        end
        ChatHub["ChatHub (SignalR)"]:::api
    end

    %% Business Layer
    subgraph "Business Layer" 
        direction TB
        DTO["DTOModels"]:::business
        subgraph "Service Interfaces" 
            direction TB
            IUserSvc["IUserService"]:::business
            IPropSvc["IPropertyService"]:::business
            IMessageSvc["IMessageService"]:::business
            ICommentSvc["ICommentService"]:::business
            IRentalSvc["IRentalService"]:::business
            ISavedSvc["ISavedPostService"]:::business
            ISearchSvc["ISearchService"]:::business
            IAdminSvc["IAdminService"]:::business
        end
        subgraph "Service Implementations" 
            direction TB
            UserSvc["UserService"]:::business
            PropSvc["PropertyService"]:::business
            MessageSvc["MessageService"]:::business
            CommentSvc["CommentService"]:::business
            RentalSvc["RentalService"]:::business
            SavedSvc["SavedPostService"]:::business
            SearchSvc["SearchService"]:::business
            AdminSvc["AdminService"]:::business
        end
    end

    %% Data Access Layer
    subgraph "Data Access Layer" 
        direction TB
        subgraph "Repositories & UoW"
            direction TB
            RepoIfc["IRepository<T>"]:::data
            RepoImpl["Repository<T>"]:::data
            UowIfc["IUnitOfWork"]:::data
            UowImpl["UnitOfWork"]:::data
        end
        DbContext["AppDbContext"]:::data
        Entities["Entities (Data/Models)"]:::data
    end

    %% Database
    Database["SQL Server<br/>(EF Core)"]:::database

    %% Infra Extensions
    subgraph "Cross-Cutting Infra"
        direction TB
        JwtExt["CustomJwtAuthExtention"]:::infra
        DIExt["ServiceCollectionExtensions"]:::infra
        Config["appsettings*.json"]:::infra
    end

    %% Connections
    Clients -->|HTTP/SignalR| APIHost
    APIHost --> Middleware
    Middleware --> AdminCtrl
    Middleware --> CommentCtrl
    Middleware --> LandlordCtrl
    Middleware --> MessageCtrl
    Middleware --> PropertyCtrl
    Middleware --> RentalRequestCtrl
    Middleware --> SaveCtrl
    Middleware --> SearchCtrl
    Middleware --> UserCtrl
    Middleware --> ChatHub

    AdminCtrl -->|calls| IUserSvc
    CommentCtrl -->|calls| ICommentSvc
    LandlordCtrl -->|calls| IPropertySvc
    MessageCtrl -->|calls| IMessageSvc
    PropertyCtrl -->|calls| IPropertySvc
    RentalRequestCtrl -->|calls| IRentalSvc
    SaveCtrl -->|calls| ISavedSvc
    SearchCtrl -->|calls| ISearchSvc
    UserCtrl -->|calls| IUserSvc
    ChatHub -->|injects| IMessageSvc

    DTO --> IUserSvc
    DTO --> IPropertySvc
    DTO --> IMessageSvc
    DTO --> ICommentSvc
    DTO --> IRentalSvc
    DTO --> ISavedSvc
    DTO --> ISearchSvc
    DTO --> IAdminSvc

    IUserSvc --> UserSvc
    IPropertySvc --> PropSvc
    IMessageSvc --> MessageSvc
    ICommentSvc --> CommentSvc
    IRentalSvc --> RentalSvc
    ISavedSvc --> SavedSvc
    ISearchSvc --> SearchSvc
    IAdminSvc --> AdminSvc

    UserSvc -->|uses| RepoImpl
    PropSvc -->|uses| RepoImpl
    MessageSvc -->|uses| RepoImpl
    CommentSvc -->|uses| RepoImpl
    RentalSvc -->|uses| RepoImpl
    SavedSvc -->|uses| RepoImpl
    SearchSvc -->|uses| RepoImpl
    AdminSvc -->|uses| RepoImpl

    RepoImpl --> RepoIfc
    RepoImpl --> DbContext
    UowImpl --> UowIfc
    UowImpl --> DbContext

    DbContext --> Entities
    DbContext --> Database

    APIHost --> JwtExt
    APIHost --> DIExt
    APIHost --> Config

    %% Click Events
    click APIHost "https://github.com/osama1010c/rentmateapi/blob/master/Program.cs"
    click AdminCtrl "https://github.com/osama1010c/rentmateapi/blob/master/Controllers/AdminController.cs"
    click CommentCtrl "https://github.com/osama1010c/rentmateapi/blob/master/Controllers/CommentController.cs"
    click LandlordCtrl "https://github.com/osama1010c/rentmateapi/blob/master/Controllers/LandlordController.cs"
    click MessageCtrl "https://github.com/osama1010c/rentmateapi/blob/master/Controllers/MessageController.cs"
    click PropertyCtrl "https://github.com/osama1010c/rentmateapi/blob/master/Controllers/PropertyController.cs"
    click RentalRequestCtrl "https://github.com/osama1010c/rentmateapi/blob/master/Controllers/RentalRequestController.cs"
    click SaveCtrl "https://github.com/osama1010c/rentmateapi/blob/master/Controllers/SaveController.cs"
    click SearchCtrl "https://github.com/osama1010c/rentmateapi/blob/master/Controllers/SearchController.cs"
    click UserCtrl "https://github.com/osama1010c/rentmateapi/blob/master/Controllers/UserController.cs"
    click ChatHub "https://github.com/osama1010c/rentmateapi/blob/master/Hub/ChatHub.cs"
    click DTO "https://github.com/osama1010c/rentmateapi/tree/master/DTOModels/"
    click IUserSvc "https://github.com/osama1010c/rentmateapi/blob/master/Services/Interfaces/IUserService.cs"
    click IPropertySvc "https://github.com/osama1010c/rentmateapi/blob/master/Services/Interfaces/IPropertyService.cs"
    click IMessageSvc "https://github.com/osama1010c/rentmateapi/blob/master/Services/Interfaces/IMessageService.cs"
    click ICommentSvc "https://github.com/osama1010c/rentmateapi/blob/master/Services/Interfaces/ICommentService.cs"
    click IRentalSvc "https://github.com/osama1010c/rentmateapi/blob/master/Services/Interfaces/IRentalService.cs"
    click ISavedSvc "https://github.com/osama1010c/rentmateapi/blob/master/Services/Interfaces/ISavedPostService.cs"
    click ISearchSvc "https://github.com/osama1010c/rentmateapi/blob/master/Services/Interfaces/ISearchService.cs"
    click IAdminSvc "https://github.com/osama1010c/rentmateapi/blob/master/Services/Interfaces/IAdminService.cs"
    click UserSvc "https://github.com/osama1010c/rentmateapi/blob/master/Services/Implementations/UserService.cs"
    click PropSvc "https://github.com/osama1010c/rentmateapi/blob/master/Services/Implementations/PropertyService.cs"
    click MessageSvc "https://github.com/osama1010c/rentmateapi/blob/master/Services/Implementations/MessageService.cs"
    click CommentSvc "https://github.com/osama1010c/rentmateapi/blob/master/Services/Implementations/CommentService.cs"
    click RentalSvc "https://github.com/osama1010c/rentmateapi/blob/master/Services/Implementations/RentalService.cs"
    click SavedSvc "https://github.com/osama1010c/rentmateapi/blob/master/Services/Implementations/SavedPostService.cs"
    click SearchSvc "https://github.com/osama1010c/rentmateapi/blob/master/Services/Implementations/SearchService.cs"
    click AdminSvc "https://github.com/osama1010c/rentmateapi/blob/master/Services/Implementations/AdminService.cs"
    click RepoIfc "https://github.com/osama1010c/rentmateapi/blob/master/Repositories/Interfaces/IRepository.cs"
    click RepoImpl "https://github.com/osama1010c/rentmateapi/blob/master/Repositories/Implementations/Repository.cs"
    click UowIfc "https://github.com/osama1010c/rentmateapi/blob/master/UOF/Interface/IUnitOfWork.cs"
    click UowImpl "https://github.com/osama1010c/rentmateapi/blob/master/UOF/Implementation/UnitOfWork.cs"
    click DbContext "https://github.com/osama1010c/rentmateapi/blob/master/Data/AppDbContext.cs"
    click Entities "https://github.com/osama1010c/rentmateapi/tree/master/Data/Models/"
    click JwtExt "https://github.com/osama1010c/rentmateapi/blob/master/Extensions/CustomJwtAuthExtention.cs"
    click DIExt "https://github.com/osama1010c/rentmateapi/blob/master/Extensions/ServiceCollectionExtensions.cs"
    click Config "https://github.com/osama1010c/rentmateapi/blob/master/appsettings.json"

    %% Styles
    classDef external fill:#EEEEEE,stroke:#999,stroke-width:1px
    classDef api fill:#D0E8FF,stroke:#0366D6,stroke-width:1px
    classDef business fill:#DFF2BF,stroke:#4F8A10,stroke-width:1px
    classDef data fill:#FFE0B2,stroke:#E65100,stroke-width:1px
    classDef database fill:#F2F2F2,stroke:#888,stroke-width:2px,stroke-dasharray: 5 5
    classDef infra fill:#E8DAEF,stroke:#6A1B9A,stroke-width:1px
```
