# tuan2305/ecommerce-store-spring architecture

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

- Interactive diagram: https://gitdiagram.com/tuan2305/ecommerce-store-spring
- Repository: https://github.com/tuan2305/ecommerce-store-spring

## Overview

##### Main Components
- Application Layer – The entry point (EcommerceStoreApplication.java) which bootstraps the Spring Boot application.
- Controller Layer – Several controllers (e.g., AdminController, AuthController, CartController, PaymentController, SellerController, etc.) handle HTTP endpoints. The README highlights seller-related endpoints (login, OTP-based verification, seller management), so include a dedicated section for Seller operations.
- Service Layer – Implements business logic. There are service interfaces (e.g., AuthService, ProductService) and their corresponding implementations in the “impl” package.
- Data Access Layer – Repositories (AddressRepository, OrderRepository, ProductRepository, etc.) for interaction with the underlying database.
- Domain/Model – Classes representing the core data structures (e.g., Order, Product, Seller, Cart, etc.) along with enumerations for statuses and roles.
- Configuration – The config package hosts configurations such as AppConfig, JWT_CONSTANT, JwtProvider, and token validators for handling JWT security.
- Utility Modules – Helper classes like OtpUtil which support functions like generating OTP.
- Exception Handling – Dedicated exception classes and a global exception mechanism that manage runtime errors and validate inputs.

##### Relationships and Data Flow
- How HTTP requests flow from the client to the REST controllers.
- From Controllers, illustrate that calls are forwarded to the Service layer where the business logic is processed.
- The Service layer then interacts with the Repositories for CRUD operations and fetching/persisting data.
- Integration points for security (JWT configuration and OTP validation) which are processed either directly in controllers or through dedicated service methods.

##### Architectural Patterns
- MVC (Model-View-Controller) or RESTful Architecture: Controllers are clearly segmented from business logic (services) and persistence (repositories).
- Dependency Inversion and Inversion of Control: The usage of service interfaces and repository interfaces along with Spring Boot’s auto-wiring.
- Security Pattern: Use of JWT for authentication and OTP for seller validation – indicating tight integration of security concerns in the configuration and controller layers.

##### Technology, Frameworks, and Libraries
- Java with Spring Boot framework as the backbone for the application.
- Maven as the build and dependency management system.
- JWT for authentication and OTP for seller verification.
- Likely a relational database accessed via Spring Data JPA repositories.
- Any external email services for OTP dispatch (referenced in the EmailService).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    Client["Client"]

    %% Application Layer
    subgraph "Application Layer"
        APP["EcommerceStoreApplication.java"]
    end

    %% Controller Layer
    subgraph "Controller Layer"
        GC["General Controllers"]
        SC["Seller Controller"]
    end

    %% Service Layer
    subgraph "Service Layer"
        SI["Service Interfaces"]
        SIMPL["Service Implementations"]
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        REPO["Repositories"]
    end

    %% Database (Relational Database)
    DB(("Relational Database"))

    %% Domain/Model Layer
    subgraph "Domain/Model"
        DM["Domain Models"]
        MM["Modal Models"]
    end

    %% Core Modules (Configuration, Utility, Exception)
    subgraph "Core Modules"
        CONFIG["Configuration (JWT, etc.)"]
        UTILS["Utility (OtpUtil)"]
        EX["Exception Handling"]
    end

    %% Data Flow Connections
    Client -->|"initiates"| APP
    APP -->|"bootstraps"| GC
    APP -->|"bootstraps"| SC
    GC -->|"calls"| SI
    SC -->|"calls"| SI
    SI -->|"delegates"| SIMPL
    SIMPL -->|"persists/fetches"| REPO
    REPO -->|"CRUD operations"| DB

    %% Domain usage (used by Services and Repositories)
    SIMPL -- "uses" --> DM
    REPO -- "maps to" --> DM
    SIMPL -- "uses" --> MM
    REPO -- "maps to" --> MM

    %% Security and Utility interactions
    GC -->|"JWT-auth"| CONFIG
    SC -->|"OTP-verify"| UTILS

    %% Exception Handling flow
    GC ---|"handles"| EX
    SC ---|"handles"| EX
    SIMPL ---|"handles"| EX

    %% Styles
    class APP entry;
    class GC,SC controller;
    class SI,SIMPL service;
    class REPO,DB repository;
    class CONFIG,UTILS config;
    class EX exception;
    class DM,MM domain;

    %% Class Definitions (with colours)
    classDef entry fill:#E0E0E0,stroke:#000,stroke-width:2px;
    classDef controller fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef service fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef repository fill:#FFFF99,stroke:#000,stroke-width:2px;
    classDef config fill:#FFA500,stroke:#000,stroke-width:2px;
    classDef exception fill:#FF7F7F,stroke:#000,stroke-width:2px;
    classDef domain fill:#D3D3D3,stroke:#000,stroke-width:2px;

    %% Click Events
    click APP "https://github.com/tuan2305/ecommerce-store-spring/blob/main/src/main/java/com/tuanvn/Ecommerce/Store/EcommerceStoreApplication.java"
    click GC "https://github.com/tuan2305/ecommerce-store-spring/tree/main/src/main/java/com/tuanvn/Ecommerce/Store/controller"
    click SC "https://github.com/tuan2305/ecommerce-store-spring/blob/main/src/main/java/com/tuanvn/Ecommerce/Store/controller/SellerController.java"
    click SI "https://github.com/tuan2305/ecommerce-store-spring/tree/main/src/main/java/com/tuanvn/Ecommerce/Store/service"
    click SIMPL "https://github.com/tuan2305/ecommerce-store-spring/tree/main/src/main/java/com/tuanvn/Ecommerce/Store/service/impl"
    click REPO "https://github.com/tuan2305/ecommerce-store-spring/tree/main/src/main/java/com/tuanvn/Ecommerce/Store/repository"
    click DM "https://github.com/tuan2305/ecommerce-store-spring/tree/main/src/main/java/com/tuanvn/Ecommerce/Store/domain"
    click MM "https://github.com/tuan2305/ecommerce-store-spring/tree/main/src/main/java/com/tuanvn/Ecommerce/Store/modal"
    click CONFIG "https://github.com/tuan2305/ecommerce-store-spring/tree/main/src/main/java/com/tuanvn/Ecommerce/Store/config"
    click UTILS "https://github.com/tuan2305/ecommerce-store-spring/blob/main/src/main/java/com/tuanvn/Ecommerce/Store/utils/OtpUtil.java"
    click EX "https://github.com/tuan2305/ecommerce-store-spring/tree/main/src/main/java/com/tuanvn/Ecommerce/Store/exceptions"
```
