The Repository system manages data persistence and business logic orchestration using a reactive, non-blocking architecture.
- Purpose: Direct interaction with the MySQL database.
- Technology: Vert.x MySQL Client (Reactive).
- Key Features:
- Uses a
Poolfor asynchronous connection management. - Configuration: Dynamic connection to
DB_HOSTandDB_PORT(Default:localhost:3306). - Prepared queries for SQL injection prevention.
- Soft-delete implementation (marking records as inactive).
- Mapping of SQL
RowSettoEmployeeDTO. - Initialization: Database schema is automatically seeded via
init.sqlon container startup.
- Uses a
- Purpose: Acts as a worker verticle that isolates data access from the web layer.
- Deployment: Deployed sequentially before the
HttpVerticleto ensure the Event Bus consumers are ready. - Flow:
- Listens for messages on the Vert.x Event Bus (e.g.,
employees.get.all,employees.create). - Batch Processing: Handles
employees.create.batchfor concurrent creation of multiple records. - Orchestrates calls to the
EmployeeService. - Returns responses or fails messages back to the requester.
- Listens for messages on the Vert.x Event Bus (e.g.,
- Resilience: Configures a
CircuitBreakerto protect database operations. - Connection Pool: Initializes a
PoolwithsetMaxSize(10). - Logging: Adopts standard SLF4J logging for deployment and operational status.
- Purpose: Manages user authentication and credential verification.
- Security: Offloads CPU-intensive
BCryptpassword hashing to a blocking executor to prevent event loop blocking. - Flow:
- Listens on
users.authenticate. - Deserializes message to
LoginRequestDTO. - Retrieves user from
UserRepository. - Verifies password hash.
- Returns
UserContextDTO(username, role) on success or fails withUNAUTHORIZED.
- Listens on
- Purpose: Domain entity representing a system user.
- Fields:
username,password_hash,id.
- Purpose: Data access for the
userstable. - Queries:
findByUsernameto fetch credentials safely using prepared statements.
- Purpose: Data Transfer Object representing an employee.
- Design Pattern: Builder Pattern.
- Provides a fluent API for object creation.
- Eliminates positional ambiguity for its 7 parameters (
id,name,department,salary,active,lastModifiedBy,lastModifiedAt).
- Audit Support: Automatically tracks
lastModifiedByandlastModifiedAtduring mutations. - Usage: Exclusively used by the Web Layer (
EmployeeController) via the Builder to ensure all mutation requests are type-safe and contain necessary audit trails. - Features: Includes
toJson()andfromJson()for seamless Vert.x JSON integration.
- Purpose: Contains business logic and validation rules.
- Logic:
- Validates DTO fields before persistence.
- Batch Support: Processes lists of employees concurrently using
CompositeFuture. - Handles conflict detection (e.g., preventing duplicates or reactivating soft-deleted records).
- Wraps repository calls in circuit breaker execution blocks.
The Repository system is completely decoupled from the Web layer via the Vert.x Event Bus.
sequenceDiagram
participant Web as HttpVerticle/Controller
participant EB as Event Bus
participant RepV as EmployeeVerticle
participant Service as EmployeeService
participant DB as MySQL
Web->>EB: request("employees.get.all")
EB->>RepV: consume("employees.get.all")
RepV->>Service: getAllEmployees()
Service->>DB: query("SELECT...")
DB-->>Service: RowSet
Service-->>RepV: List<EmployeeDTO>
RepV-->>EB: reply(JsonArray)
EB-->>Web: onSuccess(msg)
Database interactions are guarded by a CircuitBreaker configured in EmployeeVerticle.
- Threshold: 5 consecutive failures.
- Timeout: 200ms per operation (tuned for high responsiveness).
- Reset: Attempts recovery after a short reset period.