# x1ulan/shorturl architecture

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

- Interactive diagram: https://gitdiagram.com/x1ulan/shorturl
- Repository: https://github.com/x1ulan/shorturl

## Overview

##### Main Components

a) Frontend Layer:
- Single PHP interface (index.php)
- This as the entry point for user interactions
- Both URL submission and URL redirection flows

b) Application Logic Layer:
- URL processing component (util.php)
- URL generation and validation logic
- Shortening algorithm

c) Data Storage:
- JSON file storage (data.json)
- As a simple persistent storage solution

##### URL Shortening Flow
- User → index.php → util.php → data.json
- Response returns back through the same path

##### URL Redirection Flow
- User with short URL → index.php → util.php → data.json
- Redirect to original URL

##### Additional Elements

Technical details in notes or labels:
- PHP Version requirement
- Docker containerization
- JSON-based storage mechanism

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        User(("User/Client"))
    end

    subgraph "Docker Container"
        direction TB
        subgraph "Frontend Layer"
            FE["Frontend Interface"]:::frontend
        end

        subgraph "Application Layer"
            URL["URL Processing Component"]:::processing
        end

        subgraph "Storage Layer"
            DB[(Data Storage)]:::storage
        end
    end

    %% URL Shortening Flow
    User -->|1. Submit Long URL| FE
    FE -->|2. Process URL| URL
    URL -->|3. Store| DB
    DB -->|4. Confirm Storage| URL
    URL -->|5. Return Short URL| FE
    FE -->|6. Display Short URL| User

    %% URL Redirection Flow
    User -->|1. Access Short URL| FE
    FE -->|2. Lookup URL| URL
    URL -->|3. Fetch Original URL| DB
    DB -->|4. Return Original URL| URL
    URL -->|5. Redirect Info| FE
    FE -->|6. Redirect to Original URL| User

    %% Styling
    classDef frontend fill:#2196F3,stroke:#000,stroke-width:1px,color:#fff
    classDef processing fill:#4CAF50,stroke:#000,stroke-width:1px,color:#fff
    classDef storage fill:#FFC107,stroke:#000,stroke-width:1px,color:#000
    classDef container fill:#f5f5f5,stroke:#000,stroke-width:1px,color:#000

    %% Click Events
    click FE "https://github.com/x1ulan/shorturl/blob/main/index.php"
    click URL "https://github.com/x1ulan/shorturl/blob/main/util.php"
    click DB "https://github.com/x1ulan/shorturl/blob/main/data.json"

    %% Legend
    subgraph Legend
        L1["Frontend Component"]:::frontend
        L2["Processing Component"]:::processing
        L3[(Storage Component)]:::storage
    end
```
