# baotran2003/laptopshop-springmvc architecture

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

- Interactive diagram: https://gitdiagram.com/baotran2003/laptopshop-springmvc
- Repository: https://github.com/baotran2003/laptopshop-springmvc

## Overview

##### Main Components to Highlight
- Application Entry Point: Show the LaptopshopApplication class as the bootstrapping component.
- Web Layer (Controllers & Views):
- Separate controllers for admin (e.g., AdminHomePageController, AdminOrderController, AdminProductController, UserController) and client (e.g., AuthController, CartController, HomePageController, OrderController, ProductController).
- JSP-based views segregated into admin and client folders under WEB-INF/view.
- Static resources managed under the “resources” directories.
- Service Layer:
- Services handling business logic such as CartService, OrderService, ProductService, UploadService, UserService, and CustomUserDetailsService.
- Validators (e.g., RegisterValidator, StrongPasswordValidator) under a subpackage, which are important for maintaining business rules.
- Data Access Layer (Repositories & Domain Models):
- Repository interfaces (e.g., ProductRepository, OrderRepository, UserRepository) for interaction with MySQL via Hibernate.
- Domain objects for entities (e.g., Product, Cart, Order, User, Role) that encapsulate the core data.
- Security and Configuration:
- Spring Security components like SecurityConfiguration and CustomSuccessHandler.
- WebMvcConfig which defines MVC-specific settings.
- Infrastructure:
- Maven build system (pom.xml, mvnw) and resource configuration (application.properties) to manage dependencies and deployment configuration.

##### Relationships and Interactions
- Flow from Controllers to Services then to Repositories:
- Controllers invoke methods from Service classes.
- Services encapsulate business logic and call Repository methods to fetch/update persistent data.
- Data flows between the Service layer and the Database (MySQL) represented by the ORM (Hibernate).
- The Web Layer sends output to the JSP views (frontend) which use static assets such as CSS, JS, images under “resources” and “webapp/resources”.
- The Security layer manages authentication/authorization, intercepting requests and directing users appropriately using the configurations defined in SecurityConfiguration.

##### Architectural Patterns and Design Principles
- MVC (Model-View-Controller) design, segregating presentation logic (JSP views), business logic (Service layer), and data access (Repository layer).
- Layered architecture: clearly defined boundaries between presentation, business, and data access layers.
- Dependency injection provided by Spring to decouple components.
- Custom validations and security configurations highlighting extensibility and separation of concerns.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry Point and External Client
    B["Browser"]:::external
    A["LaptopshopApplication"]:::config

    %% Presentation Layer Subgraph
    subgraph "Presentation Layer"
        PC1["Admin Controllers"]:::controller
        PC2["Client Controllers"]:::controller
        PV1["JSP Views (Admin)"]:::controller
        PV2["JSP Views (Client)"]:::controller
        SR["Static Resources"]:::controller
    end

    %% Business Layer Subgraph
    subgraph "Business Layer"
        S["Service Layer"]:::service
        V["Validators"]:::service
    end

    %% Data Access Layer Subgraph
    subgraph "Data Layer"
        R["Repositories"]:::data
        D["Domain Models"]:::data
        DB["MySQL Database"]:::data
    end

    %% Security and Configuration Subgraph
    subgraph "Security & Config"
        SC["Security Configuration"]:::config
        MVC["WebMvcConfig"]:::config
    end

    %% Infrastructure Subgraph
    subgraph "Infrastructure"
        INF["Infrastructure & Build"]:::config
    end

    %% Flow of interactions
    B -->|"access"| PC2
    B -->|"access"| PC1

    PC1 -->|"invoke"| S
    PC2 -->|"invoke"| S

    S -->|"validate"| V
    S -->|"call"| R

    R -->|"access"| D
    D -->|"persist"| DB

    PC1 -->|"render"| PV1
    PC2 -->|"render"| PV2

    PV1 -->|"response"| B
    PV2 -->|"response"| B
    SR -->|"serve"| B

    %% Bootstrapping and configuration
    A -->|"initialize"| PC1
    A -->|"initialize"| PC2
    A -->|"initialize"| S
    A -->|"initialize"| R
    A -->|"load"| SC
    A -->|"load"| MVC
    A -->|"load"| INF

    %% Security intercepts
    SC -.->|"intercept"| PC1
    SC -.->|"intercept"| PC2
    MVC -.->|"configure"| PC1
    MVC -.->|"configure"| PC2

    %% Class Definitions
    classDef controller fill:#add8e6,stroke:#000,stroke-width:1px;
    classDef service fill:#90ee90,stroke:#000,stroke-width:1px;
    classDef data fill:#ffa500,stroke:#000,stroke-width:1px;
    classDef config fill:#d3d3d3,stroke:#000,stroke-width:1px;
    classDef external fill:#fffacd,stroke:#000,stroke-width:1px;

    %% Click Events
    click A "https://github.com/baotran2003/laptopshop-springmvc/blob/master/src/main/java/vn/baotran/laptopshop/LaptopshopApplication.java"
    click PC1 "https://github.com/baotran2003/laptopshop-springmvc/tree/master/src/main/java/vn/baotran/laptopshop/controller/admin"
    click PC2 "https://github.com/baotran2003/laptopshop-springmvc/tree/master/src/main/java/vn/baotran/laptopshop/controller/client"
    click PV1 "https://github.com/baotran2003/laptopshop-springmvc/tree/master/src/main/webapp/WEB-INF/view/admin"
    click PV2 "https://github.com/baotran2003/laptopshop-springmvc/tree/master/src/main/webapp/WEB-INF/view/client"
    click SR "https://github.com/baotran2003/laptopshop-springmvc/tree/master/src/main/webapp/resources"
    click S "https://github.com/baotran2003/laptopshop-springmvc/tree/master/src/main/java/vn/baotran/laptopshop/service"
    click V "https://github.com/baotran2003/laptopshop-springmvc/tree/master/src/main/java/vn/baotran/laptopshop/service/validator"
    click R "https://github.com/baotran2003/laptopshop-springmvc/tree/master/src/main/java/vn/baotran/laptopshop/repository"
    click D "https://github.com/baotran2003/laptopshop-springmvc/tree/master/src/main/java/vn/baotran/laptopshop/domain"
    click SC "https://github.com/baotran2003/laptopshop-springmvc/tree/master/src/main/java/vn/baotran/laptopshop/config"
    click MVC "https://github.com/baotran2003/laptopshop-springmvc/blob/master/src/main/java/vn/baotran/laptopshop/config/WebMvcConfig.java"
    click INF "https://github.com/baotran2003/laptopshop-springmvc/blob/master/pom.xml"
```
