# ronalhung05/bookstorewebsite-jsp-servlet-java architecture

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

- Interactive diagram: https://gitdiagram.com/ronalhung05/bookstorewebsite-jsp-servlet-java
- Repository: https://github.com/ronalhung05/bookstorewebsite-jsp-servlet-java

## Overview

##### Project Type and Purpose
- This is a Java-based web application built using pure JSP and Servlets. The README confirms it’s a “Website bán sách” (book selling website) with detailed documentation and tests.
- The application is structured following a typical MVC architecture where presentation is handled by JSPs, control flows via Servlet-based controllers, and business logic resides in services and DAOs.

##### Analyzing the File Structure
- Top-Level Directories and Files:
– WebContent: Contains web assets, configuration (web.xml), JSP pages, CSS, JavaScript, images, and various external libraries.
– src: Contains the backend Java code organized into packages for controllers (both admin and frontend), services, DAOs, and entities.
– Resources and configuration files like pom.xml (indicating Maven usage), hibernate.cfg.xml, and persistence.xml suggest the integration of Hibernate (or JPA) as the persistence layer.
- The structure shows a clear separation between the admin area (located under WebContent/admin and corresponding backend controllers in src/com/bookstore/controller/admin) and the frontend area (located under WebContent/frontend and corresponding src controllers).

##### Main Components
a. Client Layer:
– End-User web browsers accessing the system.
– Separate paths for administrative users (admin interface) and regular customers (frontend interface).

b. Web Server / Application Server:
– A container (such as Apache Tomcat) serving the application.
– Handles HTTP requests forwarded to the appropriate servlets.

c. Controller Layer (Servlets):
– Admin Controllers: Manage operations such as managing books, categories, orders, customers, reviews, and users.
– Frontend Controllers: Handle homepage, book browsing, shopping cart functionalities, checkout processes, customer login/registration, and review submissions.
– Include filters (e.g., AdminLoginFilter, CustomerLoginFilter, CommonFilter) for authentication and request preprocessing.

d. Service Layer:
– Contains business logic classes (e.g., BookServices, CategoryServices, CustomerServices, PaymentServices, etc.) that process data before interacting with the database.
– Acts as an intermediary between controllers and the data access layer.

e. Data Access Layer:
– DAO classes (e.g., BookDAO, CategoryDAO, CustomerDAO, etc.) responsible for CRUD operations.
– Entity classes (e.g., Book, Category, Customer, OrderDetail, etc.) that model the persistent data.
– Hibernate configuration files (hibernate.cfg.xml and hibernate.reveng.xml) and JPA setup (persistence.xml), reflecting ORM usage.

f. Presentation Layer:
– JSP Pages segmented into admin and frontend directories.
– Common components shared across pages (header, footer, message components).

g. External Libraries & Assets:
– Libraries for UI components (Bootstrap, jQuery, Slick Carousel, etc.) and other utilities (charting libraries, inputmask, etc.).
– These resources are managed and deployed from the WebContent/libs directory.

##### Architectural Patterns and Design Principles
- MVC Pattern: The design clearly splits concerns into views (JSPs), controllers (Servlets), and model (services/DAO/entities).
- Layered Architecture: The separation into presentation, controller, service, and persistence layers should be clearly depicted.
- Use of Filters: Authentication and common request processing are applied via servlet filters.
- Maven-Based Build: The project uses Maven for dependency management and build processes.

##### Summary

