# hung1962003/backend architecture

> Architecture diagram of the GitHub repository hung1962003/backend, 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/hung1962003/backend
- Repository: https://github.com/hung1962003/backend

## Overview

##### Main Components
- Service Layer: Found under src/main/java/store/auroraauction/be/service. This layer implements business logic and coordinates between the API and repository layers. Mark out key services (e.g., AuctionService, BidService, CartService, JewelryService, etc.).
- Data Access Layer (Repositories): Located under src/main/java/store/auroraauction/be/repository. These components interact with the database (likely using Spring Data JPA) and include AuctionRepository, BidRepository, OrderRepository, etc.
- Domain Models/Entities: Under src/main/java/store/auroraauction/be/entity. These classes represent the persistent data like Account, Auction, Bid, Cart, Jewelry, Order, etc. They form the backbone of the database schema.
- Additional Components:
- Configuration: In the src/main/java/store/auroraauction/be/config folder lie important configuration classes for security (SercurityConfig), CORS, Firebase, Thymeleaf, and WebSocket.
- Exception Handling: The exception package manages error scenarios.
- Utilities: Helpers under the utils package (like AccountUtils).
- Various enums (domain statuses), which further support business logic.
- External Integrations: The project uses Firebase integration (firebase-admin.json, FirebaseConfig), email templates (under src/main/resources/templates), and the potential for WebSocket configuration. These indicate connections to third-party services.

##### Relationships and Data Flows
- From the Controllers (API Layer), illustrate calls to corresponding Service Layer components.
- Optionally, indicate external interactions (e.g., calls to Firebase for notifications/authentication, email services for sending notifications, or operations configured via WebSocket).

##### Architectural Patterns/Design Principles
- Use of Dependency Injection: Although not drawn explicitly, mention that Spring handles wiring of API -> Service -> Repository.
- Configuration and External Integrations: Emphasize that this backend leverages Spring’s configuration capabilities to manage cross-cutting concerns like security, CORS, and integration with Firebase.
- Separation of Concerns: Each package (Models, API, Service, Repository) is separated by responsibility, enhancing testability and maintainability.

##### Technical Stack Details
- Language/Framework: Java with Spring Boot.
- Build Tool: Maven (see pom.xml, and Maven wrapper files).
- Database: While not explicitly configured here, the presence of repositories and entity classes implies a relational database.
- External Services: Firebase (for authentication or notifications), Email service (using Thymeleaf templates).
- Other Libraries: JPA/Hibernate for ORM, Spring Security for authentication/authorization, and possibly WebSocket for real-time features.

