# Phase 11 Track B Status and Development Plan

Date: 2026-03-27  
Branch: phase-11-track-b-lifecycle-afex-plan

## Scope

Track B - Wallet Lifecycle and AFEX Sync
- Sprint A: P11-SA-B01, P11-SA-B02
- Sprint B: P11-SB-B01, P11-SB-B02

## Current Status Snapshot

### P11-SA-B01 - Wallet lifecycle state model expansion
Status: done

What is implemented:
- Wallet lifecycle model in wallet_accounts includes: pending, active, suspended, frozen, closed.
- Transition guards and state helpers are present in account domain model.
- Lifecycle command flow tests exist and cover major transition paths.

What is complete:
- Database migration and Ecto account schema now allow pending and suspended statuses.
- Suspension metadata fields are represented in DB schema and write-through persistence.
- Account unit tests aligned with pending-first lifecycle behavior.

Validation evidence:
- Lifecycle command tests run with DB env: passing.
- Lifecycle and account test batch: 39 tests, 0 failures.

### P11-SA-B02 - Lifecycle commands and events v1
Status: done

What is implemented:
- Commands: ActivateAccount, SuspendAccount, ResumeAccount, CloseAccount.
- Events: AccountActivated.v1, AccountSuspended.v1, AccountResumed.v1, AccountClosed.v1.
- Command modules emit audit events and support correlation_id propagation.

Validation evidence:
- wallet_database schema/write-through test batch: 45 tests, 0 failures.

### P11-SB-B01 - AFEX profile synchronization ingestion
Status: done

What is implemented:
- `AfexProfile` struct: normalised AFEX callback payload with KYC status, risk level, credit
  limit, currency list, PII fields (name/email/phone/country); atom/string enum normalisation.
- `AfexProfileSyncRecord`: lifecycle struct (received → applied | failed | skipped) with
  mark_applied/2, mark_failed/2, mark_skipped/2 transitions.
- `AfexProfileSyncStore`: ETS GenServer with customer/status/profile indexes; purge_before_date/1
  for retention enforcement.
- `IngestAfexProfileSync` command: dependency-injected account_finder + account_updater avoids
  compile-time cross-app coupling; enforces merge rules (kyc/risk always overwrite; credit_limit,
  currencies, metadata conditional); emits AfexProfileSynced.v1 event.
- `AfexProfileSynced.v1` domain event.
- `DataGovernance` entity policy registry for all Phase 11 PII entities.
- Control catalog entries: CTRL-VIB-001, CTRL-IBR-001, CTRL-PSY-001, CTRL-RET-001.

Validation evidence:
- wallet_integrations/afex_profile_sync_test.exs: 23 tests, 0 failures.
- wallet_integrations/data_governance_test.exs: 14 tests, 0 failures.

### P11-SB-B02 - Profile reconciliation scheduled job
Status: not-started (P1 — carryover tolerated per Sprint B gate)

## Development Plan

## Phase 1 - Close Sprint A Track B Gaps (Lifecycle)

Goal: Mark P11-SA-B01 and P11-SA-B02 as done with persistence parity and passing tests.

Work items:
1. Expand account DB constraints and schema statuses to include pending and suspended.
2. Add suspended fields to DB account schema and account persistence mapping if absent.
3. Update lifecycle unit tests to reflect pending-default account creation and valid freeze paths.
4. Add a focused persistence round-trip test for suspended and pending states.

Expected commit slices:
1. wallet_database migration/schema updates for account lifecycle statuses
2. write-through mapping updates plus schema tests
3. wallet_accounts test suite alignment and lifecycle transition evidence

Acceptance check:
- wallet_accounts lifecycle tests green.
- wallet_database schema/write-through tests green.
- Lifecycle transitions and persistence constraints are consistent.

## Phase 2 - Build Sprint B B01 AFEX Sync Ingestion

Goal: Deliver AFEX profile sync ingestion path with deterministic merge policy and auditability.

Work items:
1. Define AFEX profile payload contract and normalized profile model.
2. Implement upsert handler with deterministic merge rules and conflict tag semantics.
3. Emit sync events with correlation metadata.
4. Persist/query audit trail for profile updates and conflicts.

Expected commit slices:
1. contracts and profile model
2. ingestion command/handler and merge policy
3. event emission and audit persistence
4. tests for merge/conflict scenarios

Acceptance check:
- Sync integration tests cover insert, update, stale update, conflicting update.
- Conflict tags and audit trail query path verified.

## Phase 3 - Build Sprint B B02 Reconciliation Job

Goal: Deliver scheduled compare-and-correct reconciliation for AFEX profile consistency.

Work items:
1. Implement scheduled reconciliation job for AFEX profile records.
2. Add mismatch detection and correction strategy.
3. Produce summary metrics and alert thresholds.
4. Add operational run output suitable for evidence artifacts.

Expected commit slices:
1. reconciliation job and worker wiring
2. mismatch/correction logic
3. telemetry and alert threshold handling
4. tests and reconciliation report fixture generation

Acceptance check:
- Job run report includes mismatch count and correction count.
- Alert thresholds testable and documented.

## Branch and Commit Strategy

Primary branch created:
- phase-11-track-b-lifecycle-afex-plan

Recommended execution branches after this planning commit:
1. phase-11-track-b-sa-lifecycle-parity
2. phase-11-track-b-sb-afex-sync
3. phase-11-track-b-sb-profile-recon

Merge order:
1. SA lifecycle parity branch first.
2. SB AFEX sync branch second.
3. SB profile reconciliation branch third.

## Immediate Next Action

Proceed with Sprint B Track B implementation: AFEX profile synchronization ingestion (P11-SB-B01), then profile reconciliation job (P11-SB-B02).
