# sebbys/backend-pbo architecture

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

- Interactive diagram: https://gitdiagram.com/sebbys/backend-pbo
- Repository: https://github.com/sebbys/backend-pbo

## Overview

##### Main Components

A. Core Application Layers (Vertical Layers):
- Controllers Layer (REST API Endpoints)
- Service Layer (Business Logic)
- Repository Layer (Data Access)
- Entity Layer (Domain Models)
- DTO Layer (Data Transfer Objects)

B. Cross-Cutting Components:
- Configuration (WebConfig)
- Security/Authentication
- Database

**┌─────────────────────────────────────────────────────────┐**
- Client Applications                   │
- ┘
- ↓ HTTP/REST
**┌─────────────────────────────────────────────────────────┐**
- Controllers Layer                     │
- ┤
- AuthController                                        │
- ProductController                                     │
- TransactionController                                 │
- DiscountCodeController                               │
- ┘
- ↓
**┌─────────────────────────────────────────────────────────┐**
- Service Layer                        │
- ┤
- ProductService                                        │
- TransactionService                                    │
- UserService                                          │
- ┘
- ↓
**┌─────────────────────────────────────────────────────────┐**
- Repository Layer                       │
- ┤
- ProductRepository                                     │
- TransactionRepository                                 │
- UserRepository                                        │
- DiscountCodeRepository                               │
- RoleRepository                                        │
- ┘
- ↓
**┌─────────────────────────────────────────────────────────┐**
- Database Layer                       │
- ┘

- Product
- Transaction
- TransactionItem
- DiscountCode
- SuperUser
- Role

- Blue: Controllers
- Green: Services
- Yellow: Repositories
- Orange: Entities
- Gray: Configuration/Cross-cutting concerns

##### Key Relationships to Highlight

- Relationship between DTOs and Entities
- Authentication flow through the AuthController
- Transaction processing flow
- How discount codes are applied to transactions

##### Implementation Details

Use tools like:
- Lucidchart
- PlantUML

For each component, show:
- Input/Output data types
- Key methods/operations
- Security constraints
- Error handling paths

##### Special Notes

