# nguyendatgh/eventsticket_hub architecture

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

- Interactive diagram: https://gitdiagram.com/nguyendatgh/eventsticket_hub
- Repository: https://github.com/nguyendatgh/eventsticket_hub

## Overview

##### Project Type and Purpose
- This is a Java Servlet–based web application (packaged as a WAR via Maven) implementing an event-ticket booking system.
- It follows the classic Model-View-Controller (MVC) pattern:
- Controllers are servlets under src/main/java/controller
- Views are JSPs under src/main/webapp
- The Model/Service layer consists of DAO classes (src/main/java/dao), entity models (src/main/java/models), and utility classes (src/main/java/utils)
- It uses an RDBMS (defined in databaseScript/EventTicketDB.sql) with JDBC (DBConnection) and JPA configuration (META-INF/persistence.xml).
- It integrates with an external payment gateway (VNPay).

##### File-Structure Analysis and Architectural Patterns
- Top-level: pom.xml, compile scripts, database script → Maven build + SQL schema setup
- src/main/java/context/DBConnection.java and persistence.xml → Data access configuration
- src/main/java/dao/*DAO.java → Data Access Objects for CRUD on Event, User, Order, etc.
- src/main/java/controller/*.java → Servlet controllers handling HTTP requests and orchestrating between view and model
- src/main/java/models/*.java → JavaBeans representing database tables
- src/main/java/utils and vnpay/config → Cross-cutting utilities (email, file upload, hashing, Google OAuth, VNPay config)
- src/main/webapp → JSP pages (views), static assets (CSS, images), web.xml & beans.xml (Servlet + CDI config)
- Patterns: MVC, DAO, Utility classes, External Service Integration

##### Key Insights from README
- Compile with compile.sh/.bat → produces target/*.war
- Deploy WAR to Apache Tomcat
- Access servlets via URLs like http://localhost:8080/YourApp/ServletPath

##### Main Components
a. User–Facing Browser (UI)
- JSPs (login, register, event listing, booking, payment pages) served by Tomcat
b. Web Container (Tomcat)
- Receives HTTP requests, dispatches to Servlets
c. Controller Layer (Servlets)
- Handles routes: LoginServlet, EventServlet, BookChairServlet, PaymentServlet, VNPayPaymentServlet, etc.
d. Service/DAO Layer
- DAO classes (EventDAO, UserDAO, OrderDAO, etc.) for database operations
e. Database
- MySQL/PostgreSQL using JDBC connection (DBConnection) and JPA entities
f. External Payment Gateway (VNPay)
- VNPayConfig and payment servlets for redirect/callback
g. Utility Services
- EmailUtil, GoogleUtils, HashUtil, FileUploadUtil

##### Component Relationships and Interactions
- Browser → HTTP request → Tomcat → Servlet (Controller)
- Servlet → calls DAO/Service → JDBC/JPA → Database
- Servlet → forwards to JSP (using ForwardJspUtils) → Browser (HTML)
- For payments: Servlet → redirects to VNPay → user authorizes → VNPay callback → VNPayReturnServlet → update OrderDAO → JSP PaymentResult
- Utilities invoked by controllers for hashing, emailing, file uploads

##### Architectural Patterns and Principles
- MVC: Separation of concerns between UI (JSP), Controller (Servlet), Model (DAO/Entities)
- DAO Pattern: Isolate data access logic
- Singleton (DBConnection) or connection‐pool usage
- Utility classes for cross-cutting concerns
- External service adapter (VNPay integration)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% UI Layer
    subgraph "UI Layer"
        direction TB
        Browser["User Browser"]:::ui
        JSP["JSP Pages"]:::ui
    end

    %% Web Container
    subgraph "Web Container (Tomcat)"
        direction TB
        HomePageServlet["HomePageServlet"]:::controller
        EventServlet["EventServlet"]:::controller
        BookChairServlet["BookChairServlet"]:::controller
        PaymentServlet["PaymentServlet"]:::controller
        VNPayPaymentServlet["VNPayPaymentServlet"]:::controller
        VNPayReturnServlet["VNPayReturnServlet"]:::controller
    end

    %% Service/DAO Layer
    subgraph "Service/DAO Layer"
        direction TB
        EventDAO["EventDAO"]:::dao
        UserDAO["UserDAO"]:::dao
        OrderDAO["OrderDAO"]:::dao
        TicketInforDAO["TicketInforDAO"]:::dao
        PromotionDAO["PromotionDAO"]:::dao
        GenreDAO["GenreDAO"]:::dao
        OrderItemDAO["OrderItemDAO"]:::dao
    end

    %% Model Entities
    subgraph "Entity Models"
        direction TB
        Models["JPA Entity Models"]:::models
    end

    %% Utilities
    subgraph "Utility Services"
        direction TB
        Utils["EmailUtil, GoogleUtils, HashUtil, FileUploadUtil, ForwardJspUtils"]:::utils
        DBConn["DBConnection"]:::utils
        Persistence["persistence.xml"]:::utils
        VnPayConfig["VnPayConfig"]:::utils
    end

    %% Database
    Database["Relational Database"]:::db

    %% External Payment Gateway
    VNPay["VNPay Service"]:::external

    %% Flows
    Browser -->|HTTP Request| HomePageServlet
    Browser -->|HTTP Request| EventServlet
    Browser -->|HTTP Request| BookChairServlet
    Browser -->|HTTP Request| PaymentServlet

    HomePageServlet -->|forward| JSP
    EventServlet -->|forward| JSP
    BookChairServlet -->|JDBC/JPA calls| OrderDAO
    PaymentServlet -->|redirect| VNPay
    VNPayPaymentServlet -->|redirect| VNPay
    VNPayReturnServlet -->|callback| VNPay
    VNPayReturnServlet -->|update| OrderDAO

    HomePageServlet -->|uses| Utils
    EventServlet -->|uses| Utils
    BookChairServlet -->|uses| Utils
    PaymentServlet -->|uses| Utils
    VNPayPaymentServlet -->|uses| Utils
    VNPayReturnServlet -->|uses| Utils

    OrderDAO -->|CRUD| Database
    EventDAO -->|CRUD| Database
    UserDAO -->|CRUD| Database
    TicketInforDAO -->|CRUD| Database
    PromotionDAO -->|CRUD| Database
    GenreDAO -->|CRUD| Database
    OrderItemDAO -->|CRUD| Database

    Utils -->|JDBC Singleton| DBConn
    Utils -->|JPA Config| Persistence
    VNPayPaymentServlet -->|configures| VnPayConfig
    VNPayReturnServlet -->|configures| VnPayConfig

    %% Click Events
    click JSP "https://github.com/nguyendatgh/eventsticket_hub/tree/main/src/main/webapp"
    click HomePageServlet "https://github.com/nguyendatgh/eventsticket_hub/blob/main/src/main/java/controller/HomePageServlet.java"
    click EventServlet "https://github.com/nguyendatgh/eventsticket_hub/blob/main/src/main/java/controller/EventServlet.java"
    click BookChairServlet "https://github.com/nguyendatgh/eventsticket_hub/blob/main/src/main/java/controller/BookChairServlet.java"
    click PaymentServlet "https://github.com/nguyendatgh/eventsticket_hub/blob/main/src/main/java/controller/PaymentServlet.java"
    click VNPayPaymentServlet "https://github.com/nguyendatgh/eventsticket_hub/blob/main/src/main/java/controller/VNPayPaymentServlet.java"
    click VNPayReturnServlet "https://github.com/nguyendatgh/eventsticket_hub/blob/main/src/main/java/controller/VNPayReturnServlet.java"
    click EventDAO "https://github.com/nguyendatgh/eventsticket_hub/blob/main/src/main/java/dao/EventDAO.java"
    click UserDAO "https://github.com/nguyendatgh/eventsticket_hub/blob/main/src/main/java/dao/UserDAO.java"
    click OrderDAO "https://github.com/nguyendatgh/eventsticket_hub/blob/main/src/main/java/dao/OrderDAO.java"
    click TicketInforDAO "https://github.com/nguyendatgh/eventsticket_hub/blob/main/src/main/java/dao/TicketInforDAO.java"
    click PromotionDAO "https://github.com/nguyendatgh/eventsticket_hub/blob/main/src/main/java/dao/PromotionDAO.java"
    click GenreDAO "https://github.com/nguyendatgh/eventsticket_hub/blob/main/src/main/java/dao/GenreDAO.java"
    click OrderItemDAO "https://github.com/nguyendatgh/eventsticket_hub/blob/main/src/main/java/dao/OrderItemDAO.java"
    click DBConn "https://github.com/nguyendatgh/eventsticket_hub/blob/main/src/main/java/context/DBConnection.java"
    click Persistence "https://github.com/nguyendatgh/eventsticket_hub/blob/main/src/main/resources/META-INF/persistence.xml"
    click VnPayConfig "https://github.com/nguyendatgh/eventsticket_hub/blob/main/src/main/java/vnpay/config/VnPayConfig.java"
    click Utils "https://github.com/nguyendatgh/eventsticket_hub/tree/main/src/main/java/utils"

    %% Styles
    classDef ui fill:#add8e6,stroke:#333,stroke-width:1px
    classDef controller fill:#90ee90,stroke:#333,stroke-width:1px
    classDef dao fill:#ffa500,stroke:#333,stroke-width:1px
    classDef models fill:#ffdead,stroke:#333,stroke-width:1px
    classDef utils fill:#f0e68c,stroke:#333,stroke-width:1px
    classDef db fill:#696969,stroke:#fff,stroke-width:1px
    classDef external fill:#dda0dd,stroke:#333,stroke-width:1px
```
