# tcish/url_shortener architecture

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

- Interactive diagram: https://gitdiagram.com/tcish/url_shortener
- Repository: https://github.com/tcish/url_shortener

## Overview

##### Main Components

A. Frontend Layer:
- Web Interface (Built with HTML, CSS, TailwindCSS, JavaScript)
- Components for URL shortening, user authentication, and insights
- Tippy.js for tooltips/UI enhancements

B. Backend Layer (Laravel Framework):
- Authentication System (Laravel Breeze)
- URL Shortening Service
- Analytics/Tracking Service
- API Endpoints
- Controllers Structure
- Database Models

C. Database Layer (MySQL):
- Users table
- URLs table
- Click Details table
- Cache table
- Jobs table

**[Client Layer]**
- ↑↓
**[Application Layer]**
- ↑↓
**[Database Layer]**

##### Specific Component Details

Frontend Components (Top Layer):
- Public Pages (URL shortening interface)
- Authentication Pages (login/register)
- Dashboard/Profile Area
- URL Management Interface
- Analytics/Insights View

Application Layer (Middle):
- Auth Controllers (AuthenticatedSessionController, RegisteredUserController, etc.)
- URL Management (ShortUrlController)
- API Endpoints
- Models (User, Url, ClickDetail)
- Service Providers

Database Layer (Bottom):
- Database Tables
- Relationships
- Caching System

##### Key Interactions to Highlight

a. URL Shortening Flow:
**User Input → API/Web Route → ShortUrlController → URL Model → Database**

b. URL Redirection Flow:
**Short URL Request → Controller → URL Lookup → Click Tracking → Redirect**

c. Analytics Flow:
**User Request → Controller → ClickDetail Model → Data Aggregation → View**

##### Important Elements

- Security layer (authentication/authorization)
- API endpoints
- Database relationships
- Caching mechanisms
- Click tracking flow
- User session management

##### Technical Details to Note

- Laravel 11.x as the framework
- MySQL database
- RESTful API endpoints
- Frontend asset compilation (Vite)
- Authentication middleware
- Database migrations and relationships

This system design should effectively communicate both the overall structure and the specific implementation details of the URL shortener application, making it valuable for both new team members and ongoing development reference.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef frontend fill:#3b82f6,color:white
    classDef backend fill:#22c55e,color:white
    classDef database fill:#f97316,color:white
    classDef auth fill:#dc2626,color:white
    classDef api fill:#9333ea,color:white
    classDef cache fill:#64748b,color:white

    %% Frontend Layer
    subgraph Frontend
        WebUI["Web Interface"]:::frontend
        AuthPages["Authentication Pages"]:::frontend
        Dashboard["Dashboard/Profile"]:::frontend
        URLManage["URL Management"]:::frontend
        Analytics["Analytics View"]:::frontend
        Assets["Frontend Assets"]:::frontend
    end
    click AuthPages "https://github.com/tcish/url_shortener/tree/master/resources/views/auth/"
    click Dashboard "https://github.com/tcish/url_shortener/tree/master/resources/views/profile/"
    click URLManage "https://github.com/tcish/url_shortener/blob/master/resources/views/index.blade.php"
    click Analytics "https://github.com/tcish/url_shortener/blob/master/resources/views/insight.blade.php"
    click Assets "https://github.com/tcish/url_shortener/tree/master/resources/views/layouts/"

    %% Backend Layer
    subgraph Application
        AuthController["Auth Controllers"]:::auth
        ProfileController["Profile Controller"]:::backend
        URLController["Short URL Controller"]:::backend
        TrackingService["Analytics Service"]:::backend
        APIEndpoints["API Endpoints"]:::api
    end
    click AuthController "https://github.com/tcish/url_shortener/tree/master/app/Http/Controllers/Auth/"
    click ProfileController "https://github.com/tcish/url_shortener/blob/master/app/Http/Controllers/ProfileController.php"
    click URLController "https://github.com/tcish/url_shortener/blob/master/app/Http/Controllers/ShortUrlController.php"
    click APIEndpoints "https://github.com/tcish/url_shortener/blob/master/routes/api.php"

    %% Models Layer
    subgraph Models
        UserModel["User Model"]:::backend
        URLModel["URL Model"]:::backend
        ClickModel["Click Detail Model"]:::backend
    end
    click UserModel "https://github.com/tcish/url_shortener/blob/master/app/Models/User.php"
    click URLModel "https://github.com/tcish/url_shortener/blob/master/app/Models/Url.php"
    click ClickModel "https://github.com/tcish/url_shortener/blob/master/app/Models/ClickDetail.php"

    %% Database Layer
    subgraph Database
        UsersTable[(Users Table)]:::database
        URLsTable[(URLs Table)]:::database
        ClicksTable[(Click Details)]:::database
        CacheTable[(Cache Table)]:::database
        JobsTable[(Jobs Table)]:::database
    end
    click UsersTable "https://github.com/tcish/url_shortener/blob/master/database/migrations/0001_01_01_000000_create_users_table.php"
    click URLsTable "https://github.com/tcish/url_shortener/blob/master/database/migrations/2024_09_25_071811_create_urls_table.php"
    click ClicksTable "https://github.com/tcish/url_shortener/blob/master/database/migrations/2024_09_25_072750_create_click_details.php"
    click CacheTable "https://github.com/tcish/url_shortener/blob/master/database/migrations/0001_01_01_000001_create_cache_table.php"
    click JobsTable "https://github.com/tcish/url_shortener/blob/master/database/migrations/0001_01_01_000002_create_jobs_table.php"

    %% Relationships
    WebUI --> AuthPages
    WebUI --> URLManage
    WebUI --> Dashboard
    Dashboard --> Analytics

    AuthPages --> AuthController
    Dashboard --> ProfileController
    URLManage --> URLController
    Analytics --> TrackingService

    AuthController --> UserModel
    ProfileController --> UserModel
    URLController --> URLModel
    TrackingService --> ClickModel
    APIEndpoints --> URLController
    APIEndpoints --> TrackingService

    UserModel --> UsersTable
    URLModel --> URLsTable
    ClickModel --> ClicksTable
    
    %% Cache and Jobs Relationships
    URLController -.-> CacheTable
    TrackingService -.-> JobsTable

    %% Legend
    subgraph Legend
        Frontend_["Frontend"]:::frontend
        Backend_["Backend"]:::backend
        Database_["Database"]:::database
        Auth_["Auth"]:::auth
        API_["API"]:::api
        Cache_["Cache/Jobs"]:::cache
    end
```
