Source document
docs/platform/BOOKING-FLOW.md
Source version
0.0.0
Generated time
2026-07-06T14:59:22.616Z
Owner
Unassigned
Audience
Internal
Status
Approved

BOOKING FLOW — Vertical Slice đầu tiên (Stage Beta-1)

Lifecycle luồng đặt chỗ hoàn chỉnh, đã hiện thực + verify tự động ([booking-e2e.test.ts]). Tổng hợp từ code thật — không thiết kế lại. Engine: platform-architecture/CORE-ENGINES-BOUNDARY; ranh giới: platform-contracts/ENGINE-INTERACTION-MATRIX.

Luồng

Partner ─▶ Inventory ─▶ Availability ─▶ Pricing ─▶ Booking ─▶ Audit ─▶ Database ─▶ API Response

Từng bước (engine + code)

BướcEngine / codeVàoRa
Partner → InventoryseedStagingListings (Partner publish listing/unit) → listings/units/availability/priceslisting/unit/giá/tồnReservable sẵn bán
AvailabilityCheckAvailability use-case → AvailabilityRepository (adapter SELECT…FOR UPDATE); invariant Availability.canReserve (domain)unitId, period, quantityavailable, billableUnits
PricingPricingPort.unitPricePrismaPricingAdapter (snapshot bất biến)unit, periodunitPriceVnd, totalVnd
BookingCreateReservation use-case → Reservation aggregate (state machine pending)request + availability + price snapshotreservationId, code, totalVnd, status=pending
AuditKernel ctx.audit.record("reservation.created")cùng transaction (atomic)actor/tenant/entityRefaudit_events append-only
DatabasePrismaReservationRepository.savereservations + outbox booking.reservation.created (transactional)aggregate + eventspersisted atomic
API ResponserouterReservationView / ReservationListResult (email mask, cursor)JSON contract v1

Vòng đời trạng thái (Reservation)

pending ─▶ confirmed ─▶ checked_in ─▶ checked_out
   │           │
   ▼           ├─▶ cancelled
cancelled      └─▶ no_show

HTTP endpoints (đã có)

Method · PathVai trò
GET /healthLiveness (không auth)
GET /api/booking/availability?unitId&start&end&quantity&adults&childrenAvailability + Pricing (server suy listingId từ unitId)
POST /api/booking/reservationsBooking (create); body unitId,start,end,adults,children,quantity,channel,guestName/Email/Phone
GET /api/booking/reservationsList (tenant-scoped, keyset, email mask)
POST /api/booking/reservations/:id/{confirm,cancel,check-in,check-out,no-show}Lifecycle
Auth: x-bng-api-key (production mode); không key → 401. Cross-tenant → 404. Không lộ stack/secret.

Bất biến (guardrail trong luồng)

Verify tự động

packages/platform-infrastructure/src/__tests__/booking-e2e.test.ts (3 test): full slice · confirm→payment→audit · availability trừ tồn. 0× 5xx, response đúng contract. Demo tay: demo/BOOKING-DEMO.