Microservices Architecture
This document details the microservices architecture of HMP.
Service Overview
HMP is composed of several microservices, each handling a specific business domain.
Service Specifications
Auth Service
Purpose: Handle authentication and authorization
Endpoints:
POST /auth/login- User loginPOST /auth/refresh- Refresh access tokenPOST /auth/logout- User logoutGET /auth/me- Get current user
Events Published:
user.logged_inuser.logged_outpassword.changed
Reservation Service
Purpose: Manage reservations and availability
Endpoints:
GET /reservations- List reservationsPOST /reservations- Create reservationPUT /reservations/:id- Update reservationDELETE /reservations/:id- Cancel reservationGET /availability- Check availability
Events Published:
reservation.createdreservation.modifiedreservation.cancelled
Events Consumed:
room.status_changedrate.updated
Front Desk Service
Purpose: Handle check-in/out and room operations
Endpoints:
POST /checkin/:reservationId- Check in guestPOST /checkout/:roomId- Check out guestPOST /room-move- Move guest to another roomGET /arrivals- List today's arrivalsGET /departures- List today's departures
Events Published:
guest.checked_inguest.checked_outroom.assigned
Housekeeping Service
Purpose: Manage room cleaning and status
Endpoints:
GET /rooms/status- Get all room statusesPUT /rooms/:id/status- Update room statusGET /tasks- List housekeeping tasksPOST /tasks- Create cleaning task
Events Published:
room.cleanedroom.inspectedroom.out_of_order
Events Consumed:
guest.checked_out
POS Service
Purpose: Restaurant and outlet operations
Endpoints:
GET /orders- List ordersPOST /orders- Create orderPUT /orders/:id- Update orderPOST /orders/:id/settle- Settle billPOST /orders/:id/transfer- Transfer to room
Events Published:
order.createdorder.settledcharge.posted
Inter-Service Communication
Synchronous (HTTP/REST)
Used for real-time operations requiring immediate response:
// Example: Front Desk calling Reservation Service
const reservation = await axios.get(
`${RESERVATION_SERVICE}/reservations/${id}`
);
Asynchronous (Message Queue)
Used for event-driven operations:
// Publishing an event
await messageQueue.publish('reservation.created', {
reservationId: 'res_123',
guestId: 'guest_456',
arrival: '2026-02-15'
});
// Subscribing to events
messageQueue.subscribe('guest.checked_out', async (event) => {
await createCleaningTask(event.roomId);
});
Service Discovery
Services register with a service registry and discover each other dynamically:
services:
reservation:
host: reservation-service
port: 3001
frontdesk:
host: frontdesk-service
port: 3002
housekeeping:
host: housekeeping-service
port: 3003
Circuit Breaker Pattern
Services implement circuit breakers to handle failures gracefully:
const breaker = new CircuitBreaker(callReservationService, {
timeout: 3000,
errorThresholdPercentage: 50,
resetTimeout: 30000
});
Data Ownership
Each service owns its data and exposes it via APIs:
| Service | Owned Data |
|---|---|
| Reservation | Reservations, Availability |
| Guest | Guest profiles, Preferences |
| Housekeeping | Room status, Tasks |
| POS | Orders, Menu items |
Deployment
Each service is deployed as a container:
# docker-compose.yml
services:
reservation-service:
image: hmp/reservation-service:latest
ports:
- "3001:3000"
environment:
- DATABASE_URL=postgresql://...
frontdesk-service:
image: hmp/frontdesk-service:latest
ports:
- "3002:3000"