# edu-reyna/short-link architecture

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

- Interactive diagram: https://gitdiagram.com/edu-reyna/short-link
- Repository: https://github.com/edu-reyna/short-link

## Overview

##### Main Components

- Frontend (Client Side):
- The project contains static HTML, CSS, and JavaScript files under src/main/resources/static. These serve as the user interface for landing pages (e.g., index.html, login.html, registro.html, admin.html, usuario.html) and related assets (styles, images, scripts).

- Backend (Server Side):
- This layer is implemented using Java classes encapsulated in the Spring Boot project. The primary packages include:
- Controllers (e.g., AuthController, LinkController, UsuariosController): Handle HTTP requests and map URL endpoints.
- Services (e.g., LinkServices, UsuariosServices implementing ILinkServices/IUsuariosServices): Contain core business logic.
- Repositories (e.g., ILinkRepository, IUsuarioRepository): Manage data access, likely through a database.
- Entities (e.g., Link, Role, Usuarios): Define domain models.
- Utils (e.g., JWTUtil, Conversion): Provide support utilities like JWT utilities for security and conversion methods.

- External Services & Database:
- Although the file tree does not include a dedicated database folder, typical Spring Boot URL shortener projects will interact with an external database (SQL or NoSQL) mapped via JPA repositories.
- Integration points with external authentication or other microservices (if applicable) can be highlighted if they exist, although they are not expressly evident from the file structure.

##### Relationships and Interactions

- User Requests (originating from browsers) hit the frontend static pages.
- The frontend sends HTTP requests (AJAX/fetch calls) to the backend endpoints managed by Controllers.
- Controllers coordinate with Services to process business logic.
- Services interact with Repositories to perform CRUD operations on Entities.
- Utilities such as JWTUtil support security (e.g., authentication token generation/validation) across components.

##### Architectural Patterns and Principles

- The project follows a layered (or n-tier) architecture (Controller → Service → Repository → Database).
- Separation of concerns is evident: controllers are responsible solely for handling HTTP requests, services encapsulate the business logic, and repositories isolate data access.
- The inclusion of the JWT utilities hints at token-based authentication, which should be highlighted in the security flow.

##### Relevant Technology, Frameworks, and Libraries

- Use of Maven for project management (pom.xml, mvnw, mvnw.cmd, .mvn directory).
- Likely usage of Spring Boot for the backend application.
- Java as the primary programming language.
- Static web resources may leverage vanilla JavaScript or enhanced frameworks/libraries (as seen with various JS files under static/js).
- JWT (JSON Web Token) for authentication/security as suggested by JWTUtil.

##### Elements

- Clearly labeled components:
- “Frontend” with static web pages.
- “Backend – Controllers” (e.g., AuthController, LinkController, UsuariosController).
- “Backend – Services” (e.g., LinkServices, UsuariosServices).
- “Backend – Repositories” (e.g., ILinkRepository, IUsuarioRepository).
- “Domain/Entities” (Link, Usuarios, Role).
- “Utility classes” (JWTUtil, Conversion).
- “External Database” (depicted as a separate component).

- Data flow between the clients and the controllers.
- Dependency relationships between controllers, services, repositories, and utilities.
- API calls, especially for user authentication and link redirection.

- Annotations or legends explaining:
- The role and purpose of each component.
- The architectural pattern (layered architecture).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FE["Static Web Pages & Assets"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        subgraph "Controllers"
            CT["AuthController, LinkController, UsuariosController"]:::backend
        end
        subgraph "Services"
            SV["LinkServices, UsuariosServices"]:::backend
        end
        subgraph "Repositories"
            RE["ILinkRepository, IUsuarioRepository"]:::backend
        end
        subgraph "Domain/Entities"
            EN["Link, Role, Usuarios"]:::backend
        end
        subgraph "Utility"
            UT["JWTUtil, Conversion"]:::util
        end
        MA["Main Application Startup"]:::backend
    end

    %% External Database
    DB["External Database"]:::db

    %% Connections
    FE -->|"HTTPRequests"| CT
    MA --> CT
    CT -->|"Calls"| SV
    SV -->|"Uses"| RE
    RE -->|"CRUDOperations"| DB
    CT -->|"ValidatesToken"| UT
    SV -->|"Utilizes"| UT

    %% Click Events
    click FE "https://github.com/edu-reyna/short-link/tree/main/src/main/resources/static"
    click CT "https://github.com/edu-reyna/short-link/tree/main/src/main/java/com/proyecto/shortURL/Controllers"
    click SV "https://github.com/edu-reyna/short-link/tree/main/src/main/java/com/proyecto/shortURL/Services"
    click RE "https://github.com/edu-reyna/short-link/tree/main/src/main/java/com/proyecto/shortURL/Repositories"
    click EN "https://github.com/edu-reyna/short-link/tree/main/src/main/java/com/proyecto/shortURL/Entities"
    click UT "https://github.com/edu-reyna/short-link/tree/main/src/main/java/com/proyecto/shortURL/utils"
    click MA "https://github.com/edu-reyna/short-link/blob/main/src/main/java/com/proyecto/shortURL/ShortUrlApplication.java"

    %% Styles
    classDef frontend fill:#f9e79f,stroke:#d35400,stroke-width:2px;
    classDef backend fill:#aed6f1,stroke:#2e86c1,stroke-width:2px;
    classDef util fill:#abebc6,stroke:#1e8449,stroke-width:2px;
    classDef db fill:#f5b7b1,stroke:#cb4335,stroke-width:2px;
```
