# fernicolas117/ticketsupport-backend architecture

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

- Interactive diagram: https://gitdiagram.com/fernicolas117/ticketsupport-backend
- Repository: https://github.com/fernicolas117/ticketsupport-backend

## Overview

##### Project Type and Purpose
- This is a backend service for a ticket support system.
- The project serves RESTful API endpoints to manage user authentication and ticket operations.
- It leverages Spring Boot for application bootstrapping and dependency management, with containerization support via Docker (docker-compose.yml, dockerfile).

##### Analysis of the File Structure
- Top-Level Components:
- Maven and configuration files (pom.xml, mvnw, etc.) indicate the Java build and dependency management.
- Docker files (dockerfile, docker-compose.yml) imply containerized deployment.
- The src/main/java directory shows a layered package structure under “com.ticketsupport.api.”
- Layered Architecture:
- API Layer (Controllers): Files under “controller” like AuthController, TicketController, and UserTicketController define REST endpoints.
- DTOs: Data Transfer Objects manage incoming and outgoing data, found in the “dto” packages.
- Configuration & Security: The “config” package (with SecurityConfig) and “security/jwt” illustrate that security – especially JWT-based authentication – is a core part of the system.
- Service Layer: Interfaces and implementations (e.g., TicketService, UserTicketService, AuthService along with their implementations in “service/impl”) encapsulate business logic.
- Data Access Layer: Repository interfaces (RoleRepository, TicketRepository, UserTicketRepository) facilitate database operations.
- Exception Handling: Custom exceptions like ResourceNotFoundException ensure proper error management.
- Model: Domain entities (Ticket, UserTicket, Role, ERole, etc.) modeling the application's data.

##### Relevant Architectural Patterns & Design Principles
- Layered (N-tier) design: Separates responsibilities across controllers, services, repositories, and configurations.
- MVC-inspired design: Though strictly a backend API, the separation between controllers, services, and models follows MVC best practices.
- Security: Integration of Spring Security with JWT for authentication and role-based access control.
- Containerization: Use of Docker suggests aspects of microservices or ease of deployment in cloud environments.

a. Main Components:
- API Gateway / REST Controller Layer:
- AuthController – handles login and authentication.
- TicketController & UserTicketController – manage ticket-related operations.
- Service Layer:
- AuthService, TicketService, UserTicketService and their implementation classes.
- Data Access Layer:
- Repositories (RoleRepository, TicketRepository, UserTicketRepository)
- Security Module:
- JWT components: JwtAuthenticationFilter, JwtEntryPoint, JwtUtil.
- Security configuration (SecurityConfig)
- Domain and DTO Layers:
- DTOs that facilitate data transfer between client and backend.
- Domain models representing tickets, users, and roles.
- External/Supporting Components:
- Database: (Implicit via the repositories, not directly in the file tree but assumed from Spring Boot conventions).
- Docker setup: Dockerfile and docker-compose.yml for containerization and deployment.

b. Relationships and Data Flow:
- Incoming requests from clients hit the API layer (controllers).
- Controllers invoke service layer methods to process business logic.
- The service layer interacts with the repositories to perform CRUD operations on the database.
- Authentication is handled separately via JWT-based security filters, ensuring requests are authorized before reaching protected endpoints.
- Configuration files (application.properties, SecurityConfig) guide behavior, and custom exception handling ensures proper error feedback.

