# elvificent/ticket architecture

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

- Interactive diagram: https://gitdiagram.com/elvificent/ticket
- Repository: https://github.com/elvificent/ticket

## Overview

##### Project Type and Purpose
- This is a full-stack ticket-support application.
- Front-end: React SPA (Vite) providing pages for login, ticket creation, viewing, chatbot, resources, etc.
- Back-end: Spring Boot REST API managing users, tickets, sessions, products, authentication/authorization via JWT.
- Database: Relational (initialized via schema.sql).

##### File Structure Analysis
- Top-level: `frontend/`, `backend/`, documentation files (API_DOCUMENTATION.md, GUIDE.md).
- backend: Standard Maven/Spring Boot layout.
- `config` (security, JWT, data initializer)
- `controller` (REST endpoints)
- `service` (business logic)
- `repository` (JPA interfaces)
- `model` (entities, enums)
- `security` (filters, token provider, user details)
- resources: `application.properties`, `schema.sql`
- frontend: Vite + React.
- `src/Components` (Header, Footer)
- `src/Pages` (multiple page folders)
- `main.jsx` bootstraps the app, uses React Router and Axios for API calls.

##### Key Insights from README
- Back-end: Oracle JDK, Maven, runs via `mvn spring-boot:run`.
- Front-end: Node & npm, `npm run dev` to start.
- Dependencies: `react-router-dom`, `axios`, FontAwesome.

##### Main Components
a. Front-end (React SPA)
b. API Gateway / Back-end (Spring Boot)
c. Auth subsystem (JWT token provider, filters)
d. Service layer (business logic services per entity)
e. Persistence layer (Spring Data JPA repositories)
f. Database (e.g., PostgreSQL/MySQL)
g. DataInitializer (initial seed data)
h. External (optional) Chatbot or 3rd-party resources (if any)

##### Relationships & Data Flows
- React UI → HTTP/HTTPS → Spring Boot Controllers
- Controllers → Service layer → Repository → Database
- On login: AuthController ↔ JwtTokenProvider → HTTP response with JWT
- Protected endpoints: JwtRequestFilter intercepts requests, validates JWT via CustomUserDetailsService
- DataInitializer runs at startup to seed reference data
- Front-end Axios calls include JWT in Authorization header

##### Architectural Patterns & Design Principles
- Layered architecture (Controller → Service → Repository → Database)
- Dependency Injection via Spring
- Stateless authentication with JWT
- Front-end single-page application using client-side routing
- DTOs for API responses

##### Detailed Elements to Capture
- Front-end modules/pages (Login, CreateTicket, TicketInformation, Chatbot)
- API controllers (AuthController, TicketController, UserController, etc.)
- Auth flow: `AuthController` → `JwtTokenProvider`, `JwtAuthenticationFilter`
- Service layer classes corresponding to each domain entity
- Repository interfaces connecting to the database
- Database with seeded data (via DataInitializer + schema.sql)

