# razgrom47/ticketsystem architecture

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

- Interactive diagram: https://gitdiagram.com/razgrom47/ticketsystem
- Repository: https://github.com/razgrom47/ticketsystem

## Overview

##### Project Type and Purpose
- This is a full-stack ticket management system (“TicketSystem”) combining a Java Spring Boot backend (REST API) and a Next.js/React frontend.
- Purpose: allow users to sign in (JWT-based auth), create/edit tickets and messages, upload files, and receive email notifications.

##### Key Components & Directory Structure
- Frontend (src/frontend):
- Next.js app (pages in src/app) with React components, hooks, context for JWT auth, UI theming & settings.
- Auth flow: sign-in, change-password, route guards, context provider.
- Ticket and User sections: pages, forms, filters, tables.
- Backend (src/main/java/com/ticketsystem/griffins):
- Controllers: UserController, TicketController, MessageController, FileController, SessionController.
- Services & Repositories: for users, tickets, messages, files, sessions, JWT management, email notifications.
- Entity/DTO layers modeling database tables.
- Session/filter: JwtFilter handles token validation.
- Flyway DB migrations (src/main/resources/db/migration).
- Database & Infra:
- PostgreSQL (ticketsystem DB) managed via Flyway.
- Email service connects to SMTP.
- Configuration in application.properties.

##### Relationships & Data Flow
- Browser ↔ Next.js frontend:
- User interacts with pages/components.
- Frontend calls backend REST endpoints (via axios utility).
- JWT stored in cookies/local storage; used in Authorization header.
- Next.js ↔ Spring Boot API:
- Authentication endpoints (/session).
- Ticket endpoints (/tickets), Message endpoints (/messages), File endpoints (/files), User endpoints (/users).
- File uploads/downloads.
- API ↔ Database:
- Spring Data JPA repositories read/write PostgreSQL tables.
- Flyway applies migrations on startup.
- API ↔ External Services:
- EmailService sends notifications via SMTP.

##### Architectural Patterns & Principles
- Frontend: Component-based UI, Context API for auth/settings, Route guards for role-based access, Next.js SSR/SSG.
- Backend: Layered MVC (Controller → Service → Repository), DTO mapping, JWT filter for stateless auth, Flyway for migrations.
- Clear separation of concerns: auth, tickets, messages, files, sessions each in own package.

