How isaacafrifa/user-service works
Main Components
• BookMe User Service Application: The central microservice implemented in Java Spring Boot.
• API/Controller Layer: The UserController and the REST API endpoints through which client requests are received.
• Service Layer: Contains business logic (UserService, UserValidationService) and orchestrates interactions between components.
• Persistence Layer: The UserRepository along with the database interactions to a PostgreSQL database (configured with migration scripts in src/main/resources/db/migration).
• Configuration Components: A collection of configuration classes for CORS, RabbitMQ, Hazelcast caching (CacheConfig, CacheListener), observation/tracing, etc.
• Messaging System: Integration with RabbitMQ (as seen with CustomMessage, RabbitMQConfig) for event-driven communication (for example, publishing events like UserEmailUpdatedEvent).
• Caching: Hazelcast configuration is used for improved performance (hazelcast.yaml and hazelcast-prod.yaml).
• External Integrations and Observability:
• Test containers and automated tests for integration validation.
• Logging (logback-spring.xml), distributed tracing (Micrometer), Prometheus for monitoring, and Loki for log aggregation.
• Deployment and Orchestration:
• Docker Compose, Kubernetes manifests (in the k8s folder), and Maven build support with spring-boot and cloud-native buildpacks along with a Dockerfile.
• automation scripts like mvnw and the Maven Wrapper.
Relationships and Data Flow
• Incoming HTTP Requests are handled by the UserController, which forwards them to the business logic layer (UserService).
• The Service Layer processes business rules and interacts with the persistence layer by calling the UserRepository to read/write user data from PostgreSQL.
• For caching, after data is processed or fetched, the CacheConfig (and listeners) help cache responses using Hazelcast.
• When significant changes occur (for example, a user’s email update), an event such as UserEmailUpdatedEvent is published through RabbitMQ (configured by RabbitMQConfig and using CustomMessage) to notify other parts of the application.
• Exception Handling: Application-wide exceptions are managed by the ExceptionController and specific exception classes to ensure robust error handling.
• Observability and Metrics: The ObservationConfig along with Micrometer tracing, Prometheus, and Loki log management capture metrics and monitor application health.
• The project also includes infrastructure scripts/configuration for Kubernetes and Docker Compose, which help in deploying the service, along with a Cloud-Native build approach.
Incorporate Architectural Patterns and Design Principles
• Layered Architecture: Clearly separate Controllers, Services, Repositories, and Configuration.
• Event-Driven Communication: Use the RabbitMQ configuration to decouple components.
• DevOps and Cloud-Native Practices: Containerization with Docker, automated database migrations with Flyway, and orchestrations with Kubernetes.
• Observability and Resilience: Integration with monitoring and distributed tracing tools for robust production support.