# dadasovmurad/tinyrt-url-shorten-backend architecture

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

- Interactive diagram: https://gitdiagram.com/dadasovmurad/tinyrt-url-shorten-backend
- Repository: https://github.com/dadasovmurad/tinyrt-url-shorten-backend

## Overview

##### Project Type and Its Purpose
- The project is a .NET Core Web API that provides URL shortening and link encryption capabilities.
- It utilizes techniques from Clean Architecture and Aspect-Oriented Programming with Autofac. The system is layered to separate concerns (presentation, business logic, data access, and core utilities).

##### File Structure to Recognize Key Layers/Components
- WebApi: Contains the entry point (Program.cs), controllers (LinkController, BaseApiController) and configuration files. This is the presentation layer interacting with external requests.
- Business: Contains the business logic including interfaces (IShortenService) and implementations (ShortenManager), along with validation rules (using FluentValidation) and dependency resolver modules for Autofac.
- Core: Holds cross-cutting concerns such as aspects (for AOP), interceptors, exception handling, validation tools, and utility classes. This layer acts as the backbone for cross-layer functionalities.
- DataAccess: Implements repository patterns using Entity Framework. It contains the EF context (TinytrUrlShortenContext) and concrete repositories (EfShortenDal) to interact with a relational database.
- Entitites: Contains domain models (ShortenUrl) and DTOs (e.g., ShortenUrlForCreateDto, ShortenUrlForResponseDto) that represent the data structures passed among layers.
- Additional Directories (e.g., Business/Constants, DependencyResolvers, etc.) further support maintainability and clear separation of concerns.