- Clients (Web/Mobile coming from the front end)
- API Controllers (in the API package)
- Service Components (business logic layer)
- Repositories (data access layer)
- Database (the persistence layer)
- Configurations/Integrations (Firebase, Email, WebSocket)
- From Client → API Layer (HTTP requests)
- API Layer → Service Layer (logic processing)
- Service Layer → Repository Layer (data operations)
- Repository Layer → Database (CRUD operations)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Client["Client (Web/Mobile)"]:::client

    %% API Layer
    subgraph "API Layer"
        AuctionAPI["Auction API"]:::api
        BidAPI["Bid API"]:::api
        AuthAPI["Authentication API"]:::api
        CartAPI["Cart API"]:::api
        JewelryAPI["Jewelry API"]:::api
    end

    %% Service Layer
    subgraph "Service Layer"
        AuctionService["Auction Service"]:::service
        BidService["Bid Service"]:::service
        AuthService["Authentication Service"]:::service
        CartService["Cart Service"]:::service
        JewelryService["Jewelry Service"]:::service
    end

    %% Repository Layer
    subgraph "Repository Layer"
        AuctionRepo["Auction Repository"]:::repository
        BidRepo["Bid Repository"]:::repository
        OrderRepo["Order Repository"]:::repository
        UserRepo["User Repository"]:::repository
    end

    %% Domain Models
    subgraph "Domain Models"
        Account["Account"]:::domain
        Auction["Auction"]:::domain
        Bid["Bid"]:::domain
        Cart["Cart"]:::domain
        Jewelry["Jewelry"]:::domain
        Order["Order"]:::domain
    end

    %% Configuration & External Integrations
    subgraph "Configuration & Integrations"
        Config["Configuration"]:::config
        WebSocket["WebSocket Config"]:::config
        Firebase["Firebase Integration"]:::external
        Email["Email Templates"]:::external
    end

    %% Helpers
    subgraph "Helpers"
        Exception["Exception Handling"]:::exception
        Utils["Utilities"]:::utils
    end

    %% Client to API Layer
    Client -->|"HTTP_Request"| AuctionAPI
    Client -->|"HTTP_Request"| BidAPI
    Client -->|"Login_Request"| AuthAPI
    Client -->|"HTTP_Request"| CartAPI
    Client -->|"HTTP_Request"| JewelryAPI

    %% API to Service Layer
    AuctionAPI -->|"Service_Call"| AuctionService
    BidAPI -->|"Service_Call"| BidService
    AuthAPI -->|"Service_Call"| AuthService
    CartAPI -->|"Service_Call"| CartService
    JewelryAPI -->|"Service_Call"| JewelryService

    %% Service to Repository Layer
    AuctionService -->|"DB_Operation"| AuctionRepo
    BidService -->|"DB_Operation"| BidRepo
    AuthService -->|"DB_Operation"| UserRepo
    CartService -->|"DB_Operation"| OrderRepo
    JewelryService -->|"DB_Operation"| AuctionRepo

    %% Repository Layer to Domain Models
    AuctionRepo -->|"CRUD"| Auction
    BidRepo -->|"CRUD"| Bid
    OrderRepo -->|"CRUD"| Order
    UserRepo -->|"CRUD"| Account

    %% Service Layer interactions with Domain Models (if any operations on models)
    AuctionService -->|"Utilizes"| Auction
    BidService -->|"Utilizes"| Bid
    CartService -->|"Utilizes"| Cart
    AuthService -->|"Utilizes"| Account
    JewelryService -->|"Utilizes"| Jewelry

    %% Service interactions with Configuration & Integrations and Helpers
    AuthService -->|"Firebase_Auth"| Firebase
    CartService -->|"Email_Notification"| Email
    AuctionService -->|"Uses_Config"| Config
    AuctionService -->|"Handles_Exception"| Exception
    AuctionService -->|"Uses_Utils"| Utils

    %% Class styles
    classDef client fill:#b3e5fc,stroke:#01579b,stroke-width:2px;
    classDef api fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef service fill:#c8e6c9,stroke:#1b5e20,stroke-width:2px;
    classDef repository fill:#ffe0b2,stroke:#e65100,stroke-width:2px;
    classDef domain fill:#d1c4e9,stroke:#4a148c,stroke-width:2px;
    classDef config fill:#ffcdd2,stroke:#b71c1c,stroke-width:2px;
    classDef external fill:#f0f4c3,stroke:#827717,stroke-width:2px;
    classDef exception fill:#e0f7fa,stroke:#006064,stroke-width:2px;
    classDef utils fill:#f8bbd0,stroke:#880e4f,stroke-width:2px;

    %% Click Events
    click AuctionAPI "https://github.com/hung1962003/backend/tree/main/src/main/java/store/auroraauction/be/api"
    click BidAPI "https://github.com/hung1962003/backend/tree/main/src/main/java/store/auroraauction/be/api"
    click AuthAPI "https://github.com/hung1962003/backend/tree/main/src/main/java/store/auroraauction/be/api"
    click CartAPI "https://github.com/hung1962003/backend/tree/main/src/main/java/store/auroraauction/be/api"
    click JewelryAPI "https://github.com/hung1962003/backend/tree/main/src/main/java/store/auroraauction/be/api"

    click AuctionService "https://github.com/hung1962003/backend/tree/main/src/main/java/store/auroraauction/be/service"
    click BidService "https://github.com/hung1962003/backend/tree/main/src/main/java/store/auroraauction/be/service"
    click AuthService "https://github.com/hung1962003/backend/tree/main/src/main/java/store/auroraauction/be/service"
    click CartService "https://github.com/hung1962003/backend/tree/main/src/main/java/store/auroraauction/be/service"
    click JewelryService "https://github.com/hung1962003/backend/tree/main/src/main/java/store/auroraauction/be/service"

    click AuctionRepo "https://github.com/hung1962003/backend/tree/main/src/main/java/store/auroraauction/be/repository"
    click BidRepo "https://github.com/hung1962003/backend/tree/main/src/main/java/store/auroraauction/be/repository"
    click OrderRepo "https://github.com/hung1962003/backend/tree/main/src/main/java/store/auroraauction/be/repository"
    click UserRepo "https://github.com/hung1962003/backend/tree/main/src/main/java/store/auroraauction/be/repository"

    click Account "https://github.com/hung1962003/backend/tree/main/src/main/java/store/auroraauction/be/entity"
    click Auction "https://github.com/hung1962003/backend/tree/main/src/main/java/store/auroraauction/be/entity"
    click Bid "https://github.com/hung1962003/backend/tree/main/src/main/java/store/auroraauction/be/entity"
    click Cart "https://github.com/hung1962003/backend/tree/main/src/main/java/store/auroraauction/be/entity"
    click Jewelry "https://github.com/hung1962003/backend/tree/main/src/main/java/store/auroraauction/be/entity"
    click Order "https://github.com/hung1962003/backend/tree/main/src/main/java/store/auroraauction/be/entity"

    click Config "https://github.com/hung1962003/backend/tree/main/src/main/java/store/auroraauction/be/config"
    click WebSocket "https://github.com/hung1962003/backend/tree/main/src/main/java/store/auroraauction/be/config"
    click Firebase "https://github.com/hung1962003/backend/blob/main/src/main/java/store/auroraauction/be/config/FirebaseConfig.java"
    click Email "https://github.com/hung1962003/backend/tree/main/src/main/resources/templates"

    click Exception "https://github.com/hung1962003/backend/tree/main/src/main/java/store/auroraauction/be/exception"
    click Utils "https://github.com/hung1962003/backend/tree/main/src/main/java/store/auroraauction/be/utils"
```
