Skip to content

Schema Alignment Developer Guide

Overview

This guide documents the schema corrections applied to the ABS Platform and provides guidance for developers working with the updated GraphQL schema and setup data.

โœ… Schema Corrections Applied

1. Currency Architecture Redesign

Problem: Currency definition was split inconsistently between template and plan levels.

Solution Applied:

# ServicePlanTemplate (NEW)
type ServicePlanTemplate {
  country_code: String!
  legal_jurisdiction: String!
  billing_currency: String!    # โœ… NEW: Currency defined at template level
  # ... other fields
}

# ServicePlan (UPDATED) 
type ServicePlan {
  # REMOVED: currency field - now derived from template.billing_currency
  # currency: String!
  # ... other fields
}

Developer Impact: - โœ… All currency information derives from template.billing_currency - โœ… ServicePlan resolvers must access currency via template reference - โœ… Setup data templates must include billing_currency field

2. CommonTerms Field Cleanup

Problem: monthly_quota field was conceptually invalid at template level.

Solution Applied:

type CommonTerms {
  service_name: String!
  service_description: String!
  billing_cycle: String!
  monthly_fee: Float!
  deposit_amount: Float!

  # REMOVED: monthly_quota field - conceptually invalid
  # monthly_quota: Float!

  cancellation_notice_days: Int!
  # ... other fields
}

Developer Impact: - โœ… Setup data files remove monthly_quota from all CommonTerms instances - โœ… Quota management handled at ServiceState level within bundles - โœ… Individual services define usage quotas, not template-level global quota

3. CommonState Redundancy Elimination

Problem: Multiple fields duplicated data from other entities.

Solution Applied:

type CommonState {
  status: String!
  last_billed_at: DateTime
  next_bill_at: DateTime

  # REMOVED: Redundant fields that duplicate other entity data
  # billing_balance: Float!      # Duplicated PaymentAccount.balance
  # total_services: Int!         # Can be computed from service_states.length
  # active_services: Int!        # Can be computed from service_states
}

Developer Impact: - โœ… Use PaymentAccount.balance for all balance operations - โœ… Compute service counts dynamically from ServiceAccount.service_states arrays - โœ… Remove redundant fields from all setup data plan_state objects

4. AgentConfig Version Consolidation

Problem: Duplicate version fields created confusion.

Solution Applied:

type AgentConfig {
  id: ID!
  name: String!
  version: String!               # โœ… Single authoritative version field
  description: String!
  agent_type: String!

  # REMOVED: Duplicate version field
  # agent_version: String!

  agent_params: JSON @domainSpecific
  # ... other fields
}

Developer Impact: - โœ… Use single version field for all agent versioning - โœ… Remove agent_version from setup data and inputs - โœ… Update agent configuration references to use consolidated versioning

5. ServiceAccount Data Structure Cleanup

Problem: usage_summary field duplicated structured data.

Solution Applied:

type ServiceAccount {
  id: ID!
  status: String!
  service_bundle: ServiceBundle!
  service_states: [ServiceState!]!    # โœ… Structured usage data
  service_history: [ServiceAction!]!

  # REMOVED: Redundant summary field
  # usage_summary: JSON!              # Duplicated service_states data

  created_at: DateTime!
  updated_at: DateTime!
}

Developer Impact: - โœ… Query service_states for all usage information - โœ… Compute usage summaries dynamically from structured data - โœ… Remove usage_summary from all setup data service accounts

๐Ÿ“‹ Setup Data Updates Applied

BSS Setup Data Files Updated

  1. bss-common-terms.json:
  2. โœ… Removed monthly_quota from all 3 term entries
  3. โœ… Maintained all other contract term fields

  4. nairobi-monthly-flatfee-v1.json:

  5. โœ… Added "billing_currency": "KES" to template
  6. โœ… Maintained country_code and legal_jurisdiction

  7. nairobi-monthly-flatfee-v1-plan1.json:

  8. โœ… Removed currency from service_plan object
  9. โœ… Removed billing_balance, total_services, active_services from plan_state
  10. โœ… Removed usage_summary from service_account

