# kyuu-302/ea103g4 architecture

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

- Interactive diagram: https://gitdiagram.com/kyuu-302/ea103g4
- Repository: https://github.com/kyuu-302/ea103g4

## Overview

##### Project Type and Purpose
- This is a full-stack Java EE web application (“Bookshop Project”) built on Apache Tomcat, with JSP/Servlet front-end and back-end, MVC layering, Oracle and Redis as data stores, plus WebSocket chat and scheduled tasks. The purpose is to run an online bookshop with customer shopping, reviews, book clubs, forums, admin panels, promotions, recommendation engine, and real-time features.

##### File Structure Analysis
- WebContent/: all static assets and JSPs, split into front-end/ and back-end/ subfolders for user-facing and admin consoles.
- src/: Java source organized by package:
- com.*.controller – Servlets and WebSocket endpoints
- com.*.service – business logic
- com.*.model/dao – DAO interfaces and implementations (JDBC, JNDI)
- filters/, listeners/, timers/, tools/, util/ – cross-cutting code (auth filters, startup listeners, scheduled tasks, helpers).
- WEB-INF/lib/: third-party JARs (JDBC drivers, Redis/Jedis, JSON, commons-*, WebSocket API).
- Configuration: web.xml for servlet mapping; build/run on Tomcat; Git integration; tests in src/tests.

##### README Insights
- Technologies: Java, JSP, AJAX, jQuery, Bootstrap, WebSocket, CKEditor; Oracle + Redis; Tomcat on GCP.
- Features: product/catalog management, user/account, orders, reviews, book clubs (with real-time chat and notifications), forums, promotions, recommendations, scheduled statistics/promotions.

