How yanrice/payment-transaction-spring-boot-application works
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)