# khainguyen11/java-spring-mvc architecture

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

- Interactive diagram: https://gitdiagram.com/khainguyen11/java-spring-mvc
- Repository: https://github.com/khainguyen11/java-spring-mvc

## Overview

##### Main Components
a. Presentation Layer (View):
- Web pages built using JSP files organized under src/main/webapp/WEB-INF/view.
- Both administrative views (e.g., for managing orders, products, users) and client views (e.g., homepage, product details, cart) are present.
- Additional static resources such as CSS, JS, images, and third-party libraries (e.g., Owl Carousel, Lightbox) exist under src/main/webapp/resources.
b. Controller Layer:
- Divided into admin and client controllers (located under src/main/java/vn/hoidanit/laptopshop/controller/admin and .../controller/client).
- These controllers handle inbound HTTP requests and coordinate with the service layer.
c. Service Layer:
- The business logic is implemented in the service package (e.g., ProductService, OrderService, UserService).
- Additional components include validator classes to check for input standards (like password strength and registration validation).
d. Data / Domain Layer:
- Domain models (Cart, Order, Product, User, etc.) reside in the domain package.
- Data Transfer Objects (DTOs) are also present for product criteria and user registration.
e. Repository Layer:
- This layer manages persistence and includes repositories for every domain entity (e.g., ProductRepository, OrderRepository, etc.).
- There is a custom Specification package that likely supports advanced queries (e.g., ProductSpecs).
f. Configuration & Infrastructure:
- Configuration classes (under the config package) such as SecurityConfiguration, CustomSuccessHandler, and WebMvcConfig indicate custom security settings and web MVC configurations.
- Application properties are located under src/main/resources for environment-specific settings.
- Maven-related files (pom.xml and Maven Wrapper scripts) ensure that dependencies and project builds are consistently managed.

##### Relationships and Interactions
- Client requests are received by the Controllers (admin or client) → The Controllers interact with the Service layer → The Service layer uses Repository to access the database and perform CRUD operations → Domain models represent the persisted data.
- The configuration classes initialize system components such as security filters, handler interceptors, and potentially other middleware concerns.
- Web resources (JSPs, CSS, JavaScript) as the front-end part of the presentation layer, interacting with the controllers via HTTP requests/responses.

##### Architectural Patterns and Design Principles
- MVC pattern: Clearly show the separation between the Model (domain/repository), View (JSPs and static resources), and Controller layers.
- Layered Architecture: Indicate that the service layer acts as a mediator between controllers and the data layer, promoting loose coupling.
- Security: The use of SecurityConfiguration and related classes points to an implementation of role-based access control.
- Validation: Custom validation mechanisms (e.g., RegisterValidator and password checks) are implemented as cross-cutting concerns.

##### Relevant Technologies, Frameworks, and Libraries
- Java and Maven for project build and dependency management.
- Likely Spring Boot/Spring MVC for the core framework (given the naming conventions and package structure).
- JSP for view rendering and standard web technologies (HTML/CSS/JavaScript) with libraries like Owl Carousel, Lightbox, etc.
- (Potentially) Spring Security for authentication/authorization based on the configuration classes.
- JPA/Hibernate (implied by the repository layer) for database interactions.

## Diagram (Mermaid)

```mermaid
graph TD
    %% User Interface
    U("User/Browser"):::user

    %% Controller Layer
    subgraph "Controller Layer"
        AC("Admin Controllers"):::controller
        CC("Client Controllers"):::controller
    end

    %% Service Layer
    subgraph "Service Layer"
        S1("Business Logic"):::service
        S2("Validators"):::service
    end

    %% Data/Domain & Repository Layer
    subgraph "Data/Domain & Repository Layer"
        DM("Domain Models"):::domain
        DTO("DTOs"):::domain
        REPO("Repositories & Specifications"):::repo
    end

    %% Presentation Layer
    subgraph "Presentation Layer"
        JSP("JSP Pages"):::view
        SR("Static Resources"):::view
    end

    %% Configuration & Infrastructure
    subgraph "Configuration & Infrastructure"
        CONF("Configuration Classes"):::config
        AP("Application Properties"):::config
        MVN("Maven Build Files"):::config
    end

    %% Flow Connections
    U -->|"sendsAdminRequest"| AC
    U -->|"sendsClientRequest"| CC

    AC -->|"invokes"| S1
    CC -->|"invokes"| S1

    S1 -->|"triggersValidation"| S2

    S2 -->|"accesses"| REPO
    S2 -->|"retrieves"| DM
    S2 -->|"populates"| DTO

    S1 -->|"renders"| JSP
    JSP -->|"deliversContent"| U

    U -->|"loads"| SR

    %% Configuration Connections
    CONF -->|"configures"| AC
    CONF -->|"configures"| CC
    CONF -->|"configures"| S1
    CONF -->|"configures"| S2
    AP -->|"feeds"| CONF
    MVN -->|"builds"| CONF

    %% Click Events
    click JSP "https://github.com/khainguyen11/java-spring-mvc/tree/Master/src/main/webapp/WEB-INF/view"
    click SR "https://github.com/khainguyen11/java-spring-mvc/tree/Master/src/main/webapp/resources"
    click AC "https://github.com/khainguyen11/java-spring-mvc/tree/Master/src/main/java/vn/hoidanit/laptopshop/controller/admin"
    click CC "https://github.com/khainguyen11/java-spring-mvc/tree/Master/src/main/java/vn/hoidanit/laptopshop/controller/client"
    click S1 "https://github.com/khainguyen11/java-spring-mvc/tree/Master/src/main/java/vn/hoidanit/laptopshop/service"
    click S2 "https://github.com/khainguyen11/java-spring-mvc/tree/Master/src/main/java/vn/hoidanit/laptopshop/service/validator"
    click DM "https://github.com/khainguyen11/java-spring-mvc/tree/Master/src/main/java/vn/hoidanit/laptopshop/domain"
    click DTO "https://github.com/khainguyen11/java-spring-mvc/tree/Master/src/main/java/vn/hoidanit/laptopshop/domain/dto"
    click REPO "https://github.com/khainguyen11/java-spring-mvc/tree/Master/src/main/java/vn/hoidanit/laptopshop/repository"
    click CONF "https://github.com/khainguyen11/java-spring-mvc/tree/Master/src/main/java/vn/hoidanit/laptopshop/config"
    click AP "https://github.com/khainguyen11/java-spring-mvc/blob/Master/src/main/resources/application.properties"
    click MVN "https://github.com/khainguyen11/java-spring-mvc/blob/Master/pom.xml"

    %% Styles
    classDef user fill:#aqua,stroke:#000,stroke-width:2px,fill-opacity:0.7;
    classDef controller fill:#ffcccb,stroke:#000,stroke-width:2px,fill-opacity:0.8;
    classDef service fill:#d5f5e3,stroke:#000,stroke-width:2px;
    classDef domain fill:#fcf3cf,stroke:#000,stroke-width:2px;
    classDef repo fill:#f9e79f,stroke:#000,stroke-width:2px;
    classDef view fill:#d6eaf8,stroke:#000,stroke-width:2px;
    classDef config fill:#e8daef,stroke:#000,stroke-width:2px;
```
