# nitzanpap/url-shortener architecture

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

- Interactive diagram: https://gitdiagram.com/nitzanpap/url-shortener
- Repository: https://github.com/nitzanpap/url-shortener

## Overview

##### Main Components

A. Frontend (Client Layer):
- Next.js Application
- Pages/Routes
- Components
- API Integration Layer
- PWA capabilities

B. Backend (Server Layer):
- Go/Gin Server
- URL Handling Service
- Route Management
- Base62 Encoding Utility

C. Database Layer:
- PostgreSQL Database

**[Client Tier]**

- ▼
**[Server Tier]**

- ▼
**[Database Tier]**

##### Detailed Component Breakdown

- Next.js frontend with subcomponents:
- Main Page (/src/app/page.tsx)
- URL Shortener Component
- Redirect Page (/s/[...slug])
- API Integration Layer (src/api/)
- Toast Provider for notifications

- Gin server with:
- URL Routes Handler
- URL Service Layer
- URL Repository Layer
- Base62 Encoding Utility
- Configuration Management

- PostgreSQL Database
- URL Storage
- Mapping between short and long URLs

##### Connection Flows to Illustrate

- Client to Server communication via REST API
- Server to Database interactions
- URL shortening flow:
1. User input → Frontend
2. Frontend → Backend API
3. Backend processing (Base62 encoding)
4. Database storage
5. Response flow back to user

##### Technical Details

Labels for:
- TypeScript/SCSS for frontend
- Go/Gin for backend
- PostgreSQL for database
- Base62 encoding utility
- REST API endpoints

##### Additional Elements

- A title: "URL Shortener System Architecture"
- Version/date
- Notes about deployment (Vercel for frontend, render.com for backend)
- Environment configuration flow

For tools, recommend using:
- Lucidchart

## Diagram (Mermaid)

```mermaid
graph TB
    %% Title
    title[URL Shortener System Architecture]:::title
    
    %% Main Layers
    subgraph Client["Client Layer"]
        NextApp["Next.js Application"]:::frontend
        PWA["PWA Manifest"]:::frontend
        MainPage["Main Page"]:::frontend
        RedirectPage["Redirect Page"]:::frontend
        URLShortener["URL Shortener Component"]:::frontend
        APIIntegration["API Integration Layer"]:::frontend
        ToastProvider["Toast Provider"]:::frontend
    end

    subgraph Server["Server Layer"]
        GinServer["Gin Server"]:::backend
        URLHandler["URL Routes Handler"]:::backend
        URLService["URL Service"]:::backend
        URLRepo["URL Repository"]:::backend
        Base62["Base62 Encoding Utility"]:::backend
        ServerConfig["Server Configuration"]:::backend
        DBConfig["Database Configuration"]:::backend
    end

    subgraph Database["Database Layer"]
        PostgreSQL[(PostgreSQL DB)]:::database
    end

    %% Connections
    NextApp --> APIIntegration
    MainPage --> URLShortener
    URLShortener --> APIIntegration
    APIIntegration --> URLHandler
    URLHandler --> URLService
    URLService --> URLRepo
    URLService --> Base62
    URLRepo --> PostgreSQL
    RedirectPage --> APIIntegration
    ToastProvider --> NextApp

    %% Configuration Flows
    ServerConfig --> GinServer
    DBConfig --> PostgreSQL
    PWA --> NextApp

    %% Styling
    classDef frontend fill:#3498db,color:#fff
    classDef backend fill:#2ecc71,color:#fff
    classDef database fill:#f1c40f,color:#fff
    classDef title fill:#fff,color:#000,stroke-width:0px
    
    %% Click Events
    click NextApp "https://github.com/nitzanpap/url-shortener/tree/master/client/src/app"
    click URLShortener "https://github.com/nitzanpap/url-shortener/blob/master/client/src/components/urlShortener/urlShortener.tsx"
    click APIIntegration "https://github.com/nitzanpap/url-shortener/blob/master/client/src/api/serverApi.ts"
    click PWA "https://github.com/nitzanpap/url-shortener/blob/master/client/public/manifest.json"
    click URLService "https://github.com/nitzanpap/url-shortener/blob/master/server/internal/routes/urls/urls.service.go"
    click URLRepo "https://github.com/nitzanpap/url-shortener/blob/master/server/internal/routes/urls/urls.repository.go"
    click URLHandler "https://github.com/nitzanpap/url-shortener/blob/master/server/internal/routes/urls/urls.handler.go"
    click Base62 "https://github.com/nitzanpap/url-shortener/blob/master/server/pkg/utils/base62encoding.go"
    click ServerConfig "https://github.com/nitzanpap/url-shortener/blob/master/server/internal/configs/serverConfigs/server.config.go"
    click DBConfig "https://github.com/nitzanpap/url-shortener/blob/master/server/internal/configs/dbConfigs/db.config.go"
    click ToastProvider "https://github.com/nitzanpap/url-shortener/blob/master/client/src/components/ToastProvider/ToastProvider.tsx"
    click RedirectPage "https://github.com/nitzanpap/url-shortener/blob/master/client/src/app/s/[...slug]/page.tsx"
    click MainPage "https://github.com/nitzanpap/url-shortener/blob/master/client/src/app/page.tsx"
    click GinServer "https://github.com/nitzanpap/url-shortener/blob/master/server/cmd/main.go"
```
