# ntramanh1204/bookstore-web architecture

> Architecture diagram of the GitHub repository ntramanh1204/bookstore-web, 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/ntramanh1204/bookstore-web
- Repository: https://github.com/ntramanh1204/bookstore-web

## Overview

##### Main Components
- Client/Browser: Users interact via web browsers, viewing JSP pages (in the “web” directory) that include HTML, CSS, and JavaScript.
- Web Server/Servlet Container: The application is deployed on Apache Tomcat. The server processes HTTP requests and serves the JSP pages.
- Controller Layer: All the Servlet files under “src/java/controller” manage incoming HTTP requests and coordinate responses. There are also filters (in “src/java/filter”) for cross-cutting concerns like login and home redirection.
- Business Logic/Model Layer: The packages under “src/java/model” (and some classes under “abundant”) represent the data models such as Account, Cart, Order, etc.
- Data Access Layer (DAL): Classes in “src/java/dal” (e.g., AccountDAO, CartDAO, OrderDAO) are responsible for interacting with the Microsoft SQL Server database. The database schema and data are set up using the provided BookDatabase.sql script.
- External Components: There is also supporting functionality like Selenium-based data crawling (via the Jupyter notebook in “scripts/crawl-best-books-final.ipynb”) that was used to populate the database, and static resources (images, CSS, JS) are located under “web” for both user and admin interfaces.
- Build & Deployment: Build scripts (Ant’s build.xml and nbproject files) are used for compiling and deploying the application. The “dist” folder generates both a .jar and a .war, indicating multiple deployment options.

##### Relationships and Interactions
- Clients send HTTP requests to the Tomcat server.
- The server forwards these requests to the appropriate Servlet controllers.
- Controllers (e.g., HomeServlet, LoginServlet, CartServlet) process the requests, invoke corresponding methods in the Business/Model layer, and may interact with the DAL to perform CRUD operations on the SQL Server.
- After processing, the controllers dispatch the responses (via JSP views) that are rendered back on the client side.
- Filters intercept requests to enforce session management or route unrecognized URLs to a “NotFound” page.
- The build and deployment process (via Ant and the project’s nbproject configuration) packages the application for Tomcat deployment.

##### Architectural Patterns and Technologies
- MVC Pattern: The clear separation between JSP views, Servlets controllers, and model/DAO classes suggests an MVC pattern.
- Layered Architecture: Front-end (views), controller/servlets, business logic, and data access layers are well-defined.
- Technologies: Java, Servlets, JSP, Bootstrap 5, and SQL Server (using sqljdbc42.jar), with build and deployment managed via Apache Ant and NetBeans project configuration.

##### Final Elements
- Clear and descriptive labels for every component/block (e.g., “Client Browser”, “Apache Tomcat”, “Controllers (Servlets)”, “Business Model/DAO”, “SQL Server Database”).
- Optionally, include notes on external tools for data crawling (linking the Selenium/Jupyter Notebook component to initial database population).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Top Level
    A["Client/Browsers"]:::client
    A -->|"HTTPRequest"| B["Apache Tomcat"]:::server

    %% Build & Deployment section
    BD["Build & Deployment"]:::build
    BD -->|"Deploys to"| B

    %% Internal Components within Apache Tomcat
    subgraph "Servlet Container Components"
        direction TB
        F["Filters"]:::filter
        C["Controllers (Servlets)"]:::controller
        V["JSP/HTML/CSS/JS Views"]:::view
        M["Business Logic/Model"]:::model
        D["Data Access Layer (DAL)"]:::dal
    end

    %% Internal Data Flow inside Tomcat
    B --> F
    F -->|"Intercepts"| C
    C -->|"Invokes"| M
    M -->|"Queries/Updates"| D
    D -->|"DB Ops"| DB["SQL Server Database"]:::database
    M -->|"Renders"| V
    V -->|"HTTPResponse"| A

    %% External Data Crawling component feeding Database
    EX["External Data Crawling\n(Selenium/Jupyter Notebook)"]:::external
    EX -->|"Populates"| DB

    %% Database Setup Script Note (attached to database)
    DB ---|"Setup via"| Setup["Database Setup Script"]:::script

    %% Styles for clarity
    classDef client fill:#C6E2FF,stroke:#036,stroke-width:2px;
    classDef server fill:#FFE4B5,stroke:#A0522D,stroke-width:2px;
    classDef controller fill:#FFD700,stroke:#DAA520,stroke-width:2px;
    classDef filter fill:#FFA07A,stroke:#CD5C5C,stroke-width:2px;
    classDef view fill:#98FB98,stroke:#2E8B57,stroke-width:2px;
    classDef model fill:#DDA0DD,stroke:#9932CC,stroke-width:2px;
    classDef dal fill:#F08080,stroke:#B22222,stroke-width:2px;
    classDef database fill:#FFFACD,stroke:#DAA520,stroke-width:2px,stroke-dasharray: 5 5;
    classDef external fill:#E6E6FA,stroke:#8A2BE2,stroke-width:2px;
    classDef build fill:#F5DEB3,stroke:#DEB887,stroke-width:2px;
    classDef script fill:#E0FFFF,stroke:#20B2AA,stroke-width:2px,stroke-dasharray: 3 3;

    %% Click Events
    click A "https://github.com/ntramanh1204/bookstore-web/tree/main/Bookabook/web"
    click B "https://github.com/ntramanh1204/bookstore-web/blob/main/Bookabook/web/WEB-INF/web.xml"
    click B "https://github.com/ntramanh1204/bookstore-web/blob/main/Bookabook/dist/Bookabook.war"
    click C "https://github.com/ntramanh1204/bookstore-web/tree/main/Bookabook/src/java/controller"
    click F "https://github.com/ntramanh1204/bookstore-web/tree/main/Bookabook/src/java/filter"
    click V "https://github.com/ntramanh1204/bookstore-web/tree/main/Bookabook/web"
    click M "https://github.com/ntramanh1204/bookstore-web/tree/main/Bookabook/src/java/model"
    click M "https://github.com/ntramanh1204/bookstore-web/tree/main/Bookabook/src/java/abundant"
    click D "https://github.com/ntramanh1204/bookstore-web/tree/main/Bookabook/src/java/dal"
    click EX "https://github.com/ntramanh1204/bookstore-web/blob/main/scripts/crawl-best-books-final.ipynb"
    click BD "https://github.com/ntramanh1204/bookstore-web/blob/main/Bookabook/build.xml"
    click BD "https://github.com/ntramanh1204/bookstore-web/tree/main/Bookabook/nbproject"
    click Setup "https://github.com/ntramanh1204/bookstore-web/blob/main/BookDatabase.sql"
```
