This service is responsible for user management and authentication. It follows a clean/hexagonal architecture pattern with clear separation of concerns.
user_service/
├── src/
│ └── main/
│ └── java/
│ └── microservices/
│ └── user_service/
│ ├── application/
│ │ └── services/
│ │ ├── auth/
│ │ │ └── AuthService.java
│ │ └── user/
│ │ └── UserService.java
│ ├── domain/
│ │ ├── dto/
│ │ │ ├── auth/
│ │ │ │ ├── AuthRequestDTO.java
│ │ │ │ ├── AuthResponseDTO.java
│ │ │ │ └── RegisterRequest.java
│ │ │ └── user/
│ │ ├── exception/
│ │ │ └── UserNotFoundException.java
│ │ ├── mapper/
│ │ │ └── UserMapper.java
│ │ └── model/
│ ├── infrastructure/
│ │ ├── adapters/
│ │ │ ├── persistence/
│ │ │ │ ├── entity/
│ │ │ │ │ ├── AuthEntity.java
│ │ │ │ │ ├── UserEntity.java
│ │ │ │ │ └── UserRol.java
│ │ │ │ ├── mappers/
│ │ │ │ │ ├── AuthPersistenceMapper.java
│ │ │ │ │ └── UserPersistenceMapper.java
│ │ │ │ ├── repository/
│ │ │ │ │ ├── jpa/
│ │ │ │ │ │ ├── AuthJpaRepository.java
│ │ │ │ │ │ └── UserJpaRepository.java
│ │ │ │ │ ├── AuthRepositoryAdapter.java
│ │ │ │ │ └── UserRepositoryAdapter.java
│ │ │ └── rest/
│ │ │ └── controller/
│ │ │ ├── auth/
│ │ │ │ └── AuthController.java
│ │ │ ├── exception/
│ │ │ │ └── GlobalExceptionHandler.java
│ │ │ ├── responses/
│ │ │ │ └── ApiResponse.java
│ │ │ ├── security/
│ │ │ │ ├── jwt/
│ │ │ │ │ ├── JwtAuthenticationFilter.java
│ │ │ │ │ ├── JwtService.java
│ │ │ │ │ └── JwtValidationException.java
│ │ │ │ └── SecurityConfig.java
│ │ │ └── user/
│ │ │ └── UserController.java
│ │ └── security/
│ │ └── jwt/
│ │ ├── JwtAuthenticationFilter.java
│ │ ├── JwtService.java
│ │ ├── JwtValidationException.java
│ │ └── SecurityConfig.java
│ └── usecase/
│ └── port/
│ ├── in/
│ │ ├── AuthServicePort.java
│ │ └── UserServicePort.java
│ └── out/
│ ├── AuthRepositoryPort.java
│ └── UserRepositoryPort.java
└── UserServiceApplication.java
├── resources/
└── test/
Contains the core business logic and entities:
- dto: Data Transfer Objects for API requests and responses
- model: Domain entities
- exception: Custom exceptions like
UserNotFoundException - mapper: Object mappers like
UserMapperfor converting between entities and DTOs
Defines the interfaces for the application's use cases:
- port/in: Inbound port interfaces used by the application services
- port/out: Outbound port interfaces that application services use to interact with repositories
Contains the implementation of use cases:
- services/auth: Authentication-related business logic
- services/user: User management business logic
Handles external concerns:
- entity: Database entities (
UserEntity,AuthEntity,UserRol) - mappers: Persistence mappers (
UserPersistenceMapper,AuthPersistenceMapper) - repository/jpa: JPA repositories (
UserJpaRepository,AuthJpaRepository) - repository: Repository adapters (
UserRepositoryAdapter,AuthRepositoryAdapter)
- controller/auth: Authentication controller
- controller/user: User management controller
- controller/exception: Global exception handling through
GlobalExceptionHandler - controller/responses: Standardized API responses via
ApiResponse
- security/jwt: JWT implementation components
JwtAuthenticationFilter.java: Intercepts requests to validate JWT tokensJwtService.java: Handles JWT token generation and validationJwtValidationException.java: Custom exception for JWT validation errors
- SecurityConfig.java: Security configuration with Spring Security
- AuthController: Handles authentication and registration endpoints
- AuthService: Implements authentication logic
- SecurityConfig: Configures security settings and JWT token validation
- JwtService: Manages JWT token generation and validation
- UserController: Exposes user management endpoints
- UserService: Implements user management business logic
- UserMapper: Converts between domain models and DTOs
- UserNotFoundException: Custom exception for when users aren't found
- Entity Classes: Represent database tables (UserEntity, AuthEntity, UserRol)
- JPA Repositories: Spring Data interfaces for database operations
- Repository Adapters: Implement repository ports and use JPA repositories
- Persistence Mappers: Convert between domain and persistence models
- JWT Authentication: Complete implementation of JWT-based authentication
- Token generation and validation
- Authentication filters
- Custom exceptions for security issues
- Security Configuration: Spring Security setup with appropriate authorization rules
The service exposes REST APIs for:
- User registration
- User authentication
- User management (CRUD operations)
- Java
- Spring Boot
- Spring Security
- Spring Data JPA
- JWT for authentication
- Hexagonal Architecture pattern