A production-grade SaaS platform that transforms raw e-commerce transaction data into automated RFM scores, K-Means customer cohorts, predictive business insights, and segment-specific action playbooks.
- RFM Analysis Engine: Mathematical quintile scoring (1–5) on Recency, Frequency, and Monetary dimensions for each customer.
-
K-Means ML Segmentation: Unsupervised machine learning clustering with optimal
$k$ discovery (Elbow method & Silhouette analysis) and 2D PCA projection. - Automated Insights Generator: Rule-based business intelligence alerting you to VIP revenue concentration, at-risk churn, repeat purchase velocity, and geographic skew.
- Actionable Segment Playbooks: Pre-built operational recommendations with impact & effort ratings for every cohort (VIP, Loyal, Potential, At-Risk).
- Executive Analytics Dashboard: Interactive area, bar, scatter, and pie charts with period-over-period delta indicators.
- CSV Data Pipeline: Streaming ingestion supporting the standard UCI Online Retail format with background ML execution, error tracking, and progress polling.
-
Multi-Tenant Architecture: Every database query is scoped by
workspace_id. Authentication is handled via Clerk JWT with cryptographic JWKS signature verification. - Light & Dark Theme System: Built with CSS tokens, backdrop filters, smooth gradients, and glassmorphism.
graph TD
Client[Next.js 14 App Router + TailwindCSS] -->|Clerk Bearer JWT| FastAPIServer[FastAPI Backend Python 3.12]
Client -->|Clerk Auth SDK| ClerkService[Clerk Identity Provider]
FastAPIServer -->|Async SQLAlchemy / asyncpg| PostgresDB[(PostgreSQL 16 DB)]
FastAPIServer -->|Background Processing| MLWorker[Scikit-Learn ML Pipeline]
MLWorker -->|Clean / RFM / KMeans / PCA| PostgresDB
| Layer | Technologies |
|---|---|
| Frontend | Next.js 14 (App Router), TypeScript, TailwindCSS v4, Recharts, Lucide Icons, next-themes |
| Authentication | Clerk (JWT verification via JWKS endpoint, multi-tenant workspace mapping) |
| Backend API | FastAPI, Pydantic v2, Uvicorn, Async SQLAlchemy 2.0 |
| Database | PostgreSQL 16 (dockerized or local), Alembic migrations, asyncpg driver |
| Data Science / ML | Python pandas, scikit-learn (KMeans, StandardScaler, PCA), numpy, scipy |
| Containerization | Docker, Docker Compose multi-service architecture |
- Node.js: v18+ (tested on Node v20/v24)
- Python: v3.11+ (tested on Python 3.12)
- Docker: For running PostgreSQL (or a local PostgreSQL instance)
Copy .env.example to .env:
cp .env.example .envFill in your Clerk credentials from dashboard.clerk.com:
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_...
CLERK_SECRET_KEY=sk_test_...
CLERK_ISSUER=https://your-clerk-domain.clerk.accounts.dev
CLERK_JWKS_URL=https://your-clerk-domain.clerk.accounts.dev/.well-known/jwks.json
DATABASE_URL=postgresql+asyncpg://customeriq:customeriq@localhost:5432/customeriqdocker compose up db -dcd backend
python -m venv venv
# On Windows:
.\venv\Scripts\activate
# On Linux/macOS:
source venv/bin/activate
pip install -r requirements.txt
uvicorn app.main:app --reload --port 8000Backend API documentation will be available at: http://localhost:8000/api/docs
cd frontend
npm install
npm run devFrontend will be running at: http://localhost:3000
To immediately populate the platform with 500 realistic customers and 5,000 orders:
python scripts/seed_demo_data.pyTo upload transaction data via the UI (/app/upload), ensure your CSV has the following columns (compatible with the UCI Online Retail dataset):
| Column | Type | Example |
|---|---|---|
InvoiceNo |
String | 536365 |
StockCode |
String | 85123A |
Description |
String | WHITE HANGING HEART T-LIGHT HOLDER |
Quantity |
Integer | 6 |
InvoiceDate |
Date/DateTime | 2023-12-01 08:26:00 |
UnitPrice |
Float | 2.55 |
CustomerID |
String / Int | 17850 |
Country |
String | United Kingdom |
A pre-packaged sample CSV is available in frontend/public/data/sample_retail_data.csv for immediate testing.
-
Data Sanitization: Drops cancelled orders (
InvoiceNostarting with 'C'), handles non-positive quantities/unit prices, and standardizes dates. -
RFM Derivation:
-
Recency (
$R$ ):$\text{Reference Date} - \max(\text{InvoiceDate})$ -
Frequency (
$F$ ):$\text{Count of unique } \text{InvoiceNo}$ -
Monetary (
$M$ ):$\sum (\text{Quantity} \times \text{UnitPrice})$
-
Recency (
-
Log-Transform & Scaling: Applies
$\ln(x+1)$ transform to counter monetary/frequency power-law distributions, followed byStandardScaler(mean=0, std=1). -
Clustering: Runs
KMeans(n_clusters=k, random_state=42)across standardized$(R, F, M)$ vectors. -
PCA Projection: Reduces normalized 3D coordinates to 2 dimensions via
PCA(n_components=2)for interactive browser scatter plotting. -
Persona Mapping: Automated sorting assigns business personas based on average recency and spending profiles:
- VIP Customers: Low recency, top monetary spend.
- Loyal Customers: High purchase frequency, steady engagement.
- Potential Customers: Recent single or low-frequency purchases.
- At-Risk Customers: High recency (dormant), formerly active.
Run the entire platform with a single command:
docker compose up --build -dServices started:
customeriq-db: PostgreSQL on port 5432customeriq-backend: FastAPI on port 8000customeriq-frontend: Next.js on port 3000
- Authentication: JWT token validation verified against Clerk JWKS public keys.
- Tenant Isolation: Strict
workspace_idforeign key enforcement across all DB entities. - Input Validation: Strict schema enforcement via Pydantic v2.
- Rate Limiting & File Bounds: 50MB maximum upload limit with streaming memory validation.
Proprietary SaaS Application — CustomerIQ Platform © 2024. All rights reserved.