Skip to content

BountyHunter Backend - Business Flow Overview

1. Mục tiêu tài liệu

Tài liệu này tổng hợp luồng nghiệp vụ chính của BountyHunter-Backend theo góc nhìn technical leader mới onboarding, bám theo source code thực tế trong các module web, authentication, websocket, webmarketplace, livestreamweb, batch, firebaselistener, admin, receiver-service.

2. Bức tranh tổng thể

flowchart LR
    Client[Mobile/Web Client] --> API["REST APIs\nweb/authentication/webmarketplace/livestreamweb"]
    Client --> WS["WebSocket\n/websocket/{token}"]
    AdminUI["Admin Portal"] --> AdminAPI["admin module\nport 8083"]

    API --> Core[application-core\nBusiness Services]
    WS --> Core
    AdminAPI --> Core

    Core --> DB[(MySQL)]
    Core --> Redis[(Redis)]
    Core --> MQ[(ActiveMQ Artemis)]
    Core --> Firebase[(Firebase RTDB)]

    MQ --> Batch[batch module\nJMS Listeners + Schedulers]
    Batch --> Core
    Batch --> Firebase

    FirebaseListener[firebaselistener module] --> Firebase
    FirebaseListener --> Core

    ControlServer[BountyHunter-ControlServer\nIoT Bridge] -->|"queue-control-server-gameplay\nqueue-control-server-health-check\nqueue-machine_history_log"| MQ
    MQ --> ReceiverSvc[receiver-service\nport 8088]
    ReceiverSvc --> Core
    ReceiverSvc --> Slack[(Slack Alerts)]

3. Luồng nghiệp vụ chính

Luồng Entry point Thành phần xử lý chính Kết quả
Authentication POST /api/auth/generate-code, POST /api/auth/sign-in AuthControllerLoginHandlerFactoryWeb3AuthLoginHandler/ImmutableLoginHandlerAuthService Tạo user/session, cấp JWT
Game room (PVE) WS command (CREATE_PVE_*, JOIN_PVE_*) RoomCmdConsumerCreateRoomService → Prize Allocation Queue → JMS listener → CreateRoomJMSService Tạo/join room, trừ tài nguyên
Matching & Matchmaking WS command JOIN_QUEUE_MATCH_MATCHING, JOIN_OPPONENT_POOL, SEND_INVITATION MatchMatchingCmdConsumer/OpponentPoolCmdHandler/InvitationCmdConsumer → queue chuyên biệt Ghép trận, pool đối thủ, mời chơi
Prize allocation Message vào queue-prize-allocation-* SendPrizeAllocationMessageService + nhóm listener JMS*AllocationListener Phân bổ/rollback prize theo loại
Payment & Marketplace webmarketplace APIs + webhook PaymentService (card/crypto/native/apple/google) + WebHookController Checkout, xác nhận thanh toán, cập nhật order
Livestream livestreamweb APIs + Firebase LivestreamController + LivestreamFirebaseService + gift aggregation (RedisBatch JMS) Đồng bộ lượt xem/gift/điểm/yell point
NFT management web + webmarketplace APIs NftHunterService, NftGauntletService, NftBountyBallService, NftRentalOrderService Quản lý inventory NFT + rental lifecycle
Batch & async ops Scheduler + JMS + Firebase listeners batch + firebaselistener Cleanup, reconciliation, archive, event-driven updates
Admin backoffice Admin portal REST APIs admin module: Machine/User/Event/NFT/Livestream/IoT/Dashboard controllers CRUD master data, manage machines, trigger batch, monitor KPIs
IoT machine telemetry JMS messages from ControlServer receiver-service: 3 JMS listeners Lưu machine logs, xử lý gameplay events từ crane machine, health-check

4. Luồng E2E tiêu biểu

4.1 Matchmaking (WS)

  1. Client gửi JOIN_QUEUE_MATCH_MATCHING tới WebSocket.
  2. CreateRoomService validate và route message sang queue prize allocation phù hợp (PRIZE / PRIZE_FOR_STREAMER / UNLIMITED).
  3. JMS*AllocationListener xử lý tuần tự theo queue, gọi UserMatchingService.
  4. Khi đủ điều kiện ghép trận, room được tạo và broadcast ngược về client qua pub/sub.

4.2 Mua NFT bằng native token

  1. Client gọi webmarketplace (/api/users/buy-nft/{productId} hoặc flow genesis).
  2. PaymentService ủy quyền PaymentNativeTokenService để tạo order/verify on-chain.
  3. Webhook/confirm endpoint cập nhật trạng thái order, ownership, inventory.

4.3 Livestream gift aggregation

  1. Gift events được cộng dồn trong Redis theo streamerId.
  2. GiftAggregationJob (batch) quét key, GETSET và đẩy message aggregate vào ActiveMQ (kèm JMSXGroupID=streamerId).
  3. JMSLivestreamViewerGiftFirebaseUpdateListener deposit B-Coin + update Firebase counters/WishOrb.

5. Mapping tài liệu chi tiết

Feature SPEC DESIGN PLAN
Authentication details/feature-authentication/SPEC.md DESIGN.md PLAN.md
Game & Room Management SPEC.md DESIGN.md PLAN.md
Matching & Matchmaking SPEC.md DESIGN.md PLAN.md
Prize Allocation SPEC.md DESIGN.md PLAN.md
Payment & Marketplace SPEC.md DESIGN.md PLAN.md
Livestream SPEC.md DESIGN.md PLAN.md
NFT Management SPEC.md DESIGN.md PLAN.md
Batch & Async Processing SPEC.md DESIGN.md PLAN.md
Admin Backoffice SPEC.md DESIGN.md PLAN.md
IoT Receiver Service SPEC.md DESIGN.md PLAN.md