# huynhthinhphat/website_electronics_sale architecture

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

- Interactive diagram: https://gitdiagram.com/huynhthinhphat/website_electronics_sale
- Repository: https://github.com/huynhthinhphat/website_electronics_sale

## Overview

##### Project type and purpose
- This is a Spring-Boot backed monolithic REST API (“tip_b18_electronics-sales-be”) for an electronics e-commerce platform.
- The service exposes endpoints to manage accounts, authentication, products, categories, brands, carts, orders, reviews, images, statistics, payment (PayOS), email, and Excel exports.

##### File structure
- Top-level: Dockerfile, Maven wrapper, pom.xml, application.properties
- src/main/java/com/tip/b18/electronicsales:
- configurations (Cloudinary, CORS, Security, Redis, Swagger, Password)
- controllers (REST endpoints)
- dto (data transfer objects)
- entities (JPA domain models + base classes)
- repositories (Spring Data JPA interfaces)
- mappers (DTO↔entity mapping)
- services + impls (business logic)
- filters (JWT authentication)
- exceptions (custom exceptions & global handler)
- utils & validators
- src/main/resources/application.properties holds DB, Redis, Cloudinary, mail, payment configs.
- Dockerfile packages the Spring Boot jar into a container.

##### Key architectural insights from the readme/structure
- It uses layered MVC (Controller → Service → Repository → RDBMS)
- JWT-based stateless auth via a custom filter + Spring Security
- Redis for caching (or OTP/session storage)
- External integrations: Cloudinary (image storage), SMTP/email, PayOS payment gateway, Google OAuth
- Swagger for API docs

##### Main components & relationships
a. Internal components (monolith):
- API Gateway / Inbound HTTP (Spring Boot embedded Tomcat)
- Security Layer (CorsFilter, JwtAuthenticationFilter, SecurityConfig)
- Controller Layer (AccountController, ProductController, OrderController, etc.)
- Service Layer (AccountServiceImpl, ProductServiceImpl, PayOSServiceImpl, EmailServiceImpl, ExcelServiceImpl, etc.)
- Data Access Layer (Spring Data Repositories)
- Domain Model (JPA Entities)
- DTO Layer + Mappers
- Utility modules (Utils, Validators)
b. External components:
- Relational Database (MySQL/PostgreSQL)
- Redis Cache
- Cloudinary (image hosting)
- SMTP Email Server
- PayOS Payment Gateway
- Google OAuth Service
- Swagger UI (for docs)
c. Data flows & interactions:
1. Client → HTTP(S) → Security filter → Controller
2. Controller → Service (business logic)
3. Service ↔ Repository → RDBMS
4. Service ↔ Redis (caching, OTP)
5. Service → External APIs (Cloudinary, PayOS, Email, Google OAuth)
6. Controllers return DTOs

##### Architectural patterns & design principles
- Layered architecture (Separation of concerns)
- DTO mapping using Mapper classes for decoupling API model from persistence model
- Exception handling via a GlobalExceptionHandler
- Configuration via Spring’s @Configuration classes
- Stateless JWT authentication filter
- Use of interfaces + impls for easy testing and swapping implementations

