How ebron-sasack/buynow-user-service works
Purpose and Runtime
BuyNow User Service is a Java 21 Spring Boot microservice for customer profiles and multiple user addresses. Its executable entry point is src/main/java/com/buynow/user_service/UserServiceApplication.java; runtime settings, including relational-database connectivity, belong in src/main/resources/application.properties. Maven build/dependency management is defined by pom.xml.
HTTP/API Boundary
Spring MVC controllers expose the user and address REST boundary:
• src/main/java/com/buynow/user_service/controller/UserController.java
• src/main/java/com/buynow/user_service/controller/AddressController.java
The documented flow covers retrieval and updates for /api/v1/users/{id}, plus creation and listing of /api/v1/users/{id}/addresses. src/main/java/com/buynow/user_service/configuration/WebConfig.java is the web-layer configuration boundary.
Request and Response Contracts
Controllers accept purpose-specific mutation DTOs rather than persistence entities:
• src/main/java/com/buynow/user_service/dto/request/CreateUserRequest.java
• src/main/java/com/buynow/user_service/dto/request/UpdateUserRequest.java
• src/main/java/com/buynow/user_service/dto/request/CreateAddressRequest.java
Responses are projected through src/main/java/com/buynow/user_service/dto/response/UserResponse.java and src/main/java/com/buynow/user_service/dto/response/AddressResponse.java, separating public API representation from JPA storage models.
Domain Model
The core persistent aggregate is user profile data in src/main/java/com/buynow/user_service/entity/User.java, with associated addresses in src/main/java/com/buynow/user_service/entity/Address.java. Address classification is represented by src/main/java/com/buynow/user_service/enums/AddressType.java. The tree also contains src/main/java/com/buynow/user_service/entity/SellerApplication.java and its lifecycle enum src/main/java/com/buynow/user_service/enums/ApplicationStatus.java, indicating a seller-application domain model, though no corresponding controller/service/repository is present.
Application-Service Layer
Business orchestration is defined through service interfaces and implementations:
• src/main/java/com/buynow/user_service/service/UserService.java
• src/main/java/com/buynow/user_service/service/implementation/UserServiceImpl.java
• src/main/java/com/buynow/user_service/service/implementation/AddressServiceImpl.java
Primary control flow is controller → service → repository → relational database. Services own user existence checks, profile/address updates, relationship handling, and conversion between request/entity/response shapes.
Persistence Boundary
Spring Data JPA repositories isolate database access:
• src/main/java/com/buynow/user_service/repository/UserRepository.java
• src/main/java/com/buynow/user_service/repository/AddressRepository.java
The service is designed for MySQL or PostgreSQL, selected/configured externally through application properties. Entity classes are the JPA mapping boundary; clients do not directly receive them.
Error and API Envelope Handling
Domain and validation failures are represented by typed exceptions such as src/main/java/com/buynow/user_service/exception/ResourceNotFoundException.java and src/main/java/com/buynow/user_service/exception/AlreadyExistsException.java. src/main/java/com/buynow/user_service/exception/GlobalExceptionHandler.java centralizes their HTTP translation. Shared success/error payload types reside in src/main/java/com/buynow/user_service/payload/ApiResponse.java and src/main/java/com/buynow/user_service/payload/ErrorResponse.java.
Main entry points: UserController.java User REST controller · AddressController.java Address REST controller · UserServiceImpl.java User service · AddressServiceImpl.java Address service
Components 19
Runtime
- Spring Boot application
src/main/java/com/buynow/user_service/UserServiceApplication.java - Maven build
pom.xml - Runtime settings · Configures relational database connectivity.
src/main/resources/application.properties
HTTP API
- Web configuration
src/main/java/com/buynow/user_service/configuration/WebConfig.java - User REST controller · Handles profile retrieval and updates.
src/main/java/com/buynow/user_service/controller/UserController.java - Address REST controller · Handles user address creation and listing.
src/main/java/com/buynow/user_service/controller/AddressController.java - Global exception handler · Maps typed domain failures to API errors.
src/main/java/com/buynow/user_service/exception/GlobalExceptionHandler.java - API response envelopes · Shared success and error payloads.
src/main/java/com/buynow/user_service/payload/ApiResponse.java
Application Services
- User service contract
src/main/java/com/buynow/user_service/service/UserService.java - User service · Orchestrates profile operations and mappings.
src/main/java/com/buynow/user_service/service/implementation/UserServiceImpl.java - Address service · Owns address relationship handling and mappings.
src/main/java/com/buynow/user_service/service/implementation/AddressServiceImpl.java
Domain & Contracts
- Mutation request DTOs · Create/update user and create address inputs.
src/main/java/com/buynow/user_service/dto/request/CreateUserRequest.java - Response DTOs · Public user and address projections.
src/main/java/com/buynow/user_service/dto/response/UserResponse.java - User profile
src/main/java/com/buynow/user_service/entity/User.java - Address · Classified by address type.
src/main/java/com/buynow/user_service/entity/Address.java - Seller application · Present domain model without an exposed application flow.
src/main/java/com/buynow/user_service/entity/SellerApplication.java
Persistence
- User repository
src/main/java/com/buynow/user_service/repository/UserRepository.java - Address repository
src/main/java/com/buynow/user_service/repository/AddressRepository.java - MySQL or PostgreSQL · Selected through runtime properties.
Connections 26
- Maven build → Spring Boot application: builds
- Runtime settings → Spring Boot application: configures
- Spring Boot application → Web configuration: starts MVC
- Web configuration → User REST controller: configures
- Web configuration → Address REST controller: configures
- User REST controller → Mutation request DTOs: accepts
- Address REST controller → Mutation request DTOs: accepts
- User REST controller → User service contract: delegates to
- User service contract → User service: implemented by
- Address REST controller → Address service: delegates to
- User service → User repository: loads and saves
- User service → Address repository: updates addresses
- Address service → User repository: checks user
- Address service → Address repository: loads and saves
- User repository → User profile: maps
- Address repository → Address: maps
- User profile → Address: has addresses
- User repository → MySQL or PostgreSQL: persists to
- Address repository → MySQL or PostgreSQL: persists to
- User service → Response DTOs: projects to
- Address service → Response DTOs: projects to
- User REST controller → Response DTOs: returns
- Address REST controller → Response DTOs: returns
- Global exception handler → API response envelopes: produces errors
- User REST controller → Global exception handler: failures handled by
- Address REST controller → Global exception handler: failures handled by