# quyetdaika/bookstore architecture

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

- Interactive diagram: https://gitdiagram.com/quyetdaika/bookstore
- Repository: https://github.com/quyetdaika/bookstore

## Overview

1. This is a classic Java MVC-style bookstore web application built with Maven, JSP, and Servlets. The repository is split into three main layers: presentation in `src/main/webapp`, request handling in `src/main/java/...Servlet`, and persistence in `src/main/java/bookstore/subsystem`.

2. The presentation layer is JSP-heavy. Pages like `index.jsp`, `login.jsp`, `register.jsp`, `cart.jsp`, `wishlist.jsp`, `checkout.jsp`, `product-detail.jsp`, and `search-results.jsp` render the customer-facing site, while `src/main/webapp/admin/*` contains the admin UI. The `all_component` directory holds reusable JSP fragments such as headers, navbars, footers, sliders, and CSS includes.

3. Controller logic lives in servlet packages organized by feature:
   - `bookstore.user` for authentication (`LoginServlet`, `LogoutServlet`)
   - `bookstore.user.customer` for registration
   - `bookstore.user.admin` for book management
   - `bookstore.cart` for cart actions
   - `bookstore.wishlist` for wishlist actions  
   These servlets are the HTTP entry points and likely forward to JSP views after performing business operations.

4. The domain model is minimal and centered on three entities in `bookstore.entities`: `Book`, `CartItem`, and `User`. These represent the key business objects passed between servlets, DAOs, and JSPs.

5. Persistence is abstracted through DAO interfaces in `bookstore.subsystem.iface`: `IBookDAO`, `ICartDAO`, `IUserDAO`, `IWishlistDAO`, plus `IDBConnector`. This creates a clear boundary between the web tier and storage implementation, making the data-access layer swappable.

6. The concrete database implementation is in `bookstore.subsystem.mysqlsubsystem`. `MySQLConnector` handles database connectivity, and the MySQL DAO classes (`MySQLBookDAO`, `MySQLCartDAO`, `MySQLUserDAO`, `MySQLWishlistDAO`) implement the interface contracts. The architecture is therefore database-backed, with MySQL as the operational datastore.

7. The main request/data flow is: browser request → servlet controller → DAO → MySQL database → servlet → JSP response. Cart and wishlist operations are broken into discrete actions such as add, remove, update, and bulk transfer between wishlist and cart, which suggests the application relies on session/user context plus database state.

8. Feature boundaries are clear:
   - Authentication and account creation are handled separately from shopping actions.
   - Cart and wishlist have their own servlet sets and DAO support.
   - Admin book management is isolated under the `admin` package and admin JSPs.
   This separation should be reflected as distinct subsystems in an architecture diagram.

9. The admin area has its own UI and flows. `AddBookServlet` and `ViewBookServlet` map to admin pages like `add_book.jsp` and `all_books.jsp`, indicating a management path for catalog maintenance separate from customer shopping paths.

10. `src/main/resources/META-INF/persistence.xml` and `src/main/webapp/WEB-INF/web.xml` are the key deployment/configuration files. `web.xml` defines servlet/webapp routing and startup behavior, while `persistence.xml` indicates the app also carries JPA-style persistence configuration, even though the visible implementation is DAO/MySQL-oriented.

11. The application is packaged as a standard Java web archive and runs on a servlet container rather than as a standalone server. `mvnw`, `pom.xml`, and the Maven wrapper indicate Maven manages build, dependencies, and test execution.

12. For diagramming, the important external boundary is the MySQL database. The other major boundary is the HTTP browser/client, which talks only to JSP-rendered pages and servlet endpoints; all business operations are server-side.

13. `src/test/java/Test.java` and `src/main/java/TestServlet.java` appear to be supporting/demo artifacts rather than core architecture. The core system is the bookstore flow around users, catalog, cart, and wishlist, with JSP/Servlet presentation and DAO-based persistence underneath.

