# yanrice/payment-transaction-spring-boot-application architecture

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

- Interactive diagram: https://gitdiagram.com/yanrice/payment-transaction-spring-boot-application
- Repository: https://github.com/yanrice/payment-transaction-spring-boot-application

## Overview

##### Project type and purpose
- This is a standalone Spring Boot microservice (monolith-style) providing a RESTful API for managing payment transactions.
- It has no UI layer—clients (web/mobile/other services) call the HTTP endpoints exposed by the controller.

##### File structure
- Top-level: `pom.xml` (Maven), `src/main/java/...` and `src/main/resources`.
- Java packages follow a classic layered architecture:
- `controller` (REST layer)
- `dto` (request/response objects)
- `service` (business logic)
- `repository` (data access via Spring Data JPA)
- `model` (JPA entities and enums)
- `exception` (global error handler)
- `application.properties` configures server port, H2 in-memory DB, JPA, logging.

##### Key insights from the README
- Supports CRUD operations on transactions, filtering, pagination, sorting, status updates, total calculations.
- Uses in-memory H2 for persistence (with console), Spring Data JPA, Jakarta Validation, Jackson for JSON.
- `TransactionService` simulates payment processing (mock) with an 80% success rate.

##### Main components
a. External Clients
- Web or mobile front-ends, other microservices or API consumers.
b. API Layer
- TransactionController (handles `/api/v1/transactions/**` endpoints)
- GlobalExceptionHandler (catches and formats exceptions)
c. Service Layer
- TransactionService (business rules, mockPaymentProcessing, validation orchestration)
d. Data Layer
- TransactionRepository (Spring Data JPA interface)
- H2 Database (in-memory, with console)
e. DTO Layer
- CreateTransactionRequest, UpdateTransactionStatusRequest, ApiResponse (data contracts)
f. Model Layer
- Transaction entity, TransactionStatus enum

##### Relationships and interactions
- Clients → HTTP call → TransactionController
- Controller → maps JSON to DTOs → calls TransactionService
- Service → applies business logic & mock payment → calls TransactionRepository
- Repository → translates to SQL via JPA → H2 Database
- Database returns entities → Repository → Service → Controller wraps in ApiResponse → JSON back to client
- GlobalExceptionHandler intercepts exceptions at the controller boundary

##### Architectural patterns and design principles
- Layered (Controller → Service → Repository)
- Use of DTOs to decouple API contracts from internal model
- Centralized exception handling (@ControllerAdvice)
- Inversion of Control / Dependency Injection via Spring
- Repository pattern via Spring Data JPA
- Mock external dependency (payment processor) inside service layer

##### Technologies and frameworks
- Spring Boot (embedded Tomcat, autoconfiguration)
- Spring Web MVC (REST controllers)
- Spring Data JPA (repository abstraction)
- H2 Database (in-memory persistence)
- Jackson (JSON serialization)
- Jakarta Validation (request validation annotations)
- Maven (build and dependency management)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    Clients["External Clients"]:::external

    %% API Layer
    subgraph "API Layer"
        Controller["TransactionController"]:::api
        ExceptionHandler["GlobalExceptionHandler"]:::crosscutting
    end

    %% DTOs
    CreateReq["CreateTransactionRequest"]:::dto
    UpdateStatusReq["UpdateTransactionStatusRequest"]:::dto
    ApiResponse["ApiResponse"]:::dto

    %% Service Layer
    subgraph "Service Layer"
        Service["TransactionService"]:::service
        MockPayment["MockPaymentProcessor"]:::external
    end

    %% Data Layer
    subgraph "Data Layer"
        Repository["TransactionRepository"]:::repository
        subgraph "Database"
            H2["H2 Database"]:::database
            H2Console["H2 Console"]:::external
        end
    end

    %% Model Layer
    TransactionEntity["Transaction (Entity)"]:::model
    TransactionStatusEnum["TransactionStatus (Enum)"]:::model

    %% Flow
    Clients -->|"HTTP Request"| Controller
    Controller -->|"maps to DTO"| CreateReq
    Controller -->|"maps to DTO"| UpdateStatusReq
    Controller -->|"calls"| Service
    Service -->|"uses DTO"| CreateReq
    Service -->|"uses DTO"| UpdateStatusReq
    Service -->|"mock processing"| MockPayment
    Service -->|"calls"| Repository
    Repository -->|"persists Entity"| H2
    H2 -->|"returns Entity"| Repository
    Repository -->|"returns Entity"| Service
    Service -->|"builds"| ApiResponse
    Service -->|"returns"| Controller
    Controller -->|"HTTP Response (JSON)"| Clients
    ExceptionHandler -.->|"handles exceptions"| Controller

    %% Model associations
    Repository -->|"manages"| TransactionEntity
    Repository -->|"uses"| TransactionStatusEnum

    %% Click Events
    click Controller "https://github.com/yanrice/payment-transaction-spring-boot-application/blob/main/src/main/java/com/example/payment/controller/TransactionController.java"
    click ExceptionHandler "https://github.com/yanrice/payment-transaction-spring-boot-application/blob/main/src/main/java/com/example/payment/exception/GlobalExceptionHandler.java"
    click Service "https://github.com/yanrice/payment-transaction-spring-boot-application/blob/main/src/main/java/com/example/payment/service/TransactionService.java"
    click Repository "https://github.com/yanrice/payment-transaction-spring-boot-application/blob/main/src/main/java/com/example/payment/repository/TransactionRepository.java"
    click CreateReq "https://github.com/yanrice/payment-transaction-spring-boot-application/blob/main/src/main/java/com/example/payment/dto/CreateTransactionRequest.java"
    click UpdateStatusReq "https://github.com/yanrice/payment-transaction-spring-boot-application/blob/main/src/main/java/com/example/payment/dto/UpdateTransactionStatusRequest.java"
    click ApiResponse "https://github.com/yanrice/payment-transaction-spring-boot-application/blob/main/src/main/java/com/example/payment/dto/ApiResponse.java"
    click TransactionEntity "https://github.com/yanrice/payment-transaction-spring-boot-application/blob/main/src/main/java/com/example/payment/model/Transaction.java"
    click TransactionStatusEnum "https://github.com/yanrice/payment-transaction-spring-boot-application/blob/main/src/main/java/com/example/payment/model/TransactionStatus.java"
    click H2Console "https://github.com/yanrice/payment-transaction-spring-boot-application/blob/main/src/main/resources/application.properties"

    %% Styles
    classDef external fill:#eeeeee,stroke:#666,stroke-dasharray: 5 5
    classDef api fill:#b3cde0,stroke:#036
    classDef crosscutting fill:#d9d9d9,stroke:#999
    classDef dto fill:#fdd0a2,stroke:#e6550d
    classDef service fill:#c7e9c0,stroke:#31a354
    classDef repository fill:#fdae6b,stroke:#e6550d
    classDef database fill:#9ecae1,stroke:#3182bd
    classDef model fill:#dadaeb,stroke:#756bb1
```
