# tqchuong/thuctapweb architecture

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

- Interactive diagram: https://gitdiagram.com/tqchuong/thuctapweb
- Repository: https://github.com/tqchuong/thuctapweb

## Overview

##### Main Components
- User Interface / Web Presentation Layer: Represented by the JSP files (e.g., home.jsp, login.jsp, products.jsp, etc.), HTML files, CSS, JavaScript (in the “src/main/webapp” directory). This layer provides the client-side experience.
- Controller Layer: Mainly the Java classes in the “controller” package. This includes numerous servlet controllers (e.g., LoginController, CheckoutServlet, ProductController) that handle incoming HTTP requests and route them appropriately. Also include the admin sub-package and the cart controllers.
- Business Logic / Service Layer: Although there is only one service class (ProductService.java) explicitly visible, it represents where business logic resides. This layer could be expanded as the project evolves.
- Data Access Layer (DAO): All the DAO classes (e.g., CouponDAO, ProductDAO, OrderDao, etc.) and the DB connection class (DBConnect.java) form the persistence component that interacts with the underlying database.
- Domain/Model Layer: The POJOs in the “model” package (e.g., Products, Order, Users, etc.) are used by both service and DAO layers to represent business entities.
- Utility and Configuration Components: Filters (AuthenticationFilter.java, AdminFilter.java, etc.), configuration files (db.properties), and utility classes (PasswordUtils, SessionManager, TokenGenerator) help with authentication, session management, and general configuration.
- External Services and Resources: Although not explicitly described in the README, the project implies integration with payment services (e.g., VNPay endpoints) and external assets like fonts and images.

##### Relationships and Interactions
- From each Controller, illustrate calls to the Service Layer, which handles the business logic.
- The Service Layer then interacts with the DAO classes (Data Access Layer) to perform CRUD operations in the database.
- The DAO layer communicates with the Database using configuration details from the db.properties file (managed by DBConnect.java).
- Additionally, illustrate filters (e.g., AuthenticationFilter, AdminFilter) intercepting requests before they hit the controllers, ensuring security and proper session management.
- Components for static resources (JS, CSS, images, fonts) which are served to the client along with dynamic content from JSP pages.

##### Architectural Patterns and Technologies
- Model-View-Controller (MVC): The separation into JSP (views), Servlets (controllers), and Java model/logic (models, services, DAO) is a clear indication of the MVC pattern.
- Maven is used for build and dependency management (as seen with the pom.xml and Maven wrapper files).
- Java Servlet API is used extensively across controllers and filters.
- The project’s organization into packages (controller, dao, model, service, utils) demonstrates modular design and separation of concerns.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Nodes
    CLIENT["Client Browser"]:::client

    subgraph "Presentation Layer"
        UI["User Interface (JSP, HTML, CSS, JS)"]:::ui
    end

    subgraph "Utility & Config"
        UTIL["Utilities & Filters (AuthenticationFilter, PasswordUtils, etc.)"]:::util
        CONFIG["Configuration (db.properties)"]:::config
    end

    subgraph "Controller Layer"
        CTRL["Servlet Controllers (Login, Checkout, Product, etc.)"]:::controller
    end

    subgraph "Service Layer"
        SERV["Business Logic (ProductService)"]:::service
    end

    subgraph "Data Access Layer"
        DAO["DAO Classes (CouponDAO, ProductDAO, OrderDao, etc.)"]:::dao
        DBCON["DB Connector (DBConnect)"]:::dao
    end

    subgraph "Model Layer"
        MODEL["Domain Models (Products, Order, Users, etc.)"]:::model
    end

    subgraph "External & Database"
        EXT["External Payment (VNPay)"]:::external
        DATABASE["Database"]:::database
        ASSETS["Static Assets (Fonts, Images)"]:::assets
    end

    %% Connections
    CLIENT -->|"HTTP_Request"| UTIL
    UTIL -->|"Intercepts"| CTRL
    CTRL -->|"Delegates_to"| SERV
    SERV -->|"Calls_DAO"| DAO
    DAO -->|"Database_Access"| DBCON
    DBCON -->|"Connects_to"| DATABASE
    CTRL -->|"Forwards_View"| UI
    UI -->|"Loads"| ASSETS
    CTRL -->|"Payment_Call"| EXT
    UI -->|"Renders_Response"| CLIENT

    %% Styles
    classDef client fill:#F4D03F,stroke:#000,stroke-width:1px;
    classDef ui fill:#85C1E9,stroke:#000,stroke-width:1px;
    classDef util fill:#F5B7B1,stroke:#000,stroke-width:1px;
    classDef controller fill:#82E0AA,stroke:#000,stroke-width:1px;
    classDef service fill:#F9E79F,stroke:#000,stroke-width:1px;
    classDef dao fill:#D2B4DE,stroke:#000,stroke-width:1px;
    classDef model fill:#FAD7A0,stroke:#000,stroke-width:1px;
    classDef external fill:#A9DFBF,stroke:#000,stroke-width:1px;
    classDef database fill:#D6EAF8,stroke:#000,stroke-width:1px;
    classDef assets fill:#FDEBD0,stroke:#000,stroke-width:1px;

    %% Click Events
    click UI "https://github.com/tqchuong/thuctapweb/tree/main/src/main/webapp"
    click CTRL "https://github.com/tqchuong/thuctapweb/tree/main/src/main/java/fit/hcmuaf/edu/vn/foodmart/controller"
    click SERV "https://github.com/tqchuong/thuctapweb/blob/main/src/main/java/fit/hcmuaf/edu/vn/foodmart/service/ProductService.java"
    click DAO "https://github.com/tqchuong/thuctapweb/tree/main/src/main/java/fit/hcmuaf/edu/vn/foodmart/dao"
    click DBCON "https://github.com/tqchuong/thuctapweb/blob/main/src/main/java/fit/hcmuaf/edu/vn/foodmart/dao/db/DBConnect.java"
    click MODEL "https://github.com/tqchuong/thuctapweb/tree/main/src/main/java/fit/hcmuaf/edu/vn/foodmart/model"
    click UTIL "https://github.com/tqchuong/thuctapweb/tree/main/src/main/java/fit/hcmuaf/edu/vn/foodmart/utils"
    click CONFIG "https://github.com/tqchuong/thuctapweb/blob/main/src/main/resources/db.properties"
```
