# hnthangit/thesis-backend-java architecture

> Architecture diagram of the GitHub repository hnthangit/thesis-backend-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/hnthangit/thesis-backend-java
- Repository: https://github.com/hnthangit/thesis-backend-java

## Overview

##### Main Components
- Web Layer (Presentation):
– Controllers: Located in the com.shopping.controller package (e.g., CategoryController, IndexController).
– Views: JSP files found under src/main/webapp/WEB-INF/views (e.g., index.jsp), and static resources (CSS files) under src/main/resources/static.

- Service Layer:
– Interfaces and implementations (e.g., ICategoryService and its implementation in com.shopping.service.impl) which provide business logic.

- Persistence Layer:
– DAO interfaces and their implementations (e.g., ICategoryDAO, GenericDAO, and CategoryDAOImpl).
– Spring Data Repositories (e.g., CategoryRepository, OrderRepository) encapsulating database operations.
– Entity classes (e.g., Category, Product, Order, etc.) representing the domain model.

- Configuration and Infrastructure:
– Spring configuration classes such as JPAConfig.java, WebMvcConfig.java, and WebApplicationInitializer.java, which are responsible for bootstrapping the application, setting up the web application context, and configuring JPA.
– External configuration files such as pom.xml (for Maven dependencies and build configuration), data-jpa.properties (for database connection properties), web.xml (for web deployment configuration), and log4j.properties (for logging).

##### Relationships and Interactions
- A client (browser) makes an HTTP request that is routed through the web container (configured via web.xml and WebApplicationInitializer).
- The request is handled by one of the Controllers (e.g., IndexController), which then calls services from the Service Layer.
- The Service Layer (e.g., CategoryServiceImpl) implements business logic and delegates database operations to the Persistence Layer.
- The Persistence Layer interacts with a relational database through DAOs or Spring Data Repositories that use entities mapped to database tables.
- Responses are prepared (likely as JSP views) and sent back to the client.

##### Architectural Patterns and Design Principles
- Model-View-Controller (MVC): The separation between the presentation (JSP views and controllers), business logic (services), and data access (DAOs/Repositories).
- Data Access Object (DAO) Pattern: Abstracting and encapsulating all access to the data source with separate DAO interfaces and implementations.
- Dependency Injection: Likely facilitated by Spring’s configuration classes, which manage dependencies between controllers, services, and repos.
- Layered Architecture: Separation of concerns into distinct layers (Presentation, Service, Persistence, and Configuration).

##### Relevant Technologies and Frameworks
- Java and Maven (indicated by pom.xml) as the main programming language and build tool.
- Spring Framework (Spring MVC for web, Spring Data or standard JPA) for dependency injection, web configuration, and persistence.
- JSP and standard Java web technologies for view rendering.
- Log4j for logging.
- A relational database (implied by JPA configuration and properties file) for persistent storage.