##### Capturing essential elements
- Don’t omit the Security/Filter chain and DTO↔Entity mapping step
- Cross-cutting concerns: Configuration classes (Swagger, CORS), Global exception handling, Utilities

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Application Entry
    subgraph "Spring Boot Application" 
        direction TB
        App["ElectronicsSalesApplication"]:::core
        subgraph "Configuration Modules"
            direction TB
            CloudinaryCfg["CloudinaryConfig"]:::core
            RedisCfg["RedisConfig"]:::core
            SwaggerCfg["SwaggerConfig"]:::core
            PasswordCfg["PasswordConfig"]:::core
        end
        subgraph "Security Layer"
            direction TB
            JwtFilter["JwtAuthenticationFilter"]:::core
            SecurityCfg["SecurityConfig"]:::core
            CorsCfg["CorsConfig"]:::core
        end
        subgraph "Controller Layer"
            direction TB
            Controllers["controllers/"]:::core
        end
        subgraph "DTO & Mapper"
            direction TB
            DTOs["dto/"]:::core
            Mappers["mappers/"]:::core
        end
        subgraph "Service Layer"
            direction TB
            ServicesIface["services/"]:::core
            ServicesImpl["services/impls/"]:::core
        end
        subgraph "Persistence Layer"
            direction TB
            Entities["entities/"]:::core
            Repos["repositories/"]:::core
        end
        subgraph "Exception & Utils"
            direction TB
            GlobalEx["GlobalExceptionHandler"]:::core
            Exceptions["exceptions/"]:::core
            Utils["utils/"]:::core
            Validators["validators/"]:::core
        end
        App -->|loads| CloudinaryCfg
        App -->|loads| RedisCfg
        App -->|loads| SwaggerCfg
        App -->|loads| PasswordCfg
        App -->|initializes| JwtFilter
        App -->|initializes| SecurityCfg
        App -->|initializes| CorsCfg
        JwtFilter --> Controllers
        CorsCfg --> Controllers
        Controllers -->|calls| ServicesIface
        DTOs --> Controllers
        Mappers --> ServicesImpl
        ServicesIface -->|implemented by| ServicesImpl
        ServicesImpl -->|uses| Repos
        ServicesImpl -->|uses| Entities
        ServicesImpl -->|uses| Utils
        ServicesImpl -->|uses| Validators
        Repos -->|JPA queries| RDBMS
        ServicesImpl -->|Cache get/set| Redis
        ServicesImpl -->|HTTP upload| Cloudinary
        ServicesImpl -->|SMTP send| SMTP
        ServicesImpl -->|HTTP POST| PayOS
        ServicesImpl -->|OAuth| Google
        Controllers -->|returns DTOs| DTOs
        GlobalEx --> Controllers

    end

    %% External Services and Data Stores
    subgraph "Data Stores"
        direction TB
        RDBMS["Relational DB"]:::data
        Redis["Redis Cache"]:::data
    end
    subgraph "External Integrations"
        direction TB
        Cloudinary["Cloudinary"]:::external
        SMTP["SMTP Email"]:::external
        PayOS["PayOS Gateway"]:::external
        Google["Google OAuth"]:::external
        SwaggerUI["Swagger UI"]:::external
    end

    %% Legend
    subgraph Legend
        direction LR
        Core["Core Modules"]:::core
        DataStore["Data Stores"]:::data
        External["External Services"]:::external
    end

    %% Click Events
    click App "https://github.com/huynhthinhphat/website_electronics_sale/blob/dev/src/main/java/com/tip/b18/electronicsales/ElectronicsSalesApplication.java"
    click JwtFilter "https://github.com/huynhthinhphat/website_electronics_sale/blob/dev/src/main/java/com/tip/b18/electronicsales/filters/JwtAuthenticationFilter.java"
    click SecurityCfg "https://github.com/huynhthinhphat/website_electronics_sale/blob/dev/src/main/java/com/tip/b18/electronicsales/configurations/SecurityConfig.java"
    click CorsCfg "https://github.com/huynhthinhphat/website_electronics_sale/blob/dev/src/main/java/com/tip/b18/electronicsales/configurations/CorsConfig.java"
    click CloudinaryCfg "https://github.com/huynhthinhphat/website_electronics_sale/blob/dev/src/main/java/com/tip/b18/electronicsales/configurations/CloudinaryConfig.java"
    click RedisCfg "https://github.com/huynhthinhphat/website_electronics_sale/blob/dev/src/main/java/com/tip/b18/electronicsales/configurations/RedisConfig.java"
    click SwaggerCfg "https://github.com/huynhthinhphat/website_electronics_sale/blob/dev/src/main/java/com/tip/b18/electronicsales/configurations/SwaggerConfig.java"
    click PasswordCfg "https://github.com/huynhthinhphat/website_electronics_sale/blob/dev/src/main/java/com/tip/b18/electronicsales/configurations/PasswordConfig.java"
    click Controllers "https://github.com/huynhthinhphat/website_electronics_sale/tree/dev/src/main/java/com/tip/b18/electronicsales/controllers/"
    click DTOs "https://github.com/huynhthinhphat/website_electronics_sale/tree/dev/src/main/java/com/tip/b18/electronicsales/dto/"
    click Mappers "https://github.com/huynhthinhphat/website_electronics_sale/tree/dev/src/main/java/com/tip/b18/electronicsales/mappers/"
    click ServicesIface "https://github.com/huynhthinhphat/website_electronics_sale/tree/dev/src/main/java/com/tip/b18/electronicsales/services/"
    click ServicesImpl "https://github.com/huynhthinhphat/website_electronics_sale/tree/dev/src/main/java/com/tip/b18/electronicsales/services/impls/"
    click Entities "https://github.com/huynhthinhphat/website_electronics_sale/tree/dev/src/main/java/com/tip/b18/electronicsales/entities/"
    click Repos "https://github.com/huynhthinhphat/website_electronics_sale/tree/dev/src/main/java/com/tip/b18/electronicsales/repositories/"
    click GlobalEx "https://github.com/huynhthinhphat/website_electronics_sale/blob/dev/src/main/java/com/tip/b18/electronicsales/exceptions/GlobalExceptionHandler.java"
    click Exceptions "https://github.com/huynhthinhphat/website_electronics_sale/tree/dev/src/main/java/com/tip/b18/electronicsales/exceptions/"
    click Utils "https://github.com/huynhthinhphat/website_electronics_sale/tree/dev/src/main/java/com/tip/b18/electronicsales/utils/"
    click Validators "https://github.com/huynhthinhphat/website_electronics_sale/tree/dev/src/main/java/com/tip/b18/electronicsales/validators/"

    classDef core fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef data fill:#E0F7E9,stroke:#1B6E20,color:#1B6E20;
    classDef external fill:#FFE8CD,stroke:#D65A00,color:#D65A00;
```