##### Essential Elements
- Clear labels for each rectangle or component; for instance: WebApi Controllers, Business Managers, Data Repositories, and Core Utilities.
- Presentation components (e.g., controllers) from business logic.
- Infrastructure components (DataAccess, Entities) from cross-cutting concerns (Core utilities and aspects).
- Optionally, include a note on dependency injection and how Autofac organizes module dependencies across the project.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        Program["Program (Entry Point)"]:::presentation
        BaseApiController["BaseApiController"]:::presentation
        LinkController["LinkController"]:::presentation
        HTTPReq["HTTP Request"]:::presentation
    end

    %% Business Layer
    subgraph "Business Layer"
        IShortenService["IShortenService"]:::business
        ShortenManager["ShortenManager"]:::business
        ShortenUrlValidator["ShortenUrlValidator"]:::business
        AutofacBusinessModule["AutofacBusinessModule"]:::business
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        IShortenDal["IShortenDal"]:::data
        TinytrUrlShortenContext["TinytrUrlShortenContext"]:::data
        EfShortenDal["EfShortenDal"]:::data
    end

    %% Core Utilities and Cross-Cutting Concerns
    subgraph "Core Utilities"
        ValidationAspect["ValidationAspect"]:::core
        ExceptionMiddleware["ExceptionMiddleware"]:::core
        ExceptionMiddlewareExtensions["ExceptionMiddlewareExtensions"]:::core
        AspectInterceptorSelector["AspectInterceptorSelector"]:::core
        MethodInterception["MethodInterception"]:::core
        MethodInterceptionBaseAttribute["MethodInterceptionBaseAttribute"]:::core
        SecurityKeyHelper["SecurityKeyHelper"]:::core
        SigningCredentialsHelper["SigningCredentialsHelper"]:::core
        HashingHelper["HashingHelper"]:::core
    end

    %% Domain Layer
    subgraph "Domain Layer"
        ShortenUrl["ShortenUrl"]:::domain
        ShortenUrlForCreateDto["ShortenUrlForCreateDto"]:::domain
        ShortenUrlForResponseDto["ShortenUrlForResponseDto"]:::domain
        ProtectedUrlDto["ProtectedUrlDto"]:::domain
    end

    %% Database represented as a cylinder
    DB["DB"]:::db

    %% Relationships and Data Flow
    HTTPReq -->|"incoming"| BaseApiController
    BaseApiController -->|"forwards request"| LinkController
    LinkController -->|"calls"| ShortenManager
    AutofacBusinessModule -->|"injects"| ShortenManager
    AutofacBusinessModule -->|"injects"| IShortenService
    ShortenManager -->|"implements"| IShortenService
    ShortenManager -->|"invokes repository"| EfShortenDal
    AutofacBusinessModule -->|"injects"| EfShortenDal
    EfShortenDal -->|"uses"| IShortenDal
    EfShortenDal -->|"accesses"| TinytrUrlShortenContext
    TinytrUrlShortenContext -->|"persists data"| DB

    %% Cross-cutting Concerns
    ValidationAspect -->|"applies AOP"| ShortenManager
    MethodInterception -->|"intercepts"| ShortenManager
    AspectInterceptorSelector -->|"selects interceptors for"| ShortenManager
    ExceptionMiddleware -->|"handles errors for"| Program
    ExceptionMiddlewareExtensions -->|"extends middleware"| ExceptionMiddleware
    
    %% Business Security Utilities
    ShortenManager -->|"utilizes"| SecurityKeyHelper
    ShortenManager -->|"utilizes"| SigningCredentialsHelper
    ShortenManager -->|"utilizes"| HashingHelper
    
    
    %% Styles
    classDef presentation fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef business fill:#F9E79F,stroke:#7D6608,stroke-width:2px;
    classDef data fill:#ABEBC6,stroke:#196F3D,stroke-width:2px;
    classDef core fill:#D6DBDF,stroke:#424949,stroke-width:2px;
    classDef domain fill:#F5B7B1,stroke:#943126,stroke-width:2px;
    classDef db fill:#FAD7A0,stroke:#D35400,stroke-width:2px;

    %% Click Events
    click Program "https://github.com/dadasovmurad/tinyrt-url-shorten-backend/blob/master/WebApi/Program.cs"
    click BaseApiController "https://github.com/dadasovmurad/tinyrt-url-shorten-backend/blob/master/WebApi/Controllers/BaseApiController.cs"
    click LinkController "https://github.com/dadasovmurad/tinyrt-url-shorten-backend/blob/master/WebApi/Controllers/LinkController.cs"
    click IShortenService "https://github.com/dadasovmurad/tinyrt-url-shorten-backend/blob/master/Business/Abstract/IShortenService.cs"
    click ShortenManager "https://github.com/dadasovmurad/tinyrt-url-shorten-backend/blob/master/Business/Concrete/ShortenManager.cs"
    click ShortenUrlValidator "https://github.com/dadasovmurad/tinyrt-url-shorten-backend/blob/master/Business/ValidationRules/FluentValidation/ShortenUrlValidator.cs"
    click AutofacBusinessModule "https://github.com/dadasovmurad/tinyrt-url-shorten-backend/blob/master/Business/DependencyResolvers/Autofac/AutofacBusinessModule.cs"
    click IShortenDal "https://github.com/dadasovmurad/tinyrt-url-shorten-backend/blob/master/DataAccess/Abstract/IShortenDal.cs"
    click TinytrUrlShortenContext "https://github.com/dadasovmurad/tinyrt-url-shorten-backend/blob/master/DataAccess/Concrete/Contexts/TinytrUrlShortenContext.cs"
    click EfShortenDal "https://github.com/dadasovmurad/tinyrt-url-shorten-backend/blob/master/DataAccess/Concrete/EntityFramework/EfShortenDal.cs"
    click ValidationAspect "https://github.com/dadasovmurad/tinyrt-url-shorten-backend/blob/master/Core/Aspects/Autofac/Validation/ValidationAspect.cs"
    click ExceptionMiddleware "https://github.com/dadasovmurad/tinyrt-url-shorten-backend/blob/master/Core/Extensions/ExceptionMiddleware.cs"
    click ExceptionMiddlewareExtensions "https://github.com/dadasovmurad/tinyrt-url-shorten-backend/blob/master/Core/Extensions/ExceptionMiddlewareExtensions.cs"
    click AspectInterceptorSelector "https://github.com/dadasovmurad/tinyrt-url-shorten-backend/blob/master/Core/Utilities/Interceptors/AspectInterceptorSelector.cs"
    click MethodInterception "https://github.com/dadasovmurad/tinyrt-url-shorten-backend/blob/master/Core/Utilities/Interceptors/MethodInterception.cs"
    click MethodInterceptionBaseAttribute "https://github.com/dadasovmurad/tinyrt-url-shorten-backend/blob/master/Core/Utilities/Interceptors/MethodInterceptionBaseAttribute.cs"
    click SecurityKeyHelper "https://github.com/dadasovmurad/tinyrt-url-shorten-backend/blob/master/Core/Utilities/Security/Encyption/SecurityKeyHelper.cs"
    click SigningCredentialsHelper "https://github.com/dadasovmurad/tinyrt-url-shorten-backend/blob/master/Core/Utilities/Security/Encyption/SigningCredentialsHelper.cs"
    click HashingHelper "https://github.com/dadasovmurad/tinyrt-url-shorten-backend/blob/master/Core/Utilities/Security/Hashing/HashingHelper.cs"
    click ShortenUrl "https://github.com/dadasovmurad/tinyrt-url-shorten-backend/blob/master/Entitites/Concrete/ShortenUrl.cs"
    click ShortenUrlForCreateDto "https://github.com/dadasovmurad/tinyrt-url-shorten-backend/blob/master/Entitites/DTOs/ShortenUrlForCreateDto.cs"
    click ShortenUrlForResponseDto "https://github.com/dadasovmurad/tinyrt-url-shorten-backend/blob/master/Entitites/DTOs/ShortenUrlForResponseDto.cs"
    click ProtectedUrlDto "https://github.com/dadasovmurad/tinyrt-url-shorten-backend/blob/master/Entitites/DTOs/ProtectedUrlDto.cs"
```