##### Final Advice
- Don’t over-complicate: reflect the three major tiers and their sub-components.
- Every REST endpoint class is represented under the API layer.
- Security checks as a middleware/filter between UI and controllers.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Presentation Layer"
        UI["React SPA"]:::frontend
        Boot["App Bootstrap (main.jsx)"]:::frontend
        Header["Header"]:::frontend
        Footer["Footer"]:::frontend
        Login["Login Page"]:::frontend
        CreateT["CreateTicket Page"]:::frontend
        TicketInfo["TicketInformation Page"]:::frontend
        Chatbot["Chatbot Page"]:::frontend
        Resources["ResourcesAndGuides Page"]:::frontend
        Intro["Introduction"]:::frontend
        SearchRes["SearchResources"]:::frontend
    end

    subgraph "API Layer"
        AppEntry["TicketApplication"]:::backend

        subgraph "Controllers"
            AuthCtrl["AuthController"]:::backend
            TicketCtrl["TicketController"]:::backend
            UserCtrl["UserController"]:::backend
            CustomerCtrl["CustomerController"]:::backend
            EngineerCtrl["EngineerController"]:::backend
            SessionCtrl["SessionController"]:::backend
        end

        subgraph "Auth Subsystem"
            JwtProv["JwtTokenProvider"]:::security
            JwtReqFilt["JwtRequestFilter"]:::security
            JwtAuthFilt["JwtAuthenticationFilter"]:::security
            UserDetails["CustomUserDetailsService"]:::security
            JwtResp["JwtResponse"]:::security
        end

        subgraph "Config"
            SecurityCfg["SecurityConfig"]:::backend
            JwtCfg["JwtConfig"]:::backend
            DataInit["DataInitializer"]:::backend
        end

        subgraph "Services"
            AuthServ["AuthService"]:::backend
            TicketServ["TicketService"]:::backend
            UserServ["UserService"]:::backend
            CustomerServ["CustomerService"]:::backend
            EngineerServ["EngineerService"]:::backend
            ManagerServ["ManagerService"]:::backend
            ProductServ["ProductService"]:::backend
            SessionServ["SessionService"]:::backend
            TicketTypeServ["TicketTypeService"]:::backend
        end

        subgraph "Repositories"
            UserRepo["UserRepository"]:::backend
            TicketRepo["TicketRepository"]:::backend
            CustomerRepo["CustomerRepository"]:::backend
            EngineerRepo["EngineerRepository"]:::backend
            ManagerRepo["ManagerRepository"]:::backend
            ProductRepo["ProductRepository"]:::backend
            SessionRepo["SessionRepository"]:::backend
            TicketTypeRepo["TicketTypeRepository"]:::backend
        end
    end

    subgraph "Data Layer"
        DB["Relational Database"]:::database
        Schema["schema.sql"]:::database
    end

    %% Data Flows
    UI -->|HTTP/HTTPS| AuthCtrl
    UI -->|HTTP/HTTPS| TicketCtrl
    UI -->|HTTP/HTTPS| UserCtrl
    UI -->|HTTP/HTTPS| CustomerCtrl
    UI -->|HTTP/HTTPS| EngineerCtrl
    UI -->|HTTP/HTTPS| SessionCtrl

    JwtReqFilt -.->|validates JWT| AuthCtrl
    AuthCtrl -->|calls| JwtProv
    AuthCtrl -->|uses| AuthServ
    JwtProv -->|issues tokens| JwtResp

    AuthCtrl -->|calls| AuthServ
    TicketCtrl -->|calls| TicketServ
    UserCtrl -->|calls| UserServ
    CustomerCtrl -->|calls| CustomerServ
    EngineerCtrl -->|calls| EngineerServ
    SessionCtrl -->|calls| SessionServ

    AuthServ -->|uses| UserRepo
    TicketServ -->|uses| TicketRepo
    UserServ -->|uses| UserRepo
    CustomerServ -->|uses| CustomerRepo
    EngineerServ -->|uses| EngineerRepo
    ManagerServ -->|uses| ManagerRepo
    ProductServ -->|uses| ProductRepo
    SessionServ -->|uses| SessionRepo
    TicketTypeServ -->|uses| TicketTypeRepo

    UserRepo -->|reads/writes| DB
    TicketRepo -->|reads/writes| DB
    CustomerRepo -->|reads/writes| DB
    EngineerRepo -->|reads/writes| DB
    ManagerRepo -->|reads/writes| DB
    ProductRepo -->|reads/writes| DB
    SessionRepo -->|reads/writes| DB
    TicketTypeRepo -->|reads/writes| DB

    DataInit -->|seeds| DB
    Schema -->|initial schema| DB

    AppEntry --> Controllers
    SecurityCfg --> AuthSubsystem
    JwtCfg --> AuthSubsystem

    %% Click Events
    click UI "https://github.com/elvificent/ticket/tree/main/frontend/src"
    click Boot "https://github.com/elvificent/ticket/blob/main/frontend/src/main.jsx"
    click Header "https://github.com/elvificent/ticket/blob/main/frontend/src/Components/Header.jsx"
    click Footer "https://github.com/elvificent/ticket/blob/main/frontend/src/Components/Footer.jsx"
    click Login "https://github.com/elvificent/ticket/blob/main/frontend/src/Pages/Login Page/Login.jsx"
    click CreateT "https://github.com/elvificent/ticket/blob/main/frontend/src/Pages/Ticket Support Page/CreateTicket.jsx"
    click TicketInfo "https://github.com/elvificent/ticket/blob/main/frontend/src/Pages/Ticket View Page/TicketInformation.jsx"
    click Chatbot "https://github.com/elvificent/ticket/blob/main/frontend/src/Pages/Customer Chatbot Page/Chatbot.jsx"
    click Resources "https://github.com/elvificent/ticket/blob/main/frontend/src/Pages/ResourcesAndGuides Page/ResourcesAndGuides.jsx"
    click Intro "https://github.com/elvificent/ticket/blob/main/frontend/src/Pages/Home Page/Introduction.jsx"
    click SearchRes "https://github.com/elvificent/ticket/blob/main/frontend/src/Pages/Home Page/SearchResources.jsx"
    click AppEntry "https://github.com/elvificent/ticket/blob/main/backend/src/main/java/com/Elvis/ticket/TicketApplication.java"
    click AuthCtrl "https://github.com/elvificent/ticket/blob/main/backend/src/main/java/com/Elvis/ticket/controller/AuthController.java"
    click TicketCtrl "https://github.com/elvificent/ticket/blob/main/backend/src/main/java/com/Elvis/ticket/controller/TicketController.java"
    click UserCtrl "https://github.com/elvificent/ticket/blob/main/backend/src/main/java/com/Elvis/ticket/controller/UserController.java"
    click CustomerCtrl "https://github.com/elvificent/ticket/blob/main/backend/src/main/java/com/Elvis/ticket/controller/CustomerController.java"
    click EngineerCtrl "https://github.com/elvificent/ticket/blob/main/backend/src/main/java/com/Elvis/ticket/controller/EngineerController.java"
    click SessionCtrl "https://github.com/elvificent/ticket/blob/main/backend/src/main/java/com/Elvis/ticket/controller/SessionController.java"
    click JwtProv "https://github.com/elvificent/ticket/blob/main/backend/src/main/java/com/Elvis/ticket/security/JwtTokenProvider.java"
    click JwtReqFilt "https://github.com/elvificent/ticket/blob/main/backend/src/main/java/com/Elvis/ticket/security/JwtRequestFilter.java"
    click JwtAuthFilt "https://github.com/elvificent/ticket/blob/main/backend/src/main/java/com/Elvis/ticket/security/JwtAuthenticationFilter.java"
    click UserDetails "https://github.com/elvificent/ticket/blob/main/backend/src/main/java/com/Elvis/ticket/security/CustomUserDetailsService.java"
    click JwtResp "https://github.com/elvificent/ticket/blob/main/backend/src/main/java/com/Elvis/ticket/security/JwtResponse.java"
    click SecurityCfg "https://github.com/elvificent/ticket/blob/main/backend/src/main/java/com/Elvis/ticket/config/SecurityConfig.java"
    click JwtCfg "https://github.com/elvificent/ticket/blob/main/backend/src/main/java/com/Elvis/ticket/config/JwtConfig.java"
    click DataInit "https://github.com/elvificent/ticket/blob/main/backend/src/main/java/com/Elvis/ticket/config/DataInitializer.java"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000
    classDef backend fill:#90EE90,stroke:#000
    classDef security fill:#FFA500,stroke:#000
    classDef database fill:#D3D3D3,stroke:#000
    class AuthSubsystem,JwtProv,JwtReqFilt,JwtAuthFilt,UserDetails,JwtResp security
```
