End-to-end customer churn analytics platform with a React dashboard, Flask API, machine learning models (XGBoost + MLP), and PostgreSQL-backed data workflows.
- Overview
- Key Features
- Architecture
- Repository Structure
- Tech Stack
- Getting Started
- Environment Variables
- How to Use
- API Reference (Core Endpoints)
- Model Training Notes
- Deployment
- Security & Secrets Management
- Troubleshooting
- Project Status / Roadmap
- Contributing
- License
- Acknowledgements
This project helps teams upload churn-related datasets, train churn models, run batch predictions, and explore visual analytics in a dashboard.
It is designed as a practical product-style repository:
- Frontend for visualization and workflow UX
- Backend API for ingestion, analytics, and model operations
- Database for persisted predictions and dashboard records
- ML artifacts for model metrics and feature importances
- Batch churn prediction from uploaded CSV/XLSX data
- Interactive dashboard charts (churn trends, app usage, carrier distribution, return analysis, feature importance, correlation heatmap)
- XGBoost and MLP model support
- Training session/progress endpoints for long-running training workflows
- Dashboard data upload/reset and analytics refresh
- Production split deployment support (Vercel + Railway/Render + managed Postgres)
Frontend (React + Vite)
|
| HTTP (REST)
v
Backend (Flask + Gunicorn)
|
| SQL
v
PostgreSQL (predictions, dashboard data, processed features)
Runtime flow (high level):
- Upload data for analytics and/or prediction
- Backend validates/processes data
- Data and prediction outputs are persisted to PostgreSQL
- Frontend fetches analytics + prediction endpoints and renders charts/tables
backend/ Flask API, model training/prediction scripts, DB SQL
frontend/ React + Vite dashboard app
data/ Local sample datasets
docs/ Deployment and supporting documentation
docker-compose.yml Multi-service local stack (db/backend/frontend)
SECURITY_CHECKLIST.md Public-release security checklist
Important backend files:
backend/app.py— main Flask app and API routesbackend/requirements.txt— Python dependenciesbackend/db/churn_database.sql— database schema scriptbackend/Dockerfile— backend container build
Important frontend files:
frontend/src/pages/Dashboard.jsx— dashboard orchestration and data fetchingfrontend/src/components/charts/*— chart componentsfrontend/package.json— frontend scripts/dependencies
- React 19
- Vite 6
- React Router
- React Bootstrap + Bootstrap
- Recharts / Chart.js / D3
- Python + Flask
- Gunicorn
- Pandas / NumPy / scikit-learn
- XGBoost
- PyTorch (MLP)
- SQLAlchemy + psycopg2
- PostgreSQL
- Docker + Docker Compose
- Vercel (frontend)
- Railway/Render (backend)
- Node.js 18+
- npm
- Python 3.10 (recommended for backend dependencies)
- PostgreSQL (if not using Docker)
- Docker Desktop (optional, recommended for full-stack local run)
From repo root:
docker compose up --buildDefault ports from docker-compose.yml:
- Frontend:
http://localhost:4173 - Backend:
http://localhost:5050 - Postgres:
localhost:5432
cd backend
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
flask run --host=0.0.0.0 --port=5000cd frontend
npm install
npm run devFrontend dev URL is typically http://localhost:5173.
Use frontend/.env.example as template.
VITE_ENVIRONMENT=local
VITE_API_URL=http://127.0.0.1:5050Backend reads DB settings from either:
DATABASE_URL(preferred in managed platforms), or- individual vars:
DB_HOSTDB_PORTDB_NAMEDB_USERDB_PASS
Optional operational vars:
DB_ROW_LIMITXGB_TOTAL_TRIALSMLP_TOTAL_EPOCHSFAST_XGB_TOTAL_TRIALSFAST_MLP_TOTAL_EPOCHS
- Start backend + frontend.
- Open dashboard.
- Upload dashboard data (
CSV/XLSX) through the UI. - Generate predictions from uploaded CSV batches.
- View analytics and prediction history.
- Optionally run/monitor model training from training endpoints/UI flows.
Health & diagnostics:
GET /healthGET /config
Predictions:
POST /predict_batchPOST /predict_batch_MLPGET /predictions?limit=<n>DELETE /delete_prediction_batch/<batch_id>DELETE /delete_all_predictions
Training lifecycle:
POST /train_modelPOST /train_MLP_modelGET /training_progress_XGBGET /training_progress_MLPPOST /training_sessionGET /training_session/activeGET /training_session/<training_id>POST /training_session/<training_id>/cancel
Analytics/dashboard:
POST /upload_dashboard_dataPOST /reset_dashboard_dataGET /dashboard_dataGET /carrier_distributionGET /return_analysisGET /time_analysisGET /feature_heatmap_dataGET /feature_importanceGET /feature_importance_MLP
- Supports XGBoost and MLP model pipelines.
- Tracks training progress via JSON progress/state files.
- Stores model metrics and feature importance artifacts in backend/model artifact files.
- For faster local iteration, use “fast mode” env vars where applicable.
For full deployment details, see docs/DEPLOYMENT.md.
Typical production split:
- Frontend: Vercel (project root
frontend) - Backend: Railway or Render (root
backend) - Database: managed Postgres (Railway/Neon/Supabase)
Critical production checklist:
- Set
VITE_API_URLin Vercel to backend public URL - Ensure backend DB schema is initialized (
backend/db/churn_database.sql) - Verify
GET /healthandGET /dashboard_data
Read and follow SECURITY_CHECKLIST.md before public release.
Minimum requirements:
- Never commit real
.envfiles or secrets - Rotate any leaked credentials immediately
- Keep
.env.examplefiles with placeholders only - Use platform-managed environment variables (Vercel/Railway/Render)
- Check backend response:
curl -sS <BACKEND_URL>/return_analysis- If arrays are empty, verify
dashboard_devicescontains return rows and expected columns.
VITE_API_URLpoints to unreachable backend host/port.- Start backend or update env var and redeploy frontend.
- Inspect browser console + network tab for API payload shape mismatches.
- Verify backend endpoints return JSON with expected keys.
- Use Python 3.10 where possible.
- Prefer Docker for consistent builds of heavy ML dependencies.
Current focus areas:
- Improve test coverage (frontend component tests + backend API tests)
- Harden schema/data validation for uploaded datasets
- Add CI for lint/test/build gates
- Improve dashboard performance via code splitting and optimized payloads
- Fork the repo
- Create a feature branch
- Make focused changes
- Validate locally
- Open a PR with:
- summary of changes
- validation steps
- screenshots for UI changes
Suggested contribution standards:
- Keep secrets out of commits
- Prefer small PRs
- Add/update docs when behavior changes
No license file is currently included in this repository.
If you plan to make this project public/open-source, add a LICENSE file (e.g., MIT/Apache-2.0) and update this section.
- Open-source libraries: React, Flask, scikit-learn, PyTorch, XGBoost, Recharts, D3
- Deployment platforms: Vercel, Railway/Render
If you want, I can also add a LICENSE file, CONTRIBUTING.md, and CODE_OF_CONDUCT.md to complete the standard public-repo documentation set.