How rveggab/auth-api-service works
1. What this repository is
- A Spring Boot authentication/user-management service built with Maven.
- The code is organized in a hexagonal / ports-and-adapters style, separating web, application, domain, and persistence concerns.
2. Runtime entrypoint
- AuthApplication.java is the main bootstrap class.
- The app is run with Spring profiles, specifically dev and prod as documented in the README.
3. Inbound API boundary
- The main inbound adapter is the REST web layer under infrastructure.adapter.in.web.
- UserController exposes user-related endpoints and speaks only in request/response DTOs, not domain objects.
4. Request/response contract layer
- Incoming payloads are modeled as:
- UserRequest
- UpdateUserRequest
- UpdateUserAdminRequest
- Outgoing payloads are modeled as:
- UserDetailResponse
- BaseApiResponse
- This indicates the API layer is intentionally decoupled from the internal user model.
5. Application layer orchestration
- Use cases live in application.useCase:
- RegisterUserCase
- FindUserCase
- UpdateUserCase
- Input ports define the service contracts:
- LoginUserInPort
- RegisterUserInPort
- FindUserInPort
- UpdateUserInPort
- This is the business orchestration layer that coordinates validation, lookup, and persistence.
6. Domain model and business rules
- The core domain is centered on domain.model.identity.User.
- User state/roles are represented with enums:
- UserRoles
- UserStatus
- Domain-specific failures are expressed through:
- AuthException
- EntityAlreadyExistsException
- EntityNotFoundException
- InvalidDataException
7. Outbound persistence boundary
- The application layer depends on UserRepositoryOutPort, an abstract persistence contract.
- The infrastructure layer implements that contract through:
- UserPersistenceAdapter
- JpaUserAdapter
- This means the domain/application code is insulated from the concrete database mechanism.
8. Persistence model
- UserEntity in infrastructure.adapter.out is the persistence representation.
- The presence of a JPA adapter strongly suggests Spring Data JPA / ORM-backed storage, with mapping between UserEntity and the domain User.
9. Mapping between layers
- UserMapper and UserResponseMapper handle transformation across boundaries:
- request DTOs → domain model
- domain model → response DTOs
- domain model ↔ persistence entity
- This is a key architectural seam: controllers and repositories do not share internal models directly.
10. Cross-cutting infrastructure
- SecurityConfig defines application security behavior.
- CorsConfig controls cross-origin access.
- OpenApiConfig indicates API documentation generation.
- PasswordConfig suggests password hashing/encoding is centralized and injected rather than hardcoded.
11. Error handling path
- GlobalExceptionHandler centralizes translation of domain/application exceptions into API responses.
- This keeps controllers thin and ensures consistent error formatting for clients.
12. Primary data flow
- A request enters UserController → mapped to a request DTO or domain input → passed to a use case via an input port → the use case calls UserRepositoryOutPort → persistence adapter uses JPA/entity mapping → result returns back through mappers → controller returns a response DTO.
- Errors at any layer are normalized by GlobalExceptionHandler.
13. Project boundaries to keep in the diagram
- Web/API boundary: controllers, DTOs, exception handler.
- Application boundary: ports and use cases.
- Domain boundary: user model, enums, exceptions.
- Infrastructure boundary: security, CORS, OpenAPI, password config, JPA/persistence adapters.
14. Testing surface
- There is a basic application test (AuthApplicationTests), indicating at least bootstrapping validation is covered.
- No deeper test structure is visible from the tree, so the architecture is primarily described by package structure rather than a large test harness.
15. How to draw it
- Draw the system as a Spring Boot service with one main API surface for user/auth operations, an application core of use cases and ports, a domain core with user identity and rules, and infrastructure adapters for JPA persistence and HTTP/security concerns.
Main entry points: UserController.java User controller · User.java User · GlobalExceptionHandler.java Error handler · ApplicationConfig.java App config
Components 34
Bootstrap
Application entrypoint and smoke test
Web/API
HTTP boundary, DTOs, and exception translation
- User controller · Inbound HTTP API for user operations
src/main/java/io/github/rveggab/auth/infrastructure/adapter/in/web/controller/UserController.java - Error handler · Maps domain and application failures to API responses
src/main/java/io/github/rveggab/auth/infrastructure/adapter/in/web/handler/GlobalExceptionHandler.java - User request · Create-user inbound payload
src/main/java/io/github/rveggab/auth/infrastructure/adapter/in/web/dto/request/UserRequest.java - Update request · User update inbound payload
src/main/java/io/github/rveggab/auth/infrastructure/adapter/in/web/dto/request/UpdateUserRequest.java - Admin update · Privileged user update inbound payload
src/main/java/io/github/rveggab/auth/infrastructure/adapter/in/web/dto/request/UpdateUserAdminRequest.java - User detail · User details returned to clients
src/main/java/io/github/rveggab/auth/infrastructure/adapter/in/web/dto/response/UserDetailResponse.java - Base response · Common API response envelope
src/main/java/io/github/rveggab/auth/infrastructure/adapter/in/web/dto/BaseApiResponse.java
Application
Use cases and ports
- Register use case · Coordinates user registration
src/main/java/io/github/rveggab/auth/application/useCase/RegisterUserCase.java - Find use case · Coordinates user lookup
src/main/java/io/github/rveggab/auth/application/useCase/FindUserCase.java - Update use case · Coordinates user update flows
src/main/java/io/github/rveggab/auth/application/useCase/UpdateUserCase.java - Login port · Login service contract
src/main/java/io/github/rveggab/auth/application/ports/in/LoginUserInPort.java - Register port · Registration service contract
src/main/java/io/github/rveggab/auth/application/ports/in/RegisterUserInPort.java - Find port · User lookup service contract
src/main/java/io/github/rveggab/auth/application/ports/in/FindUserInPort.java - Update port · User update service contract
src/main/java/io/github/rveggab/auth/application/ports/in/UpdateUserInPort.java - Repo port · Persistence contract for users
src/main/java/io/github/rveggab/auth/application/ports/out/UserRepositoryOutPort.java
Domain
Core identity model and business failures
- User · Core identity aggregate
src/main/java/io/github/rveggab/auth/domain/model/identity/User.java - Roles · User role definitions
src/main/java/io/github/rveggab/auth/domain/model/enums/UserRoles.java - Status · User lifecycle states
src/main/java/io/github/rveggab/auth/domain/model/enums/UserStatus.java - Auth error · Base authentication failure
src/main/java/io/github/rveggab/auth/domain/exceptions/AuthException.java - Exists error · Duplicate entity failure
src/main/java/io/github/rveggab/auth/domain/exceptions/EntityAlreadyExistsException.java - Not found · Missing entity failure
src/main/java/io/github/rveggab/auth/domain/exceptions/EntityNotFoundException.java - Invalid data · Validation and data integrity failure
src/main/java/io/github/rveggab/auth/domain/exceptions/InvalidDataException.java
Infrastructure
Security, persistence, and external adapters
- App config · Core bean wiring
src/main/java/io/github/rveggab/auth/infrastructure/config/ApplicationConfig.java - Security · Authentication and authorization setup
src/main/java/io/github/rveggab/auth/infrastructure/config/SecurityConfig.java - CORS · Cross-origin policy
src/main/java/io/github/rveggab/auth/infrastructure/config/CorsConfig.java - OpenAPI · API documentation setup
src/main/java/io/github/rveggab/auth/infrastructure/config/OpenApiConfig.java - Password · Password encoder and hashing setup
src/main/java/io/github/rveggab/auth/infrastructure/config/PasswordConfig.java - Persistence adapter · Implements user repository port
src/main/java/io/github/rveggab/auth/infrastructure/adapter/in/user/UserPersistenceAdapter.java - JPA adapter · Database-facing persistence implementation
src/main/java/io/github/rveggab/auth/infrastructure/adapter/in/user/JpaUserAdapter.java - User entity · ORM-backed user record
src/main/java/io/github/rveggab/auth/infrastructure/adapter/out/UserEntity.java - User mapper · Transforms requests and entities to domain model
src/main/java/io/github/rveggab/auth/infrastructure/adapter/mapper/UserMapper.java - Response mapper · Transforms domain data to API responses
src/main/java/io/github/rveggab/auth/infrastructure/adapter/mapper/UserResponseMapper.java
Connections 39
- Auth app → User controller: starts · Bootstraps the web API and application context
- Boot test → Auth app: verifies · Confirms the application starts
- User controller → Register port: register · Delegates registration requests through the inbound port
- User controller → Find port: find · Delegates lookup requests through the inbound port
- User controller → Update port: update · Delegates update requests through the inbound port
- User controller → User mapper: maps · Converts inbound request DTOs to internal models
- User controller → Response mapper: renders · Converts internal results to response DTOs
- Error handler → Auth error: handles · Normalizes domain failures for the API
- Error handler → Exists error: handles · Normalizes duplicate-entity failures
- Error handler → Not found: handles · Normalizes not-found failures
- Error handler → Invalid data: handles · Normalizes invalid-data failures
- Register use case → Register port: implements · Backs the registration input contract
- Find use case → Find port: implements · Backs the lookup input contract
- Update use case → Update port: implements · Backs the update input contract
- Register use case → Repo port: uses · Reads and writes users through the repository abstraction
- Find use case → Repo port: uses · Reads users through the repository abstraction
- Update use case → Repo port: uses · Persists updates through the repository abstraction
- Repo port → Persistence adapter: adapts to · Implemented by the infrastructure persistence adapter
- Persistence adapter → JPA adapter: delegates · Bridges the port to the JPA layer
- JPA adapter → User entity: persists · Stores and loads ORM entities
- User mapper → User: maps · Converts between request/persistence data and the domain user
- User mapper → User entity: maps · Converts between domain user and persistence entity
- Response mapper → User: maps · Converts domain user data to API response models
- User → Roles: uses · Encodes role state
- User → Status: uses · Encodes lifecycle state
- User → Auth error: throws · Uses domain-specific failure types
- User → Exists error: throws · Uses domain-specific failure types
- User → Not found: throws · Uses domain-specific failure types
- User → Invalid data: throws · Uses domain-specific failure types
- App config → Security: wires · Central configuration loads security concerns
- App config → CORS: wires · Central configuration loads web policy
- App config → OpenAPI: wires · Central configuration loads API docs
- App config → Password: wires · Central configuration loads password encoding
- Security → Password: uses · Security depends on password encoding
- User controller → Base response: returns · Wraps endpoint responses in a shared envelope
- User controller → User request: accepts · Consumes create-user request payloads
- User controller → Update request: accepts · Consumes standard update payloads
- User controller → Admin update: accepts · Consumes admin update payloads
- User controller → User detail: returns · Produces user detail responses