##### Final Advice
- How JWT flows from login to protected endpoints.
- Don’t omit Flyway or file-upload interactions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client"
        Browser["Web Browser"]:::external
    end

    subgraph "Frontend (Next.js/React)"
        direction TB
        NextjsApp["Next.js App\n(pages & routing)"]:::ui
        SignIn["Sign-In Page"]:::ui
        ChangePwd["Change-Password Page"]:::ui
        AuthProvider["Auth Context & JWT Provider"]:::ui
        Guards["Route Guards (AuthGuard, GuestGuard, RoleBasedGuard)"]:::ui
        AxiosUtil["HTTP Client (Axios)"]:::ui
        TicketPages["Ticket Pages"]:::ui
        TicketSections["Ticket Sections (components)"]:::ui
        UserPages["User Pages"]:::ui
        UserSections["User Sections (components)"]:::ui
        Assets["Static Assets (icons & illustrations)"]:::ui
    end

    subgraph "Backend (Spring Boot)"
        direction TB
        MainApp["GriffinsApplication"]:::backend
        subgraph "Controllers"
            direction TB
            UCtrl["UserController"]:::backend
            TCtrl["TicketController"]:::backend
            MCtrl["MessageController"]:::backend
            FCtrl["FileController"]:::backend
            SCtrl["SessionController"]:::backend
        end
        JwtFilter["JwtFilter"]:::backend
        subgraph "Services"
            direction TB
            USvc["UserService"]:::backend
            TSvc["TicketService"]:::backend
            MSvc["MessageService"]:::backend
            FSvc["FileService"]:::backend
            JWTSvc["JWTService"]:::backend
            SsnSvc["SessionService"]:::backend
            ESvc["EmailService"]:::backend
        end
        subgraph "Repositories"
            direction TB
            URepo["UserRepository"]:::persistence
            TRepo["TicketRepository"]:::persistence
            MRepo["MessageRepository"]:::persistence
            FRepo["FileRepository"]:::persistence
            SsnRepo["SessionRepository"]:::persistence
        end
        Entities["Entities & DTOs"]:::persistence
    end

    subgraph "Database & Migrations"
        direction TB
        Flyway["Flyway Migrations"]:::persistence
        Postgres["PostgreSQL DB"]:::persistence
    end

    subgraph "External Services"
        SMTP["SMTP Email Service"]:::external
    end

    Browser -->|"UI requests/navigation"| NextjsApp
    NextjsApp -->|"renders"| SignIn
    NextjsApp -->|"renders"| ChangePwd
    NextjsApp -->|"uses"| Assets
    NextjsApp -->|"uses"| TicketPages
    NextjsApp -->|"uses"| TicketSections
    NextjsApp -->|"uses"| UserPages
    NextjsApp -->|"uses"| UserSections
    SignIn -->|"auth context"| AuthProvider
    ChangePwd -->|"auth context"| AuthProvider
    NextjsApp -->|"guards routes"| Guards
    NextjsApp -->|"http calls"| AxiosUtil
    TicketPages -->|"http calls"| AxiosUtil
    TicketSections -->|"http calls"| AxiosUtil
    UserPages -->|"http calls"| AxiosUtil
    UserSections -->|"http calls"| AxiosUtil

    AxiosUtil -->|"REST calls with JWT"| UCtrl
    AxiosUtil -->|"REST calls with JWT"| TCtrl
    AxiosUtil -->|"REST calls with JWT"| MCtrl
    AxiosUtil -->|"REST calls with JWT"| FCtrl
    AxiosUtil -->|"REST calls"| SCtrl

    JwtFilter -->|"validates token"| UCtrl
    JwtFilter -->|"validates token"| TCtrl
    JwtFilter -->|"validates token"| MCtrl
    JwtFilter -->|"validates token"| FCtrl
    JwtFilter -->|"validates token"| SCtrl

    UCtrl -->|"calls"| USvc
    TCtrl -->|"calls"| TSvc
    MCtrl -->|"calls"| MSvc
    FCtrl -->|"calls"| FSvc
    SCtrl -->|"calls"| SsnSvc
    SCtrl -->|"calls"| JWTSvc

    USvc -->|"uses"| URepo
    TSvc -->|"uses"| TRepo
    MSvc -->|"uses"| MRepo
    FSvc -->|"uses"| FRepo
    SsnSvc -->|"uses"| SsnRepo
    JWTSvc -->|"uses"| SsnRepo

    ESvc -->|"sends email via"| SMTP

    MainApp -->|"bootstraps"| UCtrl
    MainApp -->|"bootstraps"| TCtrl
    MainApp -->|"bootstraps"| MCtrl
    MainApp -->|"bootstraps"| FCtrl
    MainApp -->|"bootstraps"| SCtrl
    MainApp -->|"bootstraps"| JwtFilter
    MainApp -->|"bootstraps"| USvc
    MainApp -->|"bootstraps"| TSvc
    MainApp -->|"bootstraps"| MSvc
    MainApp -->|"bootstraps"| FSvc
    MainApp -->|"bootstraps"| JWTSvc
    MainApp -->|"bootstraps"| SsnSvc
    MainApp -->|"bootstraps"| ESvc
    MainApp -->|"runs migrations"| Flyway

    URepo -->|"reads/writes"| Postgres
    TRepo -->|"reads/writes"| Postgres
    MRepo -->|"reads/writes"| Postgres
    FRepo -->|"reads/writes"| Postgres
    SsnRepo -->|"reads/writes"| Postgres
    Flyway -->|"migrates"| Postgres

    classDef ui fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef backend fill:#d4edda,stroke:#333,stroke-width:1px
    classDef persistence fill:#fff3cd,stroke:#333,stroke-width:1px
    classDef external fill:#e2e3e5,stroke:#333,stroke-width:1px

    click NextjsApp "https://github.com/razgrom47/ticketsystem/tree/main/src/frontend/src/app"
    click SignIn "https://github.com/razgrom47/ticketsystem/tree/main/src/frontend/src/app/auth/sign-in"
    click ChangePwd "https://github.com/razgrom47/ticketsystem/tree/main/src/frontend/src/app/auth/change-password"
    click AuthProvider "https://github.com/razgrom47/ticketsystem/blob/main/src/frontend/src/auth/context/jwt/auth-provider.jsx"
    click Guards "https://github.com/razgrom47/ticketsystem/tree/main/src/frontend/src/auth/guard"
    click AxiosUtil "https://github.com/razgrom47/ticketsystem/blob/main/src/frontend/src/utils/axios.js"
    click TicketPages "https://github.com/razgrom47/ticketsystem/tree/main/src/frontend/src/app/ticket"
    click TicketSections "https://github.com/razgrom47/ticketsystem/tree/main/src/frontend/src/sections/ticket"
    click UserPages "https://github.com/razgrom47/ticketsystem/tree/main/src/frontend/src/app/user"
    click UserSections "https://github.com/razgrom47/ticketsystem/tree/main/src/frontend/src/sections/user"
    click Assets "https://github.com/razgrom47/ticketsystem/tree/main/src/frontend/public/assets"
    click MainApp "https://github.com/razgrom47/ticketsystem/blob/main/src/main/java/com/ticketsystem/griffins/GriffinsApplication.java"
    click UCtrl "https://github.com/razgrom47/ticketsystem/blob/main/src/main/java/com/ticketsystem/griffins/users/controller/UserController.java"
    click TCtrl "https://github.com/razgrom47/ticketsystem/blob/main/src/main/java/com/ticketsystem/griffins/tickets/controller/TicketController.java"
    click MCtrl "https://github.com/razgrom47/ticketsystem/blob/main/src/main/java/com/ticketsystem/griffins/messages/controller/MessageController.java"
    click FCtrl "https://github.com/razgrom47/ticketsystem/blob/main/src/main/java/com/ticketsystem/griffins/files/controller/FileController.java"
    click SCtrl "https://github.com/razgrom47/ticketsystem/blob/main/src/main/java/com/ticketsystem/griffins/session/controller/SessionController.java"
    click JwtFilter "https://github.com/razgrom47/ticketsystem/blob/main/src/main/java/com/ticketsystem/griffins/session/filter/JwtFilter.java"
    click USvc "https://github.com/razgrom47/ticketsystem/blob/main/src/main/java/com/ticketsystem/griffins/users/service/UserService.java"
    click URepo "https://github.com/razgrom47/ticketsystem/blob/main/src/main/java/com/ticketsystem/griffins/users/repository/UserRepository.java"
    click TSvc "https://github.com/razgrom47/ticketsystem/blob/main/src/main/java/com/ticketsystem/griffins/tickets/service/TicketService.java"
    click TRepo "https://github.com/razgrom47/ticketsystem/blob/main/src/main/java/com/ticketsystem/griffins/tickets/repository/TicketRepository.java"
    click MSvc "https://github.com/razgrom47/ticketsystem/blob/main/src/main/java/com/ticketsystem/griffins/messages/service/MessageService.java"
    click MRepo "https://github.com/razgrom47/ticketsystem/blob/main/src/main/java/com/ticketsystem/griffins/messages/repository/MessageRepository.java"
    click FSvc "https://github.com/razgrom47/ticketsystem/blob/main/src/main/java/com/ticketsystem/griffins/files/service/FileService.java"
    click FRepo "https://github.com/razgrom47/ticketsystem/blob/main/src/main/java/com/ticketsystem/griffins/files/repository/FileRepository.java"
    click JWTSvc "https://github.com/razgrom47/ticketsystem/blob/main/src/main/java/com/ticketsystem/griffins/session/service/JWTService.java"
    click SsnSvc "https://github.com/razgrom47/ticketsystem/blob/main/src/main/java/com/ticketsystem/griffins/session/service/SessionService.java"
    click SsnRepo "https://github.com/razgrom47/ticketsystem/blob/main/src/main/java/com/ticketsystem/griffins/session/repository/SessionRepository.java"
    click ESvc "https://github.com/razgrom47/ticketsystem/blob/main/src/main/java/com/ticketsystem/griffins/emailNotification/Service/EmailService.java"
    click Flyway "https://github.com/razgrom47/ticketsystem/tree/main/src/main/resources/db/migration"
```
