# kenny516/ticket-vol architecture

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

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

## Overview

##### Main Components
- Frontend (View Layer):
- Contains JSP pages under /src/main/webapp, with separate directories for "front-office" (user interface) and "back-office" (admin interface).
- Includes static assets (CSS, JavaScript) and JSP error pages.
- Backend:
- Controllers: Classes in the com/mg/controller package handle incoming HTTP requests using custom annotations (@Controller, @Get, @Post, @Url). The separation into back-office and front-office controllers is evident.
- Services: Business logic is encapsulated in the com/mg/service package, supporting various operations such as reservations, promotion handling, and flight (vol) management.
- Data Access Layer: DAO classes in the com/mg/dao package manage CRUD operations and repository interactions (with PostgreSQL via Hibernate).
- Models/DTOs: Domain entity classes are in com/mg/model for persistence and in com/mg/DTO for data transfer across layers.
- Filters: An authentication filter in com/mg/filter ensures role-based and session-based authentication.
- Persistence and Database:
- Hibernate configuration files (hibernate.cfg.xml and persistence.xml) and SQL scripts (data.sql, script.sql) in src/main/resources define the ORM settings and schema.
- A PostgreSQL database is used, consistent with the README guidance.
- Custom Framework:
- The lib/Framework.jar implements core features like routing, controller management, session handling, and view resolution, forming the backbone of the custom MVC framework.

##### Relationships and Interactions
- Client Browsers make HTTP requests that reach the web server (e.g., Tomcat) hosting the application.
- The request passes through the servlet container and any configured filters (AuthenticationFilter) to enforce security.
- Requests are routed by the custom framework to appropriate @Controller classes based on URL mappings (@Url annotations).
- Controllers interact with the Service layer to process business logic and then use DAO classes to perform database operations using Hibernate.
- Results are converted into a ModelAndView object directing the framework to the correct JSP view for rendering.
- The CustomSession and role-based authentication logic ensure stateful interactions.

##### Architectural Patterns and Design Principles
- MVC Pattern: Clearly segregates responsibilities among views, controllers, and models.
- Layered Architecture: Separates concerns (presentation, business logic, data access).
- Custom Annotation-based Routing: Simplifies HTTP method mapping and parameter binding.
- Session and Role-based Security: Incorporated via custom authentication annotations and session utilities.
- Dependency Management: Maven (pom.xml) is used for dependency injection and build processes.

##### Relevant Technologies, Frameworks, and Libraries
- Java (Custom lightweight framework)
- Jakarta Servlet API (for HTTP requests/response handling)
- Hibernate ORM for database interaction
- PostgreSQL (database)
- GSON (for potential JSON processing)
- JSP for view rendering, enhanced by Bootstrap and DataTables for presentation

##### Detail and Clarity
- The goal is to provide a comprehensive view that could be used to understand, maintain, or extend the system.

## Diagram (Mermaid)

```mermaid
flowchart TD
    BROWSER["Client Browser"]:::external
    BROWSER -->|"HTTP_Request"| AUTH["Authentication Filter"]:::framework
    AUTH -->|"passesRequest"| FRAME["Custom Framework & Libraries"]:::framework
    FRAME -->|"routesTo"| CONTROLLER["Controllers (@Controller classes)"]:::backend
    CONTROLLER -->|"calls"| SERVICES["Services (Business Logic)"]:::backend
    SERVICES -->|"invokes"| DAO["Data Access Layer (DAO)"]:::dao
    DAO -->|"performsCRUD"| DATABASE["PostgreSQL Database"]:::persistence

    CONTROLLER -->|"rendersView"| FRONT_OFFICE["Front-office Views (JSP)"]:::presentation
    CONTROLLER -->|"rendersView"| BACK_OFFICE["Back-office Views (JSP)"]:::presentation

    DAO -->|"uses"| MODELS["Domain Models"]:::backend
    DAO -->|"uses"| DTO["Data Transfer Objects (DTO)"]:::backend

    DAO -->|"configures"| HIBERNATE["Hibernate Configuration"]:::persistence
    DAO -->|"configures"| PERSISTENCE["JPA Persistence Configuration"]:::persistence
    DAO -->|"initializes"| DATA_SQL["Data SQL Script"]:::persistence
    DAO -->|"initializes"| SCHEMA_SQL["Schema SQL Script"]:::persistence

    subgraph "Frontend Layer"
        FRONT_OFFICE
        BACK_OFFICE
    end

    subgraph "Domain Layer"
        MODELS
        DTO
    end

    subgraph "Persistence Setup"
        HIBERNATE
        PERSISTENCE
        DATA_SQL
        SCHEMA_SQL
        DATABASE
    end

    %% Click Events
    click FRONT_OFFICE "https://github.com/kenny516/ticket-vol/tree/main/src/main/webapp/front-office"
    click BACK_OFFICE "https://github.com/kenny516/ticket-vol/tree/main/src/main/webapp/back-office"
    click CONTROLLER "https://github.com/kenny516/ticket-vol/tree/main/src/main/java/com/mg/controller"
    click SERVICES "https://github.com/kenny516/ticket-vol/tree/main/src/main/java/com/mg/service"
    click DAO "https://github.com/kenny516/ticket-vol/tree/main/src/main/java/com/mg/dao"
    click MODELS "https://github.com/kenny516/ticket-vol/tree/main/src/main/java/com/mg/model"
    click DTO "https://github.com/kenny516/ticket-vol/tree/main/src/main/java/com/mg/DTO"
    click AUTH "https://github.com/kenny516/ticket-vol/blob/main/src/main/java/com/mg/filter/AuthenticationFilter.java"
    click HIBERNATE "https://github.com/kenny516/ticket-vol/blob/main/src/main/resources/hibernate.cfg.xml"
    click PERSISTENCE "https://github.com/kenny516/ticket-vol/blob/main/src/main/resources/META-INF/persistence.xml"
    click DATA_SQL "https://github.com/kenny516/ticket-vol/blob/main/src/main/resources/data.sql"
    click SCHEMA_SQL "https://github.com/kenny516/ticket-vol/blob/main/src/main/resources/script.sql"
    click FRAME "https://github.com/kenny516/ticket-vol/blob/main/lib/Framework.jar"

    %% Styles
    classDef external fill:#ffdead,stroke:#000,stroke-width:2px;
    classDef presentation fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#333,stroke-width:2px;
    classDef dao fill:#f8d7da,stroke:#333,stroke-width:2px;
    classDef persistence fill:#fff3cd,stroke:#333,stroke-width:2px;
    classDef framework fill:#d1c4e9,stroke:#333,stroke-width:2px;
```
