How barath1412/telecom-customer-churn-prediction-and-retention-recommendation works
Purpose and system shape
This is a telecom customer-churn scoring and retention-recommendation system. It combines an ML/policy pipeline that prioritizes customers and recommends offers, a Python backend exposing that data and actions, and a React retention-console UI for operators. Shared API response fixtures/contracts establish the cross-layer boundary: ml/api-contract/POST_score.json, backend/app/routes.py, retention-console-frontend/api-contract/POST_score.json.
Entry points and serving layer
The backend application is centered on backend/app/main.py, with HTTP endpoint registration in backend/app/routes.py. It appears to serve queue, customer-detail, catalog, summary, scoring, and action operations; endpoint-specific orchestration is separated into backend/app/score.py, backend/app/detail.py, and backend/app/actions_log.py. Shell/batch launchers are backend/run.sh and backend/run.bat.
The browser entry points are retention-console-frontend/frontend/src/main.tsx and retention-console-frontend/frontend/src/App.tsx; route composition is in retention-console-frontend/frontend/src/routes.tsx.
ML scoring and recommendation pipeline
The core ML workflow starts from churn data and a trained model: ml/data/Telco_customer_churn.xlsx, ml/src/train.py, and ml/artifacts/churn_model_v1.joblib. Runtime scoring likely derives model-ready fields, predicts churn, and attaches feature attribution through ml/src/features.py, ml/src/predict.py, and ml/src/attribution.py.
A decision layer turns risk/economic inputs into actionable retention outcomes. ml/src/decision.py, ml/src/levers.py, and ml/src/gate.py define the recommendation, eligible intervention levers, and policy/eligibility gates. This is an important boundary: model risk alone does not imply an offer; decision logic can produce review or no-action states.
Batch queue and durable artifacts
Queue generation is a separate batch-oriented stage: ml/src/queue_build.py, ml/src/run_batch.py, and ml/artifacts/queue_full.csv. It produces ranked operational views and audit material, including ml/artifacts/queue_top40.csv and ml/artifacts/queue_audit.json.
The backend appears artifact-backed rather than database-backed: state/access adapters include backend/app/cache.py, backend/app/queue_state.py, and backend/app/population.py. Model registry and evidence identifiers are persisted as files in ml/artifacts/model_registry.json and ml/artifacts/evidence_ids.json.
Explanation, evidence, and narration
Recommendations carry explainability and policy trace data from model attribution and decision stages. Customer-facing detail/narration is handled by backend/app/detail.py and backend/app/narrate.py, supported in ML by ml/src/narration_client.py and ml/src/kb_retrieval.py. The knowledge source is ml/data/kb/knowledge_base.md, with construction support in ml/src/kb_build.py.
This separates deterministic scoring/policy from generated or retrieved explanatory text, allowing the UI to render both recommendation economics and narrative evidence.
Operator console and API consumption
The React/Vite frontend organizes workflows by operational task: queue (retention-console-frontend/frontend/src/features/queue/QueuePage.tsx), customer review/action (retention-console-frontend/frontend/src/features/customer/CustomerPage.tsx), and ad hoc scoring (retention-console-frontend/frontend/src/features/score/ScorePage.tsx). API transport and typed response handling are centralized in retention-console-frontend/frontend/src/lib/api.ts and retention-console-frontend/frontend/src/types/api.ts.
The UI explicitly surfaces expected-value and policy/narration outputs through retention-console-frontend/frontend/src/components/EVBreakdown.tsx, retention-console-frontend/frontend/src/components/PolicyTrace.tsx, and retention-console-frontend/frontend/src/components/NarrationPanel.tsx. Local mock-service-worker infrastructure (retention-console-frontend/frontend/src/mocks/handlers.ts) lets the console operate against the shared fixture contracts without the backend.
Validation boundaries and external dependencies
Input validity and leakage prevention are first-class constraints: ml/src/validators.py, ml/src/contracts.py, and ml/src/fallback.py protect scoring and response formation; backend errors are represented in backend/app/errors.py. Frontend score-form leakage protection is mirrored in retention-console-frontend/frontend/src/features/score/leakageGuard.ts.
Material runtimes are Python for the backend/ML pipeline (backend/requirements.txt, ml/requirements.txt) and Node/TypeScript with Vite for the console (retention-console-frontend/frontend/package.json). The only evident external content service is the narration client; its provider/configuration is not identifiable from the supplied tree.
Main entry points: score.py Score, detail & actions · api.ts API client & types · predict.py Risk scoring & attribution · POST_score.json Score response contract
Components 21
ML & policy pipeline
- Churn training data
ml/data/Telco_customer_churn.xlsx - Model training
ml/src/train.py - Risk scoring & attribution · Builds features, predicts risk, and attaches attribution.
ml/src/predict.py - Decision policy · Applies levers and eligibility gates to produce offers, review, or no-action.
ml/src/decision.py - Batch queue builder · Ranks scored customers into operational queues and audit output.
ml/src/run_batch.py - Retention knowledge base
ml/data/kb/knowledge_base.md - Narration & retrieval · Keeps retrieved or generated explanation separate from deterministic policy.
ml/src/narration_client.py
Durable artifacts
- Churn model
ml/artifacts/churn_model_v1.joblib - Ranked queue
ml/artifacts/queue_full.csv - Queue audit
ml/artifacts/queue_audit.json - Model & evidence registry
ml/artifacts/model_registry.json
Python backend
- Backend application
backend/app/main.py - HTTP routes · Serves queue, detail, catalog, summary, scoring, and action operations.
backend/app/routes.py - Score, detail & actions
backend/app/score.py - Artifact-backed state · Reads queue, population, and cached artifact state instead of a database.
backend/app/queue_state.py
Retention console
- Console application
retention-console-frontend/frontend/src/App.tsx - Operator workflows · Queue, customer review/action, and ad hoc scoring views.
retention-console-frontend/frontend/src/routes.tsx - API client & types
retention-console-frontend/frontend/src/lib/api.ts - EV, policy & narration · Renders economics, policy trace, and narrative evidence.
retention-console-frontend/frontend/src/components/EVBreakdown.tsx - Mock API handlers · Runs the console against fixture contracts without the backend.
retention-console-frontend/frontend/src/mocks/handlers.ts
Other components
- Score response contract · Cross-layer scoring response boundary.
ml/api-contract/POST_score.json
Connections 25
- Churn training data → Model training: trains
- Model training → Churn model: produces
- Churn model → Risk scoring & attribution: loaded for inference
- Risk scoring & attribution → Decision policy: risk & attribution
- Decision policy → Batch queue builder: retention outcomes
- Batch queue builder → Ranked queue: writes
- Batch queue builder → Queue audit: writes
- Churn model → Model & evidence registry: registered with evidence
- Retention knowledge base → Narration & retrieval: retrieved context
- Decision policy → Narration & retrieval: policy trace
- Backend application → HTTP routes: registers
- HTTP routes → Score, detail & actions: dispatches
- Score, detail & actions → Artifact-backed state: reads operational state
- Artifact-backed state → Ranked queue: loads
- Score, detail & actions → Risk scoring & attribution: requests scoring
- Score, detail & actions → Narration & retrieval: requests explanation
- Risk scoring & attribution → Score response contract: forms response
- Score, detail & actions → Score response contract: returns
- Console application → Operator workflows: composes
- Operator workflows → API client & types: uses
- API client & types → HTTP routes: HTTP requests
- Operator workflows → EV, policy & narration: renders
- API client & types → Score response contract: typed against
- Mock API handlers → Score response contract: serves fixture
- API client & types → Mock API handlers: local development