How nguyendatgh/eventsticket_hub works
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)