# ms1034/url_shortner architecture

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

- Interactive diagram: https://gitdiagram.com/ms1034/url_shortner
- Repository: https://github.com/ms1034/url_shortner

## Overview

##### Main Components

A. Frontend Layer (Next.js Application):
- Client-side Components
- Dashboard Module
- Authentication Pages
- URL Management
- Analytics Module
- API Keys Management
- Brand Logo Management
- URL Tags Management

B. Backend Layer (NestJS Application):
- Core Modules
- Auth Module
- URL Module
- Analytics Module
- Users Module
- API Keys Module
- Logo Module
- Tags Module
- Caching Module

C. External Services:
- Cloudinary (for image storage)
- IP Geolocation Service

D. Database Layer:
- PostgreSQL Database (via Prisma ORM)

##### Architecture Patterns to Highlight

- Clean Architecture (visible in the backend structure)
- Module-based Architecture (NestJS modules)
- MVC Pattern (Controllers, Services, DTOs)
- Repository Pattern (for data access)
- Middleware Architecture (for request processing)

**[Client Browser]**
- ↕
**[Frontend Layer (Next.js)] → [Redux Store]**
- ↕
**[API Gateway/Load Balancer]**
- ↕
**[Backend Layer (NestJS)]**
- ↙     ↓     ↘
**[Cloudinary] [PostgreSQL] [IP Geolocation]**

##### Additional Details

Technical aspects:
- Environment Configuration
- Database Migration System
- Caching Layer
- Error Handling
- Logging System

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Browser["Web Browser"]
    end

    subgraph Frontend["Frontend Layer (Next.js)"]
        Dashboard["Dashboard"]:::frontend
        AuthPages["Authentication Pages"]:::frontend
        URLManagement["URL Management"]:::frontend
        Analytics["Analytics Module"]:::frontend
        APIKeys["API Keys Management"]:::frontend
        BrandLogo["Brand Logo Management"]:::frontend
        URLTags["URL Tags Management"]:::frontend
        ReduxStore["Redux Store"]:::frontend
    end

    subgraph Backend["Backend Layer (NestJS)"]
        AuthModule["Auth Module"]:::backend
        URLModule["URL Module"]:::backend
        AnalyticsModule["Analytics Module"]:::backend
        UsersModule["Users Module"]:::backend
        APIKeysModule["API Keys Module"]:::backend
        LogoModule["Logo Module"]:::backend
        TagsModule["Tags Module"]:::backend
        CachingModule["Caching Module"]:::backend
        
        subgraph Security["Security Layer"]
            JWTStrategy["JWT Strategy"]:::security
            AuthGuard["Auth Guard"]:::security
            RolesGuard["Roles Guard"]:::security
        end
        
        subgraph Common["Common Components"]
            Middleware["Middleware"]:::common
            Interceptors["Interceptors"]:::common
            Filters["Filters"]:::common
        end
    end

    subgraph External["External Services"]
        Cloudinary["Cloudinary Storage"]:::external
        IPGeo["IP Geolocation Service"]:::external
    end

    subgraph Database["Database Layer"]
        PostgreSQL["PostgreSQL"]:::database
        PrismaORM["Prisma ORM"]:::database
    end

    %% Relationships
    Browser <--> Dashboard
    Browser <--> AuthPages
    Browser <--> URLManagement
    Browser <--> Analytics
    Browser <--> APIKeys
    Browser <--> BrandLogo
    Browser <--> URLTags

    Dashboard --> ReduxStore
    AuthPages --> ReduxStore
    URLManagement --> ReduxStore
    Analytics --> ReduxStore
    APIKeys --> ReduxStore
    BrandLogo --> ReduxStore
    URLTags --> ReduxStore

    ReduxStore --> Backend

    Backend <--> Cloudinary
    Backend <--> IPGeo
    Backend <--> PostgreSQL
    PrismaORM <--> PostgreSQL

    %% Click Events
    click Dashboard "https://github.com/MS1034/url_shortner/blob/main/frontend/src/app/(dashboard)/dashboard/page.tsx"
    click AuthPages "https://github.com/MS1034/url_shortner/blob/main/frontend/src/app/login/page.tsx"
    click URLManagement "https://github.com/MS1034/url_shortner/blob/main/frontend/src/app/(dashboard)/url-management/page.tsx"
    click Analytics "https://github.com/MS1034/url_shortner/blob/main/frontend/src/app/(dashboard)/url-analytics/page.tsx"
    click APIKeys "https://github.com/MS1034/url_shortner/blob/main/frontend/src/app/(dashboard)/api-keys/page.tsx"
    click BrandLogo "https://github.com/MS1034/url_shortner/blob/main/frontend/src/app/(dashboard)/brand-logo/page.tsx"
    click URLTags "https://github.com/MS1034/url_shortner/blob/main/frontend/src/app/(dashboard)/url-tags/page.tsx"
    click ReduxStore "https://github.com/MS1034/url_shortner/blob/main/frontend/src/redux/store.ts"
    click AuthModule "https://github.com/MS1034/url_shortner/tree/main/backend/src/modules/auth"
    click URLModule "https://github.com/MS1034/url_shortner/tree/main/backend/src/modules/url"
    click AnalyticsModule "https://github.com/MS1034/url_shortner/tree/main/backend/src/modules/analytics"
    click UsersModule "https://github.com/MS1034/url_shortner/tree/main/backend/src/modules/users"
    click APIKeysModule "https://github.com/MS1034/url_shortner/tree/main/backend/src/modules/api-key"
    click LogoModule "https://github.com/MS1034/url_shortner/tree/main/backend/src/modules/logo"
    click TagsModule "https://github.com/MS1034/url_shortner/tree/main/backend/src/modules/tags"
    click CachingModule "https://github.com/MS1034/url_shortner/tree/main/backend/src/modules/caching"
    click JWTStrategy "https://github.com/MS1034/url_shortner/blob/main/backend/src/modules/auth/jwt.strategy.ts"
    click AuthGuard "https://github.com/MS1034/url_shortner/blob/main/backend/src/common/guards/auth/auth.guard.ts"
    click RolesGuard "https://github.com/MS1034/url_shortner/blob/main/backend/src/common/guards/roles/roles.guard.ts"
    click Middleware "https://github.com/MS1034/url_shortner/tree/main/backend/src/common/middlewares"
    click Interceptors "https://github.com/MS1034/url_shortner/tree/main/backend/src/common/interceptors"
    click Filters "https://github.com/MS1034/url_shortner/tree/main/backend/src/common/filters"
    click PrismaORM "https://github.com/MS1034/url_shortner/blob/main/backend/prisma/schema.prisma"

    %% Styles
    classDef frontend fill:#2196F3,color:white
    classDef backend fill:#4CAF50,color:white
    classDef security fill:#f44336,color:white
    classDef common fill:#9C27B0,color:white
    classDef external fill:#FF9800,color:white
    classDef database fill:#673AB7,color:white

    %% Legend
    subgraph Legend
        Frontend_L["Frontend"]:::frontend
        Backend_L["Backend"]:::backend
        Security_L["Security"]:::security
        Common_L["Common"]:::common
        External_L["External"]:::external
        Database_L["Database"]:::database
    end
```
