# tuanpntse173039/diamond-valuation-system-be architecture

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

- Interactive diagram: https://gitdiagram.com/tuanpntse173039/diamond-valuation-system-be
- Repository: https://github.com/tuanpntse173039/diamond-valuation-system-be

## Overview

##### Main Components

- Frontend Client (React): Although the file tree is only for the backend, note the React frontend mentioned in the README. This component will interact with the backend via RESTful endpoints.

- Backend API (Spring Boot Application): The primary core of the system, handling business logic and interacting with data. Key components include:
- Controllers (e.g., AuthController, CustomerController, DashboardController, etc.)
- Services (service interfaces and implementations like AccountService/AccountServiceImpl)
- Repositories (JPA repositories for data access, e.g., AccountRepository, CustomerRepository, etc.)
- Domain Models/Entities (e.g., Account, Customer, DiamondImage, etc.)
- Configuration/Utility Components (SecurityConfig for JWT authentication, MailConfiguration, WebConfig, and various utility classes)
- Exception Handling (GlobalExceptionHandler and custom exception classes)

- External Services/Integrations:
- Real-time diamond price update service: indicated in the README.
- Third-party services (such as mail services) configured in classes like MailConfiguration.

- Database: Implicit in the repository structure. While not directly visible, the JPA repositories indicate persistence, so include a relational database element.

- Infrastructure:
- Docker (Dockerfile provided)
- CI/CD pipelines (GitHub Actions workflow in .github/workflows/ci.yml)
- Build Management (Maven configuration via pom.xml and wrapper scripts)

##### Relationships and Data Flow

- Users using the frontend (React) send HTTP requests (using JWT for secured endpoints) to the backend’s REST API endpoints (controllers).

- Controllers receive the requests and delegate to the corresponding Service components. For example, a valuation request goes to the ValuationRequestController which then calls its service layer (ValuationRequestServiceImpl) for business logic.

- The Service layer communicates with the Repository layer to perform CRUD operations on the underlying relational database.

- The Security components (e.g., JwtAuthenticationFilter, SecurityConfig) enforce authentication and authorization, ensuring that requests reach the correct endpoints.

- External integrations, such as the real-time diamond price update service, are consumed either directly within service components or through dedicated integration modules (if any).

- Exception handling is centralized (via GlobalExceptionHandler), which intercepts errors from controllers/services and returns structured error responses.

##### Architectural Patterns and Design Principles

- MVC/Layered Architecture: Separation of concerns between Controllers, Services, Repositories, and Entities.

- Dependency Injection: Achieved by Spring, ensuring that components such as services and security configurations are modular.

- Security: JWT-based authentication and role-based authorization are core to the design.

- Containerization and CI/CD: Docker and GitHub Actions highlight modern DevOps practices in the project.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction
    FE["Frontend (React)"]:::frontend

    %% Backend Core
    APP["Spring Boot Application Entry Point"]:::application
    CTL["API Controllers"]:::controller

    subgraph "Service Layer"
        SI["Service Interfaces"]:::service
        SIMP["Service Implementations"]:::service
    end

    REP["Repository Layer"]:::repository
    ENT["Domain Models/Entities"]:::domain

    %% Support Components
    CONFIG["Configuration Components"]:::config
    SEC["Security Components"]:::security
    EXCEP["Exception Handling"]:::exception
    UTIL["Utility Components"]:::utility
    EXT["External Integrations (Price Update & Mail)"]:::external

    %% Infrastructure
    DCK["Docker"]:::infrastructure
    CICD["CI/CD Pipeline"]:::infrastructure
    BUILD["Build Management (pom.xml & Maven)"]:::infrastructure

    %% Data Flow
    FE -->|"REST_API_Calls"| APP
    APP -->|"Initializes"| CTL
    CTL -->|"Delegates"| SI
    SI -->|"Implements"| SIMP
    SIMP -->|"Invokes_CRUD"| REP
    REP -->|"Maps_Entities"| ENT

    %% Support Relationships
    APP -->|"Uses"| CONFIG
    APP -->|"Secured_By"| SEC
    CTL -->|"HandlesErrors"| EXCEP
    SIMP -->|"Utilizes"| UTIL
    SIMP -->|"Integrates_with"| EXT

    %% Infrastructure Connections
    APP -->|"Containerized_By"| DCK
    APP -->|"CI_CD"| CICD
    APP -->|"Build_Managed"| BUILD

    %% Click Events
    click APP "https://github.com/tuanpntse173039/diamond-valuation-system-be/blob/main/src/main/java/com/letitbee/diamondvaluationsystem/DiamondValuationSystemBeApplication.java"
    click CTL "https://github.com/tuanpntse173039/diamond-valuation-system-be/tree/main/src/main/java/com/letitbee/diamondvaluationsystem/controller"
    click SI "https://github.com/tuanpntse173039/diamond-valuation-system-be/tree/main/src/main/java/com/letitbee/diamondvaluationsystem/service"
    click SIMP "https://github.com/tuanpntse173039/diamond-valuation-system-be/tree/main/src/main/java/com/letitbee/diamondvaluationsystem/service/impl"
    click REP "https://github.com/tuanpntse173039/diamond-valuation-system-be/tree/main/src/main/java/com/letitbee/diamondvaluationsystem/repository"
    click ENT "https://github.com/tuanpntse173039/diamond-valuation-system-be/tree/main/src/main/java/com/letitbee/diamondvaluationsystem/entity"
    click CONFIG "https://github.com/tuanpntse173039/diamond-valuation-system-be/tree/main/src/main/java/com/letitbee/diamondvaluationsystem/config"
    click SEC "https://github.com/tuanpntse173039/diamond-valuation-system-be/tree/main/src/main/java/com/letitbee/diamondvaluationsystem/security"
    click EXCEP "https://github.com/tuanpntse173039/diamond-valuation-system-be/tree/main/src/main/java/com/letitbee/diamondvaluationsystem/exception"
    click UTIL "https://github.com/tuanpntse173039/diamond-valuation-system-be/tree/main/src/main/java/com/letitbee/diamondvaluationsystem/utils"
    click DCK "https://github.com/tuanpntse173039/diamond-valuation-system-be/tree/main/Dockerfile"
    click CICD "https://github.com/tuanpntse173039/diamond-valuation-system-be/blob/main/.github/workflows/ci.yml"
    click BUILD "https://github.com/tuanpntse173039/diamond-valuation-system-be/blob/main/pom.xml"

    %% Styles
    classDef frontend fill:#85C1E9,stroke:#1B4F72,stroke-width:2px;
    classDef application fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef controller fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef service fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef repository fill:#A9DFBF,stroke:#145A32,stroke-width:2px;
    classDef domain fill:#D7BDE2,stroke:#6C3483,stroke-width:2px;
    classDef config fill:#FAD7A0,stroke:#9A7D0A,stroke-width:2px;
    classDef security fill:#E8DAEF,stroke:#6C3483,stroke-width:2px;
    classDef exception fill:#F1948A,stroke:#922B21,stroke-width:2px;
    classDef utility fill:#D6EAF8,stroke:#1B4F72,stroke-width:2px;
    classDef external fill:#FFD700,stroke:#B8860B,stroke-width:2px;
    classDef infrastructure fill:#D5F5E3,stroke:#1E8449,stroke-width:2px;
```
