# porumbescu/tinify architecture

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

- Interactive diagram: https://gitdiagram.com/porumbescu/tinify
- Repository: https://github.com/porumbescu/tinify

## Overview

##### Main Components

A. Frontend Layer (React.js):
- Main React application container
- Components:
- Shortener.js (URL input component)
- Result.js (URL result display component)
- App.js (main application component)

B. Backend Layer (Spring Boot):
- Controller layer (TinifyController)
- Service layer (TinifyService)
- Repository layer (TinifyRepository)
- Exception handling (GlobalExceptionHandler)
- CORS configuration (CorsConfig)

C. Database Layer:
- PostgreSQL database
- Link entity storage

##### User Interface Flow
- User → React Frontend → URL Input
- Frontend → Backend API calls
- Backend Response → Frontend Display

##### Backend Processing Flow
- API Endpoints → Controller
- Controller → Service
- Service → Repository
- Repository → Database

**[User Browser]**
- ↓
**[React Frontend]**
- Shortener Component
- Result Component
- ↓
- HTTP/REST
- ↓
**[Spring Boot Backend]**
- Controller Layer
- Service Layer
- Repository Layer
- ↓
**[PostgreSQL Database]**

##### Key Elements to Emphasize

A. API Endpoints:
- POST /api/tinify/shorten
- GET /{shortCode}

B. Data Flow Patterns:
- URL shortening flow
- URL redirection flow
- Error handling paths

C. Cross-Cutting Concerns:
- CORS configuration
- Global exception handling
- URL validation

##### Technical Details

- Framework versions (Spring Boot, React)
- Database connection pool
- HTTP/REST communication
- Entity relationship (Link model)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef database fill:#f1c40f,stroke:#f39c12,color:black
    classDef error fill:#e74c3c,stroke:#c0392b,color:white
    classDef config fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef entity fill:#9b59b6,stroke:#8e44ad,color:white

    %% User
    User([User Browser])

    %% Frontend Layer
    subgraph Frontend
        App["App Container"]
        Shortener["URL Input Component"]
        Result["URL Result Display"]
    end

    %% Backend Layer
    subgraph Backend
        MainApp["Tinify Application"]
        Controller["Tinify Controller"]
        Service["Tinify Service"]
        Repository["Tinify Repository"]
        ExHandler["Global Exception Handler"]
        CORS["CORS Configuration"]
        LinkEntity["Link Entity"]
    end

    %% Database Layer
    DB[(PostgreSQL Database)]

    %% Relationships
    User --> App
    App --> Shortener
    App --> Result
    Shortener --> Controller
    Result --> Controller
    
    Controller --> Service
    Service --> Repository
    Repository --> DB
    Service --> ExHandler
    Controller --> ExHandler
    
    CORS --> Controller
    Service --> LinkEntity
    MainApp --> Controller

    %% Click Events
    click App "https://github.com/Porumbescu/Tinify/blob/main/tinify-frontend/src/App.js"
    click Shortener "https://github.com/Porumbescu/Tinify/blob/main/tinify-frontend/src/Shortener.js"
    click Result "https://github.com/Porumbescu/Tinify/blob/main/tinify-frontend/src/Result.js"
    click Controller "https://github.com/Porumbescu/Tinify/blob/main/tinify-backend/src/main/java/com/porumb/tinify/TinifyController.java"
    click Service "https://github.com/Porumbescu/Tinify/blob/main/tinify-backend/src/main/java/com/porumb/tinify/TinifyService.java"
    click Repository "https://github.com/Porumbescu/Tinify/blob/main/tinify-backend/src/main/java/com/porumb/tinify/TinifyRepository.java"
    click ExHandler "https://github.com/Porumbescu/Tinify/blob/main/tinify-backend/src/main/java/com/porumb/tinify/GlobalExceptionHandler.java"
    click CORS "https://github.com/Porumbescu/Tinify/blob/main/tinify-backend/src/main/java/com/porumb/tinify/CorsConfig.java"
    click LinkEntity "https://github.com/Porumbescu/Tinify/blob/main/tinify-backend/src/main/java/com/porumb/tinify/Link.java"
    click MainApp "https://github.com/Porumbescu/Tinify/blob/main/tinify-backend/src/main/java/com/porumb/tinify/TinifyApplication.java"

    %% Styling
    class App,Shortener,Result frontend
    class Controller,Service,Repository,MainApp backend
    class DB database
    class ExHandler error
    class CORS config
    class LinkEntity entity

    %% Legend
    subgraph Legend
        Frontend_L["Frontend Component"]:::frontend
        Backend_L["Backend Component"]:::backend
        Database_L["Database"]:::database
        Error_L["Error Handling"]:::error
        Config_L["Configuration"]:::config
        Entity_L["Entity"]:::entity
    end
```