Sample Data Files Updated

  1. service_plan_templates.json:
  2. โœ… Changed embedded objects to ID references (contract_terms_id, service_cycle_fsm_id, etc.)
  3. โœ… Added required fields: country_code, legal_jurisdiction, billing_currency

  4. service_plans.json:

  5. โœ… Removed redundant fields from plan_state arrays
  6. โœ… Maintained essential state tracking fields

  7. service_accounts.json:

  8. โœ… Removed usage_summary field
  9. โœ… Maintained structured service_states arrays

๐Ÿ”ง Developer Guidelines

Working with Currency

// โœ… CORRECT: Access currency through template
const currency = servicePlan.template.billing_currency;

// โŒ INCORRECT: Direct currency access (field removed)
// const currency = servicePlan.currency;

Computing Service Metrics

// โœ… CORRECT: Compute from service_states
const totalServices = serviceAccount.service_states.length;
const activeServices = serviceAccount.service_states.filter(s => s.quota > 0).length;

// โŒ INCORRECT: Access from plan_state (fields removed)
// const totalServices = servicePlan.plan_state.total_services;

Working with Balance Information

// โœ… CORRECT: Use PaymentAccount as single source of truth
const balance = servicePlan.payment_account.balance;

// โŒ INCORRECT: Access from CommonState (field removed)
// const balance = servicePlan.plan_state.billing_balance;

Agent Version Management

// โœ… CORRECT: Use single version field
const agentVersion = agentConfig.version;

// โŒ INCORRECT: Use duplicate field (removed)
// const agentVersion = agentConfig.agent_version;

๐ŸŽฏ GraphQL Resolver Implications

Template Resolvers

type ServicePlanTemplate {
  # Resolvers must handle new billing_currency field
  billing_currency: String!
}

ServicePlan Resolvers

type ServicePlan {
  # Currency resolver must derive from template
  currency: String! # Computed field - resolves template.billing_currency
}

CommonState Resolvers

type CommonState {
  # Computed fields for removed data
  billing_balance: Float!   # Computed from PaymentAccount.balance
  total_services: Int!      # Computed from service_states.length
  active_services: Int!     # Computed from service_states filter
}

๐Ÿงช Testing Implications

Schema Validation Tests

  • โœ… Validate templates include required billing_currency
  • โœ… Ensure ServicePlan currency resolution works correctly
  • โœ… Test computed field calculations for service counts and balances

Data Migration Tests

  • โœ… Verify setup data loads without schema violations
  • โœ… Test FK reference resolution for template relationships
  • โœ… Validate removed fields don't appear in API responses

Integration Tests

  • โœ… Test end-to-end ServicePlan creation with corrected schema
  • โœ… Verify currency inheritance from template to plan
  • โœ… Test dynamic computation of usage and balance metrics

๐Ÿ“ File Reference Quick List

Updated Setup Data Files

models/battery-swap/setup-data/
โ”œโ”€โ”€ bss-common-terms.json              # โœ… Removed monthly_quota
โ”œโ”€โ”€ nairobi-monthly-flatfee-v1.json    # โœ… Added billing_currency
โ””โ”€โ”€ nairobi-monthly-flatfee-v1-plan1.json # โœ… Removed redundant fields

models/samples/abs/types/
โ”œโ”€โ”€ service_plan_templates.json        # โœ… Fixed FK references
โ”œโ”€โ”€ service_plans.json                 # โœ… Removed redundant plan_state fields
โ””โ”€โ”€ service_accounts.json              # โœ… Removed usage_summary

Schema Reference Files

schema/abs.graphql                     # โœ… Corrected schema with commented fields
diagrams/entities-erd.puml             # โŒ Needs update to match schema
schema/SCHEMA_ANALYSIS.md              # โœ… Detailed analysis of corrections
models/MODELS_SCHEMA_COMPATIBILITY.md  # โœ… Compatibility analysis

๐Ÿš€ Next Steps for Developers

  1. Review Schema Changes: Understand field removals and additions
  2. Update Resolvers: Implement currency derivation and computed fields
  3. Test Data Loading: Verify updated setup data loads correctly
  4. Update ERD: Sync entity diagram with corrected schema
  5. Documentation: Update API docs to reflect schema changes

Status: โœ… SCHEMA ALIGNMENT COMPLETE Setup Data: โœ… FULLY COMPLIANT Developer Impact: ๐Ÿ“‹ RESOLVER UPDATES REQUIRED

For additional context, see: - Models Schema Compatibility Archive - Historical schema issues (resolved) - BSS Model Status - Current BSS implementation status