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¶
- bss-common-terms.json:
- โ
Removed
monthly_quotafrom all 3 term entries -
โ Maintained all other contract term fields
-
nairobi-monthly-flatfee-v1.json:
- โ
Added
"billing_currency": "KES"to template -
โ Maintained country_code and legal_jurisdiction
-
nairobi-monthly-flatfee-v1-plan1.json:
- โ
Removed
currencyfrom service_plan object - โ
Removed
billing_balance,total_services,active_servicesfrom plan_state - โ
Removed
usage_summaryfrom service_account
Sample Data Files Updated¶
- service_plan_templates.json:
- โ
Changed embedded objects to ID references (
contract_terms_id,service_cycle_fsm_id, etc.) -
โ Added required fields:
country_code,legal_jurisdiction,billing_currency -
service_plans.json:
- โ Removed redundant fields from plan_state arrays
-
โ Maintained essential state tracking fields
-
service_accounts.json:
- โ
Removed
usage_summaryfield - โ
Maintained structured
service_statesarrays
๐ง 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¶
- Review Schema Changes: Understand field removals and additions
- Update Resolvers: Implement currency derivation and computed fields
- Test Data Loading: Verify updated setup data loads correctly
- Update ERD: Sync entity diagram with corrected schema
- 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