a. Main Components
- Presentation Layer
– Front-end JSP pages + CSS/JS assets
– Back-end admin JSP pages
- Controller Layer
– Servlets (com.*.controller)
– WebSocket endpoints for chat/notifications
- Service Layer
– Business logic classes (com.*.service)
- Data Access Layer
– DAO interfaces + JDBC/JNDI implementations
- Databases
– Oracle RDBMS (persistent storage)
– Redis cache (session data, pub/sub, temporary data)
- External Services
– SMTP/Gmail for email
– SMS gateway for password recovery
- Infrastructure
– Apache Tomcat on GCP
– Scheduled tasks (PromoTimerTask, StatisticsTimerTask)
b. Relationships & Data Flow
1. Browser → HTTP request → JSP/View (WebContent)
2. JSP invokes a Servlet → Controller processes request
3. Controller calls Service layer → business logic
4. Service calls DAO → interacts with Oracle or Redis
5. DAO returns data → Service → Controller → JSP response
6. WebSocket channels connect browser ↔ server endpoint for real-time chat/notifications
7. Timer tasks triggered by ServletContextListener on server to perform scheduled DB/cache operations
c. Architectural Patterns
- MVC: clear separation of View (JSP), Controller (Servlets), Model/Service
- DAO pattern for data access abstraction (supports JDBC and JNDI lookup)
- Singleton or Factory for JedisUtil (Redis connection pooling)
- Observer/pub-sub via WebSocket and Redis (for real-time notifications)
- Filter chain for authentication/authorization (SignInFilter, BackEndPermissionFilter)
d. Key Technologies & Frameworks
- Java Servlets/JSP, JDBC, JNDI
- Redis (Jedis) for caching, sessions, pub/sub
- WebSocket API for chat/notifications
- jQuery/AJAX, Bootstrap, CKEditor for rich UI
- Oracle database with PL/SQL triggers/stored procedures

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "User Presentation Layer"
        direction TB
        Frontend["Front-end JSP Views"]:::presentation
        AdminViews["Admin JSP Views"]:::presentation
    end

    %% Controller & WebSocket Layer
    subgraph "Controller Layer & Real-Time Endpoints"
        direction TB
        Controllers["Servlet Controllers"]:::controller
        subgraph "WebSocket Endpoints"
            direction TB
            WS1["BookClubServerEcho"]:::controller
            WS2["NoticeWS"]:::controller
            WS3["SubscribeNotifyWs"]:::controller
        end
    end

    %% Service Layer
    subgraph "Service Layer"
        direction TB
        BookService["BookService"]:::service
        OrderService["OrderService"]:::service
    end

    %% DAO Layer
    subgraph "Data Access Layer"
        direction TB
        DAOInterface["DAO Interfaces"]:::dao
        JDBCImpl["JDBC DAO Implementations"]:::dao
        JNDIImpl["JNDI DAO Implementations"]:::dao
    end

    %% Infrastructure Components
    subgraph "Cross-Cutting Components"
        direction TB
        Filters["Auth & Permission Filters"]:::infrastructure
        Listeners["Application Listeners"]:::infrastructure
        Timers["Scheduled Tasks"]:::infrastructure
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        OracleDB["Oracle Database"]:::db
        RedisCache["Redis Cache"]:::db
    end

    %% External Services
    subgraph "External Services"
        direction TB
        SMTP["SMTP/Gmail Email Service"]:::external
        SMS["SMS Gateway"]:::external
    end

    %% Unit Tests
    Tests["Unit Tests"]:::test

    %% Flows
    Frontend -->|HTTP GET/POST| Controllers
    AdminViews -->|HTTP GET/POST| Controllers
    Controllers -->|"invoke business logic"| BookService
    Controllers -->|"invoke business logic"| OrderService
    BookService -->|"calls DAO"| DAOInterface
    OrderService -->|"calls DAO"| DAOInterface
    DAOInterface -->|"JDBC Query"| JDBCImpl
    DAOInterface -->|"JNDI Lookup"| JNDIImpl
    JDBCImpl -->|"SQL"| OracleDB
    JNDIImpl -->|"SQL"| OracleDB
    DAOInterface -->|"Redis SET/GET"| RedisCache

    Frontend -.->|WebSocket Connect| WS1
    Frontend -.->|WebSocket Connect| WS2
    Frontend -.->|WebSocket Connect| WS3
    WS1 -->|pub/sub notifications| RedisCache
    WS2 -->|pub/sub notifications| RedisCache
    WS3 -->|pub/sub notifications| RedisCache

    Timers -.->|scheduled DB/cache ops| JDBCImpl
    Timers -.->|scheduled DB/cache ops| RedisCache

    Controllers -->|send email| SMTP
    Controllers -->|send SMS| SMS

    Listeners -->|initialize app| Controllers
    Filters -->|intercept requests| Controllers

    Tests --> Controllers
    Tests --> BookService
    Tests --> DAOInterface

    %% Click Events
    click Frontend "https://github.com/kyuu-302/ea103g4/tree/master/WebContent/front-end"
    click AdminViews "https://github.com/kyuu-302/ea103g4/tree/master/WebContent/back-end"
    click WS1 "https://github.com/kyuu-302/ea103g4/blob/master/src/com/bookclub/controller/BookClubServerEcho.java"
    click WS2 "https://github.com/kyuu-302/ea103g4/blob/master/src/com/util/NoticeWS.java"
    click WS3 "https://github.com/kyuu-302/ea103g4/blob/master/src/com/util/notifyWs/SubscribeNotifyWs.java"
    click BookService "https://github.com/kyuu-302/ea103g4/blob/master/src/com/book/model/BookService.java"
    click OrderService "https://github.com/kyuu-302/ea103g4/blob/master/src/com/order/model/OrderService.java"
    click DAOInterface "https://github.com/kyuu-302/ea103g4/blob/master/src/com/book/model/BookDAO_interface.java"
    click JDBCImpl "https://github.com/kyuu-302/ea103g4/blob/master/src/com/book/model/BookDAOImpl.java"
    click JNDIImpl "https://github.com/kyuu-302/ea103g4/blob/master/src/com/book/model/BookJNDIDAO.java"
    click Filters "https://github.com/kyuu-302/ea103g4/blob/master/src/filters/SignInFilter.java"
    click Listeners "https://github.com/kyuu-302/ea103g4/blob/master/src/listeners/BookshopInitializer.java"
    click Timers "https://github.com/kyuu-302/ea103g4/blob/master/src/timers/PromoTimerTask.java"
    click SMTP "https://github.com/kyuu-302/ea103g4/blob/master/src/com/util/MailService.java"
    click SMS "https://github.com/kyuu-302/ea103g4/blob/master/src/com/mem/controller/sendSMSForgerPwd.java"
    click Tests "https://github.com/kyuu-302/ea103g4/tree/master/src/tests/"

    %% Styles
    classDef presentation fill:#9f6,stroke:#333,stroke-width:1px
    classDef controller fill:#6bf,stroke:#333,stroke-width:1px
    classDef service fill:#6fb,stroke:#333,stroke-width:1px
    classDef dao fill:#6f6,stroke:#333,stroke-width:1px
    classDef db fill:#fb6,stroke:#333,stroke-width:1px
    classDef external fill:#f66,stroke:#333,stroke-width:1px
    classDef infrastructure fill:#bbb,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
    classDef test fill:#ccc,stroke:#333,stroke-width:1px,stroke-dasharray: 2 2
```