Main entry points: [`src/main/webapp`](https://github.com/quyetdaika/bookstore/tree/main/src/main/webapp) (Storefront), [`src/main/java/bookstore/subsystem/iface`](https://github.com/quyetdaika/bookstore/tree/main/src/main/java/bookstore/subsystem/iface) (DAO API), [`src/main/java/bookstore/user`](https://github.com/quyetdaika/bookstore/tree/main/src/main/java/bookstore/user) (Auth), [`src/main/java/bookstore/user/admin`](https://github.com/quyetdaika/bookstore/tree/main/src/main/java/bookstore/user/admin) (Catalog Admin)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_presentation["Presentation"]
  node_shared_jsp["Shared JSPs<br/>jsp-fragments"]
  node_customer_views["Storefront<br/>jsp-pages"]
  node_admin_views["Admin UI<br/>jsp-pages"]
end

subgraph group_controllers["Controllers"]
  node_login_servlet["Auth<br/>servlet"]
  node_register_servlet["Register<br/>servlet"]
  node_admin_servlet["Catalog Admin<br/>servlet"]
  node_cart_servlet["Cart<br/>servlet"]
  node_wishlist_servlet["Wishlist<br/>servlet"]
end

subgraph group_domain["Domain"]
  node_book_entity["Book<br/>entity<br/>[Book.java]"]
  node_cart_item_entity["CartItem<br/>entity<br/>[CartItem.java]"]
  node_user_entity["User<br/>entity<br/>[User.java]"]
end

subgraph group_persistence["Persistence"]
  node_dao_iface["DAO API<br/>interfaces"]
  node_mysql_connector[("MySQL Connector<br/>db-connector")]
  node_mysql_daos[("MySQL DAOs<br/>dao-impls")]
end

subgraph group_config["Config"]
  node_web_xml["web.xml<br/>deployment descriptor<br/>[web.xml]"]
  node_persistence_xml["persistence.xml<br/>persistence config<br/>[persistence.xml]"]
  node_maven_build{{"Maven Build<br/>[pom.xml]"}}
end

node_browser(("Browser<br/>client"))
node_mysql_db[("MySQL DB<br/>database")]

node_browser -->|"browse"| node_customer_views
node_browser -->|"admin"| node_admin_views
node_customer_views -.->|"includes"| node_shared_jsp
node_admin_views -.->|"includes"| node_shared_jsp
node_customer_views -->|"submit"| node_login_servlet
node_customer_views -->|"submit"| node_register_servlet
node_customer_views -->|"actions"| node_cart_servlet
node_customer_views -->|"actions"| node_wishlist_servlet
node_admin_views -->|"actions"| node_admin_servlet
node_login_servlet -->|"uses"| node_dao_iface
node_register_servlet -->|"uses"| node_dao_iface
node_admin_servlet -->|"uses"| node_dao_iface
node_cart_servlet -->|"uses"| node_dao_iface
node_wishlist_servlet -->|"uses"| node_dao_iface
node_dao_iface -->|"implemented by"| node_mysql_daos
node_mysql_daos -->|"connects via"| node_mysql_connector
node_mysql_connector -->|"reads/writes"| node_mysql_db
node_login_servlet -.->|"maps"| node_user_entity
node_register_servlet -.->|"creates"| node_user_entity
node_admin_servlet -.->|"manages"| node_book_entity
node_cart_servlet -.->|"manages"| node_cart_item_entity
node_wishlist_servlet -.->|"tracks"| node_book_entity
node_web_xml -.->|"routes"| node_login_servlet
node_web_xml -.->|"routes"| node_admin_servlet
node_persistence_xml -.->|"configures"| node_mysql_connector
node_maven_build -.->|"packages"| node_web_xml
node_maven_build -.->|"packages"| node_persistence_xml

click node_shared_jsp "https://github.com/quyetdaika/bookstore/tree/main/src/main/webapp/all_component"
click node_customer_views "https://github.com/quyetdaika/bookstore/tree/main/src/main/webapp"
click node_admin_views "https://github.com/quyetdaika/bookstore/tree/main/src/main/webapp/admin"
click node_login_servlet "https://github.com/quyetdaika/bookstore/tree/main/src/main/java/bookstore/user"
click node_register_servlet "https://github.com/quyetdaika/bookstore/tree/main/src/main/java/bookstore/user/customer"
click node_admin_servlet "https://github.com/quyetdaika/bookstore/tree/main/src/main/java/bookstore/user/admin"
click node_cart_servlet "https://github.com/quyetdaika/bookstore/tree/main/src/main/java/bookstore/cart"
click node_wishlist_servlet "https://github.com/quyetdaika/bookstore/tree/main/src/main/java/bookstore/wishlist"
click node_book_entity "https://github.com/quyetdaika/bookstore/blob/main/src/main/java/bookstore/entities/Book.java"
click node_cart_item_entity "https://github.com/quyetdaika/bookstore/blob/main/src/main/java/bookstore/entities/CartItem.java"
click node_user_entity "https://github.com/quyetdaika/bookstore/blob/main/src/main/java/bookstore/entities/User.java"
click node_dao_iface "https://github.com/quyetdaika/bookstore/tree/main/src/main/java/bookstore/subsystem/iface"
click node_mysql_connector "https://github.com/quyetdaika/bookstore/blob/main/src/main/java/bookstore/subsystem/mysqlsubsystem/MySQLConnector.java"
click node_mysql_daos "https://github.com/quyetdaika/bookstore/tree/main/src/main/java/bookstore/subsystem/mysqlsubsystem"
click node_web_xml "https://github.com/quyetdaika/bookstore/blob/main/src/main/webapp/WEB-INF/web.xml"
click node_persistence_xml "https://github.com/quyetdaika/bookstore/blob/main/src/main/resources/META-INF/persistence.xml"
click node_maven_build "https://github.com/quyetdaika/bookstore/blob/main/pom.xml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_shared_jsp,node_customer_views,node_admin_views toneBlue
class node_login_servlet,node_register_servlet,node_admin_servlet,node_cart_servlet,node_wishlist_servlet toneAmber
class node_book_entity,node_cart_item_entity,node_user_entity toneMint
class node_dao_iface,node_mysql_connector,node_mysql_daos toneRose
class node_web_xml,node_persistence_xml,node_maven_build toneIndigo
class node_browser,node_mysql_db toneNeutral
```

## Components

### Presentation

Customer and admin JSP views

- [Shared JSPs](https://github.com/quyetdaika/bookstore/tree/main/src/main/webapp/all_component): jsp-fragments · Reusable headers, navbars, footers, and UI components · `src/main/webapp/all_component`
- [Storefront](https://github.com/quyetdaika/bookstore/tree/main/src/main/webapp): jsp-pages · Customer-facing pages for browsing, login, cart, wishlist, checkout, and search · `src/main/webapp`
- [Admin UI](https://github.com/quyetdaika/bookstore/tree/main/src/main/webapp/admin): jsp-pages · Admin pages for catalog management · `src/main/webapp/admin`

### Controllers

Servlet entry points

- [Auth](https://github.com/quyetdaika/bookstore/tree/main/src/main/java/bookstore/user): servlet · Login and logout request handling · `src/main/java/bookstore/user`
- [Register](https://github.com/quyetdaika/bookstore/tree/main/src/main/java/bookstore/user/customer): servlet · Customer account creation · `src/main/java/bookstore/user/customer`
- [Catalog Admin](https://github.com/quyetdaika/bookstore/tree/main/src/main/java/bookstore/user/admin): servlet · Admin book add and listing flows · `src/main/java/bookstore/user/admin`
- [Cart](https://github.com/quyetdaika/bookstore/tree/main/src/main/java/bookstore/cart): servlet · Add, remove, and update cart actions · `src/main/java/bookstore/cart`
- [Wishlist](https://github.com/quyetdaika/bookstore/tree/main/src/main/java/bookstore/wishlist): servlet · Wishlist add/remove and transfer-to-cart actions · `src/main/java/bookstore/wishlist`

### Domain

Core business entities

- [Book](https://github.com/quyetdaika/bookstore/blob/main/src/main/java/bookstore/entities/Book.java): entity · Catalog item model · `src/main/java/bookstore/entities/Book.java`
- [CartItem](https://github.com/quyetdaika/bookstore/blob/main/src/main/java/bookstore/entities/CartItem.java): entity · Shopping cart line item model · `src/main/java/bookstore/entities/CartItem.java`
- [User](https://github.com/quyetdaika/bookstore/blob/main/src/main/java/bookstore/entities/User.java): entity · Account and identity model · `src/main/java/bookstore/entities/User.java`

### Persistence

DAO interfaces and MySQL implementations

- [DAO API](https://github.com/quyetdaika/bookstore/tree/main/src/main/java/bookstore/subsystem/iface): interfaces · Storage contracts for books, carts, users, wishlist, and DB connections · `src/main/java/bookstore/subsystem/iface`
- [MySQL Connector](https://github.com/quyetdaika/bookstore/blob/main/src/main/java/bookstore/subsystem/mysqlsubsystem/MySQLConnector.java): db-connector · Creates and manages database connectivity · `src/main/java/bookstore/subsystem/mysqlsubsystem/MySQLConnector.java`
- [MySQL DAOs](https://github.com/quyetdaika/bookstore/tree/main/src/main/java/bookstore/subsystem/mysqlsubsystem): dao-impls · Concrete MySQL implementations for book, cart, user, and wishlist persistence · `src/main/java/bookstore/subsystem/mysqlsubsystem`

### Config

Build and deployment configuration

- [web.xml](https://github.com/quyetdaika/bookstore/blob/main/src/main/webapp/WEB-INF/web.xml): deployment descriptor · Servlet routing and webapp configuration · `src/main/webapp/WEB-INF/web.xml`
- [persistence.xml](https://github.com/quyetdaika/bookstore/blob/main/src/main/resources/META-INF/persistence.xml): persistence config · JPA-style persistence configuration · `src/main/resources/META-INF/persistence.xml`
- [Maven Build](https://github.com/quyetdaika/bookstore/blob/main/pom.xml): build · Project build and dependency management · `pom.xml`

### Other components

- **Browser**: client · HTTP client using rendered JSP pages
- **MySQL DB**: database · Operational datastore

## Connections

- Browser → Storefront: browse · Users load storefront pages
- Browser → Admin UI: admin · Admins use management pages
- Storefront → Shared JSPs: includes · Storefront pages reuse common components
- Admin UI → Shared JSPs: includes · Admin pages reuse shared UI pieces
- Storefront → Auth: submit · Login and account actions post to servlets
- Storefront → Register: submit · Registration posts to servlet
- Storefront → Cart: actions · Cart operations originate from storefront views
- Storefront → Wishlist: actions · Wishlist operations originate from storefront views
- Admin UI → Catalog Admin: actions · Admin catalog actions post to servlet controllers
- Auth → DAO API: uses · Auth controllers read/write through DAO contracts
- Register → DAO API: uses · Registration relies on user persistence contract
- Catalog Admin → DAO API: uses · Admin catalog flows use book DAO contract
- Cart → DAO API: uses · Cart flows use cart DAO contract
- Wishlist → DAO API: uses · Wishlist flows use wishlist DAO contract
- DAO API → MySQL DAOs: implemented by · MySQL classes realize the DAO interfaces
- MySQL DAOs → MySQL Connector: connects via · DAO implementations acquire database connections
- MySQL Connector → MySQL DB: reads/writes · Connector talks to the MySQL datastore
- Auth → User: maps · Authentication uses user model
- Register → User: creates · Registration creates user records
- Catalog Admin → Book: manages · Catalog management centers on books
- Cart → CartItem: manages · Cart actions operate on cart items
- Wishlist → Book: tracks · Wishlist stores books for later purchase
- web.xml → Auth: routes · Deployment descriptor maps servlet endpoints
- web.xml → Catalog Admin: routes · Deployment descriptor maps admin endpoints
- persistence.xml → MySQL Connector: configures · Persistence settings accompany database access
- Maven Build → web.xml: packages · Build assembles the web archive
- Maven Build → persistence.xml: packages · Build includes persistence configuration