c. Detailed Elements:
- Interactions such as:
- TicketController -> TicketService -> TicketRepository for ticket operations.
- UserTicketController -> UserTicketService -> UserTicketRepository for user-specific ticket actions.
- Security component interception on incoming HTTP requests.
- If possible, mark interactions with the database and external dependencies like Dockerized environments.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Entry Point
    A["TicketSupportApplication"]:::app
    click A "https://github.com/fernicolas117/ticketsupport-backend/blob/main/src/main/java/com/ticketsupport/api/TicketSupportApplication.java"
    
    %% External Client
    B["Client Request"]:::external

    %% Security Module (intercepts requests)
    subgraph "Security Module"
        S1["SecurityConfig"]:::security
        click S1 "https://github.com/fernicolas117/ticketsupport-backend/blob/main/src/main/java/com/ticketsupport/api/config/SecurityConfig.java"
        S2["JwtAuthenticationFilter"]:::security
        click S2 "https://github.com/fernicolas117/ticketsupport-backend/blob/main/src/main/java/com/ticketsupport/api/security/jwt/JwtAuthenticationFilter.java"
        S3["JwtEntryPoint"]:::security
        click S3 "https://github.com/fernicolas117/ticketsupport-backend/blob/main/src/main/java/com/ticketsupport/api/security/jwt/JwtEntryPoint.java"
        S4["JwtUtil"]:::security
        click S4 "https://github.com/fernicolas117/ticketsupport-backend/blob/main/src/main/java/com/ticketsupport/api/security/jwt/JwtUtil.java"
    end

    %% API Layer (Controllers)
    subgraph "API Layer"
        C1["AuthController"]:::controller
        click C1 "https://github.com/fernicolas117/ticketsupport-backend/blob/main/src/main/java/com/ticketsupport/api/controller/AuthController.java"
        C2["TicketController"]:::controller
        click C2 "https://github.com/fernicolas117/ticketsupport-backend/blob/main/src/main/java/com/ticketsupport/api/controller/TicketController.java"
        C3["UserTicketController"]:::controller
        click C3 "https://github.com/fernicolas117/ticketsupport-backend/blob/main/src/main/java/com/ticketsupport/api/controller/UserTicketController.java"
    end

    %% Service Layer
    subgraph "Service Layer"
        D1["AuthService"]:::service
        click D1 "https://github.com/fernicolas117/ticketsupport-backend/blob/main/src/main/java/com/ticketsupport/api/service/AuthService.java"
        D2["TicketService"]:::service
        click D2 "https://github.com/fernicolas117/ticketsupport-backend/blob/main/src/main/java/com/ticketsupport/api/service/TicketService.java"
        D3["UserTicketService"]:::service
        click D3 "https://github.com/fernicolas117/ticketsupport-backend/blob/main/src/main/java/com/ticketsupport/api/service/UserTicketService.java"
        D4["TicketServiceImpl"]:::serviceImpl
        click D4 "https://github.com/fernicolas117/ticketsupport-backend/blob/main/src/main/java/com/ticketsupport/api/service/impl/TicketServiceImpl.java"
        D5["UserTicketServiceImpl"]:::serviceImpl
        click D5 "https://github.com/fernicolas117/ticketsupport-backend/blob/main/src/main/java/com/ticketsupport/api/service/impl/UserTicketServiceImpl.java"
    end

    %% Data Access Layer (Repositories)
    subgraph "Data Access Layer"
        E1["RoleRepository"]:::repository
        click E1 "https://github.com/fernicolas117/ticketsupport-backend/blob/main/src/main/java/com/ticketsupport/api/repository/RoleRepository.java"
        E2["TicketRepository"]:::repository
        click E2 "https://github.com/fernicolas117/ticketsupport-backend/blob/main/src/main/java/com/ticketsupport/api/repository/TicketRespository.java"
        E3["UserTicketRepository"]:::repository
        click E3 "https://github.com/fernicolas117/ticketsupport-backend/blob/main/src/main/java/com/ticketsupport/api/repository/UserTicketRepository.java"
    end

    %% Database
    F["Database"]:::database

    %% Domain Models
    subgraph "Domain Models"
        M1["Ticket"]:::model
        click M1 "https://github.com/fernicolas117/ticketsupport-backend/blob/main/src/main/java/com/ticketsupport/api/model/Ticket.java"
        M2["UserTicket"]:::model
        click M2 "https://github.com/fernicolas117/ticketsupport-backend/blob/main/src/main/java/com/ticketsupport/api/model/UserTicket.java"
        M3["Role"]:::model
        click M3 "https://github.com/fernicolas117/ticketsupport-backend/blob/main/src/main/java/com/ticketsupport/api/model/Role.java"
        M4["ERole"]:::model
        click M4 "https://github.com/fernicolas117/ticketsupport-backend/blob/main/src/main/java/com/ticketsupport/api/model/ERole.java"
        M5["ETicketStatus"]:::model
        click M5 "https://github.com/fernicolas117/ticketsupport-backend/blob/main/src/main/java/com/ticketsupport/api/model/ETicketStatus.java"
    end

    %% Data Transfer Objects (DTOs)
    subgraph "DTOs"
        T1["LoginResponseDTO"]:::dto
        click T1 "https://github.com/fernicolas117/ticketsupport-backend/blob/main/src/main/java/com/ticketsupport/api/dto/LoginResponseDTO.java"
        T2["LoginUserDTO"]:::dto
        click T2 "https://github.com/fernicolas117/ticketsupport-backend/blob/main/src/main/java/com/ticketsupport/api/dto/LoginUserDTO.java"
        T3["NewUserTicketDTO"]:::dto
        click T3 "https://github.com/fernicolas117/ticketsupport-backend/blob/main/src/main/java/com/ticketsupport/api/dto/NewUserTicketDTO.java"
        T4["TicketListDTO"]:::dto
        click T4 "https://github.com/fernicolas117/ticketsupport-backend/blob/main/src/main/java/com/ticketsupport/api/dto/TicketListDTO.java"
        T5["TicketStatusDTO"]:::dto
        click T5 "https://github.com/fernicolas117/ticketsupport-backend/blob/main/src/main/java/com/ticketsupport/api/dto/TicketStatusDTO.java"
        T6["UserTicketDTO"]:::dto
        click T6 "https://github.com/fernicolas117/ticketsupport-backend/blob/main/src/main/java/com/ticketsupport/api/dto/UserTicketDTO.java"
        T7["TicketListForADMIN"]:::dto
        click T7 "https://github.com/fernicolas117/ticketsupport-backend/blob/main/src/main/java/com/ticketsupport/api/dto/ticket/TicketListForADMIN.java"
        T8["TicketsForUserDTO"]:::dto
        click T8 "https://github.com/fernicolas117/ticketsupport-backend/blob/main/src/main/java/com/ticketsupport/api/dto/ticket/TicketsForUserDTO.java"
    end

    %% Exception Handling
    G["ResourceNotFoundException"]:::exception
    click G "https://github.com/fernicolas117/ticketsupport-backend/blob/main/src/main/java/com/ticketsupport/api/exception/ResourceNotFoundException.java"

    %% Containerization / Deployment
    subgraph "Containerization"
        DCK1["Dockerfile"]:::docker
        click DCK1 "https://github.com/fernicolas117/ticketsupport-backend/tree/main/dockerfile"
        DCK2["docker-compose.yml"]:::docker
        click DCK2 "https://github.com/fernicolas117/ticketsupport-backend/blob/main/docker-compose.yml"
    end

    %% Connections
    A -->|"starts"| B
    B -->|"intercepted_by"| S2
    S2 -->|"routes_to"| C1
    S2 -->|"routes_to"| C2
    S2 -->|"routes_to"| C3

    %% API to Service
    C1 -->|"calls"| D1
    C2 -->|"calls"| D2
    C3 -->|"calls"| D3

    %% Service implementations (for business logic)
    D2 -->|"implemented_by"| D4
    D3 -->|"implemented_by"| D5

    %% Service to Repositories
    D1 -->|"queries"| E1
    D2 -->|"queries"| E2
    D3 -->|"queries"| E3

    %% Repositories to Database
    E1 --> F
    E2 --> F
    E3 --> F

    %% Cross-layer usage
    %% Controllers use DTOs to send/receive data
    C1 -.->|"uses"| T1
    C1 -.-> T2
    C2 -.->|"uses"| T4
    C2 -.-> T5
    C3 -.->|"uses"| T6
    %% Also ticket-related DTOs
    C2 -.-> T7
    C3 -.-> T8

    %% Services and Repositories use Domain Models
    D1 -.->|"processes"| M3
    D2 -.-> M1
    D3 -.-> M2

    %% Exception handling in controllers
    C1 -.->|"throws"| G
    C2 -.-> G
    C3 -.-> G

    %% Application containerization relation
    A -->|"deployed_with"| DCK1
    A --> DCK2

    %% Styles
    classDef external fill:#f0f9ff,stroke:#1a5276,stroke-width:2px;
    classDef controller fill:#f9e79f,stroke:#c0392b,stroke-width:2px;
    classDef service fill:#aed6f1,stroke:#1f618d,stroke-width:2px;
    classDef serviceImpl fill:#85c1e9,stroke:#2874a6,stroke-width:2px,stroke-dasharray: 5 5;
    classDef repository fill:#d5f5e3,stroke:#27ae60,stroke-width:2px;
    classDef database fill:#fcf3cf,stroke:#f1c40f,stroke-width:2px;
    classDef security fill:#f5b7b1,stroke:#e74c3c,stroke-width:2px;
    classDef model fill:#fcf3cf,stroke:#f39c12,stroke-width:2px;
    classDef dto fill:#f6ddcc,stroke:#d35400,stroke-width:2px;
    classDef exception fill:#fdebd0,stroke:#f39c12,stroke-width:2px;
    classDef app fill:#d7bde2,stroke:#8e44ad,stroke-width:2px;
    classDef docker fill:#d6eaf8,stroke:#3498db,stroke-width:2px;
```
