# embarkxofficial/url-shortener-project architecture

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

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

## Overview

##### Main Components

A. Frontend Layer (url-shortener-react):
- React Application Container
- Components Module (showing key components like Dashboard, Auth pages)
- Context API Module
- API Integration Layer
- Routing Module

B. Backend Layer (url-shortener-sb):
- Spring Boot Application Container
- Controllers Layer
- Service Layer
- Repository Layer
- Security Layer
- Models/DTOs

C. Database Layer:
- Database (likely PostgreSQL/MySQL based on Spring Boot setup)
- Main entities: User, UrlMapping, ClickEvent

##### Component Relationships

- Frontend → Backend: Show REST API calls with JWT authentication
- Backend → Database: Show data persistence flows
- Security Layer: Show JWT token flow and authentication process

##### Specific Implementation Details

Frontend Structure:
**React App**
- Public Routes (Landing, Login, Register)
- Protected Routes (Dashboard)
- Shared Components
- API Integration Layer

Backend Structure:
**Spring Boot App**
- Security (JWT + Spring Security)
- Controllers (Auth, URL, Redirect)
- Services
- Repositories

##### URL Shortening Flow
- User input → API call → URL generation → Database storage
##### URL Redirection Flow
- Short URL request → Lookup → Redirect → Click tracking
##### Authentication Flow
- Login/Register → JWT generation → Protected routes

##### Additional Elements

- Notes for important architectural decisions
- Scaling considerations
- Error handling paths

##### Technical Stack Callouts

Frontend:
- React
- Context API for state management
- React Router
- Tailwind CSS

Backend:
- Spring Boot
- Spring Security
- JPA/Hibernate
- JWT Authentication

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef frontend fill:#3b82f6,color:white
    classDef backend fill:#22c55e,color:white
    classDef security fill:#eab308,color:white
    classDef database fill:#6b7280,color:white
    classDef api fill:#ef4444,color:white

    %% Frontend Layer
    subgraph Frontend
        ReactApp["React Application"]:::frontend
        click ReactApp "https://github.com/EmbarkXOfficial/url-shortener-project/tree/main/url-shortener-react/src"
        
        subgraph Components
            Dashboard["Dashboard"]:::frontend
            click Dashboard "https://github.com/EmbarkXOfficial/url-shortener-project/tree/main/url-shortener-react/src/components/Dashboard"
            AuthPages["Auth Pages"]:::frontend
            click AuthPages "https://github.com/EmbarkXOfficial/url-shortener-project/blob/main/url-shortener-react/src/components/LoginPage.jsx"
        end
        
        ContextAPI["Context API"]:::frontend
        click ContextAPI "https://github.com/EmbarkXOfficial/url-shortener-project/blob/main/url-shortener-react/src/contextApi/ContextApi.jsx"
        
        APIIntegration["API Integration"]:::frontend
        click APIIntegration "https://github.com/EmbarkXOfficial/url-shortener-project/blob/main/url-shortener-react/src/api/api.js"
        
        Router["Router"]:::frontend
        click Router "https://github.com/EmbarkXOfficial/url-shortener-project/blob/main/url-shortener-react/src/AppRouter.jsx"
    end

    %% Backend Layer
    subgraph Backend
        SpringApp["Spring Boot Application"]:::backend
        
        subgraph Controllers
            AuthController["Auth Controller"]:::backend
            click AuthController "https://github.com/EmbarkXOfficial/url-shortener-project/blob/main/url-shortener-sb/src/main/java/com/url/shortener/controller/AuthController.java"
            RedirectController["Redirect Controller"]:::backend
            click RedirectController "https://github.com/EmbarkXOfficial/url-shortener-project/blob/main/url-shortener-sb/src/main/java/com/url/shortener/controller/RedirectController.java"
            UrlController["URL Controller"]:::backend
            click UrlController "https://github.com/EmbarkXOfficial/url-shortener-project/blob/main/url-shortener-sb/src/main/java/com/url/shortener/controller/UrlMappingController.java"
        end
        
        subgraph Services
            UrlService["URL Service"]:::backend
            click UrlService "https://github.com/EmbarkXOfficial/url-shortener-project/blob/main/url-shortener-sb/src/main/java/com/url/shortener/service/UrlMappingService.java"
            UserService["User Service"]:::backend
            click UserService "https://github.com/EmbarkXOfficial/url-shortener-project/blob/main/url-shortener-sb/src/main/java/com/url/shortener/service/UserService.java"
        end
        
        subgraph Security
            JWTSecurity["JWT Security"]:::security
            click JWTSecurity "https://github.com/EmbarkXOfficial/url-shortener-project/tree/main/url-shortener-sb/src/main/java/com/url/shortener/security/jwt"
            WebSecurity["Web Security"]:::security
            click WebSecurity "https://github.com/EmbarkXOfficial/url-shortener-project/blob/main/url-shortener-sb/src/main/java/com/url/shortener/security/WebSecurityConfig.java"
        end
        
        subgraph Repositories
            UrlRepo["URL Repository"]:::backend
            click UrlRepo "https://github.com/EmbarkXOfficial/url-shortener-project/blob/main/url-shortener-sb/src/main/java/com/url/shortener/repository/UrlMappingRepository.java"
            UserRepo["User Repository"]:::backend
            click UserRepo "https://github.com/EmbarkXOfficial/url-shortener-project/blob/main/url-shortener-sb/src/main/java/com/url/shortener/repository/UserRepository.java"
            ClickRepo["Click Repository"]:::backend
            click ClickRepo "https://github.com/EmbarkXOfficial/url-shortener-project/blob/main/url-shortener-sb/src/main/java/com/url/shortener/repository/ClickEventRepository.java"
        end
        
        subgraph Models
            UrlModel["URL Model"]:::backend
            click UrlModel "https://github.com/EmbarkXOfficial/url-shortener-project/blob/main/url-shortener-sb/src/main/java/com/url/shortener/models/UrlMapping.java"
            UserModel["User Model"]:::backend
            click UserModel "https://github.com/EmbarkXOfficial/url-shortener-project/blob/main/url-shortener-sb/src/main/java/com/url/shortener/models/User.java"
            ClickModel["Click Model"]:::backend
            click ClickModel "https://github.com/EmbarkXOfficial/url-shortener-project/blob/main/url-shortener-sb/src/main/java/com/url/shortener/models/ClickEvent.java"
        end
    end

    %% Database Layer
    Database[(Database)]:::database

    %% Relationships
    ReactApp --> Components
    ReactApp --> ContextAPI
    ReactApp --> APIIntegration
    ReactApp --> Router
    
    APIIntegration --> AuthController
    APIIntegration --> UrlController
    APIIntegration --> RedirectController
    
    AuthController --> UserService
    UrlController --> UrlService
    RedirectController --> UrlService
    
    UserService --> UserRepo
    UrlService --> UrlRepo
    UrlService --> ClickRepo
    
    UserRepo --> Database
    UrlRepo --> Database
    ClickRepo --> Database
    
    JWTSecurity --> WebSecurity
    WebSecurity --> Controllers
    
    %% Legend
    subgraph Legend
        Frontend_["Frontend"]:::frontend
        Backend_["Backend"]:::backend
        Security_["Security"]:::security
        Database_["Database"]:::database
    end
```
