Skip to content

Battery Swap Service (BSS) - Model Status

Last Updated: October 2025 - Service Payment Documentation and Implementation Blueprint Model Phase: Implementation Complete - FSM Signal Compression + Agent Architecture v2 + Payment Blueprint Ready Integration Status: โœ… Ready for DIRAC Integration with Payment Enhancement Blueprint Schema Status: โœ… Fully Aligned with Service-Specific Payment Event Documentation Signal Architecture: โœ… FSM Signal Compression Implemented - External signal compression with fundamental FSM inputs Payment Enhancement: ๐Ÿ”ง Service Payment Blueprint Ready - Documentation and implementation guide completed, awaiting clean agent implementation MQTT Pattern: โœ… Payment Coordination Patterns Documented - Service-specific payment topics and top-up event patterns defined

๐Ÿ” Terminology Note

BSS (Battery Swap Service) refers to the service model in this repository, defining operational and technical implementation (workflows, FSMs, agents).

Participants in the BSS ecosystem include: - BCS (Battery Circulation Service): Asset provider managing battery assets - SNS (Swap Network Service): Network operator managing stations and customers

Financial modeling of BCS and SNS as business units is handled separately in the BUFM (Business Unit Financial Model) framework.

Architecture Overview

โœ… Service-Specific Payment Enhancement

Key Innovation: Enhanced payment processing for multi-service bundles with separate ledger tracking

Service Payment Allocation

  • Service-Specific Payments: Payments must specify target service since ServicePlan contains multiple bundle services
  • Quota Calculation: Payment amount divided by unit price determines quota increment
  • Payment Event Structure: Complete payment allocation details with service targeting
  • MQTT Coordination: emit/abs/bss/payment/{plan_id}/service_payment pattern

Top-up as Service Events

  • Service Event Recording: Top-ups recorded as separate service events representing "I have topped up your service by this amount"
  • Separate Ledger Entries: Payment events and service events maintained in separate ledgers
  • Quota Management: Real-time quota updates with before/after tracking
  • Service Event Topics: emit/abs/bss/service/{service_id}/topup_applied pattern

Implementation Status

  • โœ… Workflow Documentation Enhanced: Service payment structures defined in bss-serviceState-workflow.md
  • โœ… Blueprint Created: Developer implementation guide in service-payment-implementation-blueprint.md
  • โœ… Function Specifications: processServiceSpecificPayment and recordTopupServiceEvent specifications defined
  • ๐Ÿ”ง Agent Implementation: Blueprint ready for developer clean implementation (compilation issues require cleanup first)

โœ… FSM Signal Compression Architecture

Key Principle: Service agent compresses "noisy external signals" to fundamental signals and state transitions, NOT pass them into FSMs.

Fundamental FSM Inputs (8 signals)

  • Service Cycle: DEPOSIT_CONFIRMED, BATTERY_ISSUED, BATTERY_RETURNED, BATTERY_LOST, BATTERY_FOUND, SERVICE_CANCELLED, ASSET_SETTLEMENT_COMPLETE, CONTINUE_SERVICE_REQUESTED
  • Payment Cycle: CONTRACT_SIGNED, DEPOSIT_PAID, RENEWAL_PAID, SUBSCRIPTION_EXPIRED, QUOTA_EXHAUSTED, FINAL_PAYMENT_DUE, FINAL_PAYMENT_PAID

External Signal Compression

Service agent processes complex external events (W1-W5 workflows, MQTT, Odoo, personnel validation) and compresses them into fundamental FSM inputs, maintaining O(1) FSM performance while providing rich operational signals for external systems.

โœ… W1-W5 Rider Workflow Implementation

Functions: getRequiredAssetIds, emitServiceIntentSignal, bindCustomerToLocation, sendAssetAllocationSignal, updateServiceStatesAndBilling