This approach should provide a comprehensive depiction of the system, reflecting its multi-tiered design and ensuring that all essential architectural elements are captured clearly.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        Cust["Customer Browser"]:::client
        Adm["Admin Browser"]:::client
    end

    %% Application Server
    Server["Web Server (Tomcat)"]:::server

    Cust -->|"HTTP_Request"| Server
    Adm -->|"HTTP_Request"| Server

    %% Presentation Layer
    subgraph "Presentation Layer"
        PS["Presentation Aggregator"]:::presentation
        PS1["Admin JSPs"]:::presentation
        PS2["Frontend JSPs"]:::presentation
        PS3["Common JSP Components"]:::presentation
        PS4["CSS"]:::presentation
        PS5["JS"]:::presentation
        PS6["Images"]:::presentation
        PS7["Libraries"]:::presentation
        PS --> PS1
        PS --> PS2
        PS --> PS3
        PS --> PS4
        PS --> PS5
        PS --> PS6
        PS --> PS7
    end

    %% Controller Layer
    subgraph "Controller Layer"
        CT["Controllers Aggregator"]:::controller
        AC["Admin Controllers"]:::controller
        FC["Frontend Controllers"]:::controller
        ALF["AdminLoginFilter"]:::controller
        CF["CommonFilter"]:::controller
        CLF["CustomerLoginFilter"]:::controller
        CT --> AC
        CT --> FC
        CT --> ALF
        CT --> CF
        CT --> CLF
    end

    %% Service Layer
    subgraph "Service Layer"
        SVC["Business Services"]:::service
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        DAO["DAOs"]:::dao
        ENT["Entities"]:::dao
        ORM1["Hibernate Config"]:::dao
        ORM2["Hibernate Reveng"]:::dao
        ORM3["JPA Persistence"]:::dao
        DAO --> ENT
        ENT --> ORM1
        ORM1 --> ORM2
        ORM2 --> ORM3
    end

    DB["Database"]:::db

    %% Main Flow Connections
    Server -->|"Delegate_Request"| CT
    CT -->|"Invoke_Business"| SVC
    SVC -->|"CRUD_Operations"| DAO
    DAO -->|"Database_Query"| DB
    CT -->|"Render_View"| PS
    PS -->|"HTTP_Response"| Cust
    PS -->|"HTTP_Response"| Adm

    %% Click Events for Client Layer
    click Cust "https://github.com/ronalhung05/bookstorewebsite-jsp-servlet-java/tree/hung/WebContent/frontend"
    click Adm "https://github.com/ronalhung05/bookstorewebsite-jsp-servlet-java/tree/hung/WebContent/admin"

    %% Click Events for Presentation Layer
    click PS1 "https://github.com/ronalhung05/bookstorewebsite-jsp-servlet-java/blob/hung/WebContent/admin/*.jsp"
    click PS2 "https://github.com/ronalhung05/bookstorewebsite-jsp-servlet-java/blob/hung/WebContent/frontend/*.jsp"
    click PS3 "https://github.com/ronalhung05/bookstorewebsite-jsp-servlet-java/tree/hung/WebContent/common"
    click PS4 "https://github.com/ronalhung05/bookstorewebsite-jsp-servlet-java/tree/hung/WebContent/css"
    click PS5 "https://github.com/ronalhung05/bookstorewebsite-jsp-servlet-java/tree/hung/WebContent/js"
    click PS6 "https://github.com/ronalhung05/bookstorewebsite-jsp-servlet-java/tree/hung/WebContent/images"
    click PS7 "https://github.com/ronalhung05/bookstorewebsite-jsp-servlet-java/tree/hung/WebContent/libs"

    %% Click Events for Controller Layer
    click AC "https://github.com/ronalhung05/bookstorewebsite-jsp-servlet-java/tree/hung/src/com/bookstore/controller/admin"
    click FC "https://github.com/ronalhung05/bookstorewebsite-jsp-servlet-java/tree/hung/src/com/bookstore/controller/frontend"
    click ALF "https://github.com/ronalhung05/bookstorewebsite-jsp-servlet-java/blob/hung/src/com/bookstore/controller/admin/AdminLoginFilter.java"
    click CF "https://github.com/ronalhung05/bookstorewebsite-jsp-servlet-java/blob/hung/src/com/bookstore/controller/frontend/CommonFilter.java"
    click CLF "https://github.com/ronalhung05/bookstorewebsite-jsp-servlet-java/blob/hung/src/com/bookstore/controller/frontend/CustomerLoginFilter.java"

    %% Click Event for Service Layer
    click SVC "https://github.com/ronalhung05/bookstorewebsite-jsp-servlet-java/tree/hung/src/com/bookstore/service"

    %% Click Events for Data Access Layer
    click DAO "https://github.com/ronalhung05/bookstorewebsite-jsp-servlet-java/tree/hung/src/com/bookstore/dao"
    click ENT "https://github.com/ronalhung05/bookstorewebsite-jsp-servlet-java/tree/hung/src/com/bookstore/entity"
    click ORM1 "https://github.com/ronalhung05/bookstorewebsite-jsp-servlet-java/blob/hung/src/hibernate.cfg.xml"
    click ORM2 "https://github.com/ronalhung05/bookstorewebsite-jsp-servlet-java/blob/hung/src/hibernate.reveng.xml"
    click ORM3 "https://github.com/ronalhung05/bookstorewebsite-jsp-servlet-java/blob/hung/resources/META-INF/persistence.xml"

    %% Styles
    classDef client fill:#bbf,stroke:#333,stroke-width:2px;
    classDef server fill:#aff,stroke:#333,stroke-width:2px;
    classDef presentation fill:#f9f,stroke:#333,stroke-width:2px;
    classDef controller fill:#ff9,stroke:#333,stroke-width:2px;
    classDef service fill:#9f9,stroke:#333,stroke-width:2px;
    classDef dao fill:#f99,stroke:#333,stroke-width:2px;
    classDef db fill:#fcc,stroke:#333,stroke-width:2px;
```