##### Additional Detail and Precision
- Do not overly simplify: aim to decompose the system into as many meaningful components as possible, ensuring clarity on how data flows through the system.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global client
    ClientBrowser("Client (Browser)"):::client

    %% Web Layer
    subgraph "Web Layer"
        IndexController("IndexController"):::controller
        CategoryController("CategoryController"):::controller
        JSPViews("JSP Views"):::view
        StaticCSS("Static CSS"):::view
    end

    %% Service Layer
    subgraph "Service Layer"
        ICategoryService("ICategoryService"):::service
        CategoryServiceImpl("CategoryServiceImpl"):::service
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        subgraph "DAO"
            ICategoryDAO("ICategoryDAO"):::dao
            CategoryDAOImpl("CategoryDAOImpl"):::dao
        end
        subgraph "Repository"
            CategoryRepository("CategoryRepository"):::repository
            OrderRepository("OrderRepository"):::repository
        end
        subgraph "Entities"
            CategoryEntity("Category"):::entity
            ProductEntity("Product"):::entity
            OrderEntity("Order"):::entity
        end
    end

    %% Configuration & Infrastructure
    subgraph "Configuration & Infrastructure"
        JPAConfig("JPAConfig"):::config
        WebApplicationInitializer("WebApplicationInitializer"):::config
        WebMvcConfig("WebMvcConfig"):::config
        POM("pom.xml"):::config
        DataJPA("data-jpa.properties"):::config
        Log4j("log4j.properties"):::config
        WebXML("web.xml"):::config
    end

    %% Database
    Database("Relational Database"):::database

    %% Connections between Client and Web Layer
    ClientBrowser -->|"HTTP request"| IndexController
    ClientBrowser -->|"HTTP request"| CategoryController

    %% Connections within Web -> Service
    IndexController -->|"calls"| CategoryServiceImpl
    CategoryController -->|"calls"| CategoryServiceImpl

    %% Connections within Service -> Persistence (DAO and Repository)
    CategoryServiceImpl -->|"uses"| ICategoryDAO
    CategoryServiceImpl -->|"calls"| CategoryRepository

    %% DAO relationship
    ICategoryDAO -->|"implementedBy"| CategoryDAOImpl

    %% Persistence to Database
    CategoryDAOImpl -->|"accesses"| Database
    CategoryRepository -->|"accesses"| Database
    OrderRepository -->|"accesses"| Database

    %% Configuration relations to layers
    WebApplicationInitializer -->|"bootstraps"| IndexController
    WebApplicationInitializer -->|"bootstraps"| CategoryController
    JPAConfig -->|"configures"| ICategoryDAO
    JPAConfig -->|"configures"| CategoryRepository
    WebMvcConfig -->|"configures"| IndexController
    WebMvcConfig -->|"configures"| CategoryController
    WebXML -->|"defines-view"| JSPViews
    WebXML -->|"defines-view"| StaticCSS

    %% Click Events for Web Layer - Controllers and Views
    click IndexController "https://github.com/hnthangit/thesis-backend-java/blob/master/src/main/java/com/shopping/controller/IndexController.java"
    click CategoryController "https://github.com/hnthangit/thesis-backend-java/blob/master/src/main/java/com/shopping/controller/CategoryController.java"
    click JSPViews "https://github.com/hnthangit/thesis-backend-java/tree/master/src/main/webapp/WEB-INF/views"
    click StaticCSS "https://github.com/hnthangit/thesis-backend-java/tree/master/src/main/resources/static/css"

    %% Click Events for Service Layer
    click ICategoryService "https://github.com/hnthangit/thesis-backend-java/blob/master/src/main/java/com/shopping/service/ICategoryService.java"
    click CategoryServiceImpl "https://github.com/hnthangit/thesis-backend-java/blob/master/src/main/java/com/shopping/service/impl/CategoryServiceImpl.java"

    %% Click Events for Persistence Layer - DAO
    click ICategoryDAO "https://github.com/hnthangit/thesis-backend-java/blob/master/src/main/java/com/shopping/dao/ICategoryDAO.java"
    click CategoryDAOImpl "https://github.com/hnthangit/thesis-backend-java/blob/master/src/main/java/com/shopping/dao/impl/CategoryDAOImpl.java"

    %% Click Events for Persistence Layer - Repository
    click CategoryRepository "https://github.com/hnthangit/thesis-backend-java/blob/master/src/main/java/com/shopping/repository/CategoryRepository.java"
    click OrderRepository "https://github.com/hnthangit/thesis-backend-java/blob/master/src/main/java/com/shopping/repository/OrderRepository.java"

    %% Click Events for Persistence Layer - Entities
    click CategoryEntity "https://github.com/hnthangit/thesis-backend-java/blob/master/src/main/java/com/shopping/entity/Category.java"
    click ProductEntity "https://github.com/hnthangit/thesis-backend-java/blob/master/src/main/java/com/shopping/entity/Product.java"
    click OrderEntity "https://github.com/hnthangit/thesis-backend-java/blob/master/src/main/java/com/shopping/entity/Order.java"

    %% Click Events for Configuration & Infrastructure
    click JPAConfig "https://github.com/hnthangit/thesis-backend-java/blob/master/src/main/java/com/shopping/config/JPAConfig.java"
    click WebApplicationInitializer "https://github.com/hnthangit/thesis-backend-java/blob/master/src/main/java/com/shopping/config/WebApplicationInitializer.java"
    click WebMvcConfig "https://github.com/hnthangit/thesis-backend-java/blob/master/src/main/java/com/shopping/config/WebMvcConfig.java"
    click POM "https://github.com/hnthangit/thesis-backend-java/blob/master/pom.xml"
    click DataJPA "https://github.com/hnthangit/thesis-backend-java/blob/master/src/main/resources/data-jpa.properties"
    click Log4j "https://github.com/hnthangit/thesis-backend-java/blob/master/src/main/resources/log4j.properties"
    click WebXML "https://github.com/hnthangit/thesis-backend-java/blob/master/src/main/webapp/WEB-INF/web.xml"

    %% Styles
    classDef client fill:#e6e6ff,stroke:#333,stroke-width:2px
    classDef controller fill:#ffcccc,stroke:#333,stroke-width:2px
    classDef view fill:#ffe6cc,stroke:#333,stroke-width:2px
    classDef service fill:#ccffcc,stroke:#333,stroke-width:2px
    classDef dao fill:#cce5ff,stroke:#333,stroke-width:2px
    classDef repository fill:#99ccff,stroke:#333,stroke-width:2px
    classDef entity fill:#ffffcc,stroke:#333,stroke-width:2px
    classDef config fill:#d9d9d9,stroke:#333,stroke-width:2px
    classDef database fill:#ffe6f2,stroke:#333,stroke-width:2px
```