Key Features: - W1: Fleet dependency resolution โ†’ returns fleet IDs for ARM microservice - W2: Service intent MQTT emission โ†’ customer/location notification
- W3: Customer-location binding โ†’ session establishment - W4: Fleet allocation signals โ†’ ARM handles asset-specific allocation - W5: Service state updates โ†’ battery assignments, quota tracking, billing

Architecture Compliance: BSS Agent works with fleet IDs only; ARM resolves to specific assets

Key Corrections Applied: - Before: BSS Agent returned specific asset IDs (cabinet_001, station_002) - After: BSS Agent returns fleet IDs (fleet-swap-stations-nairobi) โ†’ ARM resolves to specific assets - Result: Proper separation of concerns, scalability, flexibility, maintainability

โœ… Enhanced Agent Architecture v2

  • Single Delegation Function: serviceAgent as unified entry point
  • Signal Compression: Agent handles external complexity, emits fundamental FSM signals
  • Centralized State Management: AgentStateManager for type-safe operations
  • Model-Confined Types: BSSAgentState interface within agent module
  • Registry Compatibility: Maintains functional dependency injection pattern

๐Ÿ“‹ Implementation Status

โœ… FSM Architecture - Payment cycle (7 inputs) + Service cycle (8 inputs) with fundamental signal compression โœ… Enhanced Agent v2 - Single delegation function with centralized state management
โœ… W1-W5 Rider Workflow - Complete implementation with ABS-ARM boundary compliance โœ… Schema Aligned - All setup data matches corrected GraphQL schema โœ… Documentation Updated - All diagrams and docs reflect signal compression architecture

๐Ÿ”„ BSS Workflow Summary

Workflow Purpose Key Functions Implementation Status Documentation
Service State Workflow Core service state management logic Service initialization, consumption tracking, availability checks, quota management, service payment documentation โœ… Complete + Payment Blueprint bss-serviceState-workflow.md
Rider Workflow (W1-W5) End-to-end customer service journey Asset discovery, intent signaling, location binding, service execution โœ… Complete + Polished bss-rider-workflow.md
Attendant Workflow (A1-A4) Station personnel service delivery Customer identification, validation processes, service operations, activity reporting โœ… Complete + Polished bss-attendant-workflow-enhanced.md
Operator Workflow Station management and customer coordination Station readiness, service monitoring, customer support, asset operations ๐Ÿ”„ In Progress bss-operator-workflow.md
Asset Manager Workflow Strategic fleet management and optimization Fleet analytics, lifecycle management, deployment strategy, energy optimization ๐Ÿ“‹ Planned bss-assetManager-workflow.md
Odoo Billing Sync ABS-Odoo billing synchronization Payment state sync, subscription lifecycle, usage reporting, payment status queries โœ… Complete + Enhanced bss-odooBillingSync-workflow.md
ARM IoT Sync IoT signal processing and device coordination Signal compression, device monitoring, hub-spoke communication โœ… Complete + Polished bss-armIoTSync-workflow.md

Workflow Implementation Details

โœ… Implemented Workflows

  • Service State Workflow: Bundle AND logic, quota management, infinity quota support, enhanced with service payment documentation and implementation blueprint
  • Rider Workflow: W1-W5 functions with MQTT signals and ARM integration + polished with business intent focus
  • Attendant Workflow: A1-A4 functions for complete station personnel workflow with customer identification, validation processes, service operations, and activity reporting + polished with business intent focus
  • Odoo Billing Sync: Federation-based integration with domain isolation + enhanced payment queries and usage reporting
  • ARM IoT Sync: Signal compression pattern with hub-spoke architecture + polished with business intent focus

๐Ÿ”„ In Progress

  • Operator Workflow: OP1-OP6 functions for station management and customer service
  • Station readiness management and MQTT broadcasting
  • Service intent monitoring and customer coordination
  • Asset operations and performance monitoring

