How hiendang123a/project_web works
Main Components
• Client/Presentation Layer: This is represented by the web pages (JSP files under /src/main/webapp, divided into Admin, KhachHang, Staff, etc.), CSS, JavaScript assets, and static resources. The user interfaces are developed with JSPs and front-end resources.
• Controller Layer: Under the “src/main/java/controller” package (including sub-packages for chat, customerController, order, and staffManagementController), Servlets are used to handle HTTP requests which bridge the client and business logic.
• Business / Domain Layer: The “business” package contains core domain models (e.g., Furniture, Customer, Order, Payment) and resource configuration (like JakartaEE8Resource). This layer represents the data and business rules.
• Service Layer: There are interfaces and implementations in “src/main/java/services” (and its sub-packages, including customerService and impl) which encapsulate the business logic. They act as an intermediary between the controllers and the data access layer.
• Data Access Layer: The “DAO” packages (and its sub-folders) hold various Data Access Objects (like CategoryDAO, FurnitureDAO, OrderDAO, etc.) that interact with the database. Additionally, utility classes in the “data” and “utils” packages (e.g., DBUtil, ImageUtil and others) help to manage database connections and common operations.
• Data Transfer / Mapping: The project includes DTO (Data Transfer Object) packages and Mapper classes (including “Mapper/customerConvert”) that handle data conversions between various layers.
• Third-Party Integrations: There are specialized packages such as “VietQR” for potential payment or banking service integration, “googlelogin” for handling Google authentication, and “mail” for email and OTP services.
• Infrastructure and Configuration: The persistence.xml file (located in src/main/resources/META-INF) configures JPA with MySQL. Tomcat configuration files in .smarttomcat, and Maven’s pom.xml, set up the build, deployment, and runtime environment.
Relationships and Interactions
• Client requests made through a browser hit the Web Layer (JSPs), which delegate to the Controller Layer (Servlets).
• Controllers then invoke services in the Service Layer to execute business logic.
• The Service Layer uses DAOs in the Data Access Layer to perform CRUD operations on the MySQL database.
• DTOs and Mapper classes help format the data appropriately as it travels between the layers.
• The Apache Tomcat server acts as the runtime container, hosting the web application, and facilitating communications between client requests and server responses.
Architectural Patterns and Design Principles
• Layered Architecture: The clear separation (Presentation, Controller, Business/Service, and Data Access) adheres to the layered pattern, making it easier to track concerns and maintain the application.
• MVC Pattern: Controllers (servlets) mediate between the view (JSPs) and the model (business objects/DTOs), representing a classic Model-View-Controller design.
• Dependency Injection and Decoupling: Usage of configuration files (like persistence.xml) and the existence of Mapper and Service interfaces indicate an adherence to loose coupling and modular design.
• External Integration Points for third-party services (such as Google login, VietQR for payments, and email services) are clearly delineated.