- Planned changes mentioned in the TODO section
- Transition from the current schema to the new schema
- A note about the removal of TransactionProduct and TransactionItems tables
- Role entity changes and their impact on the system

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        CA[Client Applications]
    end

    subgraph Controllers
        AC["AuthController"]:::controller
        PC["ProductController"]:::controller
        TC["TransactionController"]:::controller
        DC["DiscountCodeController"]:::controller
    end

    subgraph Services
        PS["ProductService"]:::service
        TS["TransactionService"]:::service
        US["UserService"]:::service
    end

    subgraph Repositories
        PR["ProductRepository"]:::repository
        TR["TransactionRepository"]:::repository
        UR["UserRepository"]:::repository
        DR["DiscountCodeRepository"]:::repository
        RR["RoleRepository"]:::repository
    end

    subgraph Entities
        PE["Product"]:::entity
        TE["Transaction"]:::entity
        TI["TransactionItem"]:::entity
        DE["DiscountCode"]:::entity
        SU["SuperUser"]:::entity
        RE["Role"]:::entity
    end

    subgraph DTOs
        LD["LoginDTO"]:::dto
        PD["ProductDTO"]:::dto
        TD["TransactionDTO"]:::dto
        TID["TransactionItemDTO"]:::dto
    end

    subgraph Config
        WC["WebConfig"]:::config
        AP["Application Properties"]:::config
        AY["Application YAML"]:::config
    end

    subgraph Database
        DB[(Database)]:::database
    end

    %% Relationships
    CA --> AC & PC & TC & DC
    
    AC --> US
    PC --> PS
    TC --> TS
    DC --> TS

    PS --> PR
    TS --> TR & DR
    US --> UR & RR

    PR --> PE
    TR --> TE
    UR --> SU
    DR --> DE
    RR --> RE

    TE --> TI
    SU --> RE

    %% DTO Relationships
    AC --> LD
    PC <--> PD
    TC <--> TD & TID

    %% Database Relationships
    PR & TR & UR & DR & RR --> DB

    %% Click Events
    click AC "https://github.com/Sebbys/backend-pbo/blob/main/src/main/java/com/nightfall/backend/controllers/AuthController.java"
    click PC "https://github.com/Sebbys/backend-pbo/blob/main/src/main/java/com/nightfall/backend/controllers/ProductController.java"
    click TC "https://github.com/Sebbys/backend-pbo/blob/main/src/main/java/com/nightfall/backend/controllers/TransactionController.java"
    click DC "https://github.com/Sebbys/backend-pbo/blob/main/src/main/java/com/nightfall/backend/controllers/DiscountCodeController.java"
    
    click PS "https://github.com/Sebbys/backend-pbo/blob/main/src/main/java/com/nightfall/backend/service/ProductService.java"
    click TS "https://github.com/Sebbys/backend-pbo/blob/main/src/main/java/com/nightfall/backend/service/TransactionService.java"
    click US "https://github.com/Sebbys/backend-pbo/blob/main/src/main/java/com/nightfall/backend/service/UserService.java"
    
    click PR "https://github.com/Sebbys/backend-pbo/blob/main/src/main/java/com/nightfall/backend/repository/ProductRepository.java"
    click TR "https://github.com/Sebbys/backend-pbo/blob/main/src/main/java/com/nightfall/backend/repository/TransactionRepository.java"
    click UR "https://github.com/Sebbys/backend-pbo/blob/main/src/main/java/com/nightfall/backend/repository/UserRepository.java"
    click DR "https://github.com/Sebbys/backend-pbo/blob/main/src/main/java/com/nightfall/backend/repository/DiscountCodeRepository.java"
    click RR "https://github.com/Sebbys/backend-pbo/blob/main/src/main/java/com/nightfall/backend/repository/RoleRepository.java"
    
    click PE "https://github.com/Sebbys/backend-pbo/blob/main/src/main/java/com/nightfall/backend/entity/Product.java"
    click TE "https://github.com/Sebbys/backend-pbo/blob/main/src/main/java/com/nightfall/backend/entity/Transaction.java"
    click TI "https://github.com/Sebbys/backend-pbo/blob/main/src/main/java/com/nightfall/backend/entity/TransactionItem.java"
    click DE "https://github.com/Sebbys/backend-pbo/blob/main/src/main/java/com/nightfall/backend/entity/DiscountCode.java"
    click SU "https://github.com/Sebbys/backend-pbo/blob/main/src/main/java/com/nightfall/backend/entity/SuperUser.java"
    click RE "https://github.com/Sebbys/backend-pbo/blob/main/src/main/java/com/nightfall/backend/entity/Role.java"
    
    click LD "https://github.com/Sebbys/backend-pbo/blob/main/src/main/java/com/nightfall/backend/dto/LoginDTO.java"
    click PD "https://github.com/Sebbys/backend-pbo/blob/main/src/main/java/com/nightfall/backend/dto/ProductDTO.java"
    click TD "https://github.com/Sebbys/backend-pbo/blob/main/src/main/java/com/nightfall/backend/dto/TransactionDTO.java"
    click TID "https://github.com/Sebbys/backend-pbo/blob/main/src/main/java/com/nightfall/backend/dto/TransactionItemDTO.java"
    
    click WC "https://github.com/Sebbys/backend-pbo/blob/main/src/main/java/com/nightfall/backend/config/WebConfig.java"
    click AP "https://github.com/Sebbys/backend-pbo/blob/main/src/main/resources/application.properties"
    click AY "https://github.com/Sebbys/backend-pbo/blob/main/src/main/resources/application.yml"

    %% Styles
    classDef controller fill:#2196F3,stroke:#1565C0,color:white
    classDef service fill:#4CAF50,stroke:#2E7D32,color:white
    classDef repository fill:#FFC107,stroke:#FFA000,color:black
    classDef entity fill:#FF9800,stroke:#F57C00,color:white
    classDef dto fill:#9C27B0,stroke:#7B1FA2,color:white
    classDef config fill:#757575,stroke:#424242,color:white
    classDef database fill:#607D8B,stroke:#455A64,color:white
```