๐Ÿ“‹ Planned

  • Asset Manager Workflow: AM1-AM6 functions for strategic fleet management
  • Fleet performance analytics and lifecycle management
  • Strategic deployment and energy optimization
  • Financial management and fleet rebalancing operations

๐Ÿ“ BSS File Organization

models/bss/
โ”œโ”€โ”€ bss-agent-v2.ts                    # โœ… Enhanced functional agent
โ”œโ”€โ”€ bss-agent-config-v2.json           # โœ… Shared agent configuration
โ”œโ”€โ”€ bss-agent-versions.json            # โœ… Agent version tracking
โ”œโ”€โ”€ bss-fsm-v1.json                    # โœ… Clean FSM (8 fundamental signals)
โ”œโ”€โ”€ model-status.md                    # โœ… This file - BSS model status
โ””โ”€โ”€ README.md                          # โœ… BSS overview

design-intent/                         # Business specifications
โ”œโ”€โ”€ bss-business-logic.md              # Business case and rules
โ”œโ”€โ”€ bss-technical-specs.md             # Technical implementation spec
โ”œโ”€โ”€ bss-rider-workflow.md              # W1-W5 workflow functions
โ”œโ”€โ”€ bss-serviceState-workflow.md       # Service payment and consumption tracking
โ”œโ”€โ”€ service-payment-implementation-blueprint.md # Developer payment implementation guide
โ””โ”€โ”€ bss-scenario-tests.md              # Test scenarios

setup-data/                            # Market-specific configuration (see setup-data/README.md)
โ”œโ”€โ”€ README.md                          # Setup data organization, naming conventions, entity hierarchy
โ”œโ”€โ”€ Kenya_Nairobi/                     # Nairobi market (v2, production)
โ””โ”€โ”€ Togo_Lome/                         # Lome market (v1, ready for deployment)

diagrams/                              # Visual models
โ”œโ”€โ”€ battery-swap-service-cycle.puml
โ””โ”€โ”€ battery-swap-fsm-interaction.puml

example-data/                          # Sample data for testing
โ””โ”€โ”€ tests/                             # Test scenarios and cases

For detailed setup data organization, naming conventions, and entity hierarchy, see setup-data/README.md

๐Ÿ”„ Dependencies

Architecture Foundations: Architecture Overview - fsm-signal-compression.md - FSM signal compression principles - mqtt-integration.md - MQTT integration guidelines

Platform Architecture: Architecture Overview - Overall ABS platform architecture

๐ŸŽฏ Current Status

โœ… Implementation Complete - All core functions, FSM signal compression, enhanced service-specific payment processing, and top-up ledger implementation โœ… Payment Blueprint Ready - Service-specific payment documentation and developer implementation guide completed โœ… Blueprint Created - Developer implementation guide ready for clean payment function implementation โœ… Attendant Workflow Complete - A1-A4 functions implemented with comprehensive MQTT patterns, timeout/retry mechanisms, and Validator Array Pattern โœ… Service State Workflow Enhanced - Expanded with service-specific payment events, top-up ledger, and consumption tracking โœ… Naming Convention Enforced - All workflow files follow bss-[function]-workflow.md pattern with single camelCase words โœ… Schema Aligned - All setup data matches corrected GraphQL schema with payment event structures โœ… Documentation Consolidated - Centralized in model-status.md and architecture docs โœ… DIRAC Ready - Proper component boundaries with ARM integration and enhanced payment coordination โœ… MQTT Payment Patterns - Service-specific payment topics and top-up event coordination implemented โœ… Workflow Documentation Polished - Applied four-principle approach with enhanced payment processing specifications

Next Phase: Service-specific payment function implementation and operator workflow (OP1-OP6)


BSS Status: โœ… SERVICE PAYMENT BLUEPRINT + TOP-UP DOCUMENTATION + IMPLEMENTATION GUIDE READY Next Milestone: Clean Payment Function Implementation + Agent Code Cleanup

For platform-level architecture and infrastructure information, see Architecture Overview.