# koraysrn/retention-intelligence architecture

> Architecture diagram of the GitHub repository koraysrn/retention-intelligence, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/koraysrn/retention-intelligence
- Repository: https://github.com/koraysrn/retention-intelligence

## Overview

This repository implements an e-commerce churn re-engagement platform: customer data is ingested and transformed into features, churn risk is modeled and served, campaigns are evaluated through experimentation, and an agentic workflow drafts guarded personalized outreach or escalates cases. The dashboard is the main visible user entry point; the API also exposes scoring and customer/business views. Streaming events, CDP/channel integrations, and drift monitoring are supporting capabilities. Some end-to-end connections are documented in the README but their runtime wiring was not sampled, so those links cite the README rather than implying source-level calls.

Main entry points: [`src/agents/orchestrator.py`](https://github.com/koraysrn/retention-intelligence/blob/main/src/agents/orchestrator.py) (Agent orchestrator), [`src/models/train.py`](https://github.com/koraysrn/retention-intelligence/blob/main/src/models/train.py) (Model training), [`src/streaming/flow.py`](https://github.com/koraysrn/retention-intelligence/blob/main/src/streaming/flow.py) (Event flow), [`src/serving/api.py`](https://github.com/koraysrn/retention-intelligence/blob/main/src/serving/api.py) (Serving API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Dashboard and serving"]
  node_dashboard["Dashboard<br/>[App.tsx]"]
  node_api["Serving API<br/>[api.py]"]
  node_batch["Batch scoring<br/>[batch_score.py]"]
end

subgraph group_data["Customer data"]
  node_ingestion["Data ingestion<br/>[loader.py]"]
  node_quality["Data quality<br/>[quality.py]"]
  node_features["Feature engineering<br/>[ecommerce.py]"]
  node_onlinefeatures[("Online features<br/>[online_store.py]")]
  node_cdp["CDP client<br/>[client.py]"]
  node_eventflow["Event flow<br/>[flow.py]"]
  node_eventbus["Event bus<br/>[events.py]"]
end

subgraph group_ml["Churn modeling"]
  node_training["Model training<br/>[train.py]"]
  node_preparation["Training preparation<br/>[prepare.py]"]
  node_ensemble["Model ensemble<br/>[ensemble.py]"]
  node_evaluation["Model evaluation<br/>[evaluate.py]"]
  node_monitoring["Drift monitoring<br/>[drift.py]"]
  node_retraining["Retraining control<br/>[retrain.py]"]
end

subgraph group_experimentation["Campaign experiments"]
  node_assignment["Experiment assignment<br/>[assignment.py]"]
  node_experimentanalysis["Experiment analysis<br/>[analysis.py]"]
  node_cuped["CUPED adjustment<br/>[cuped.py]"]
end

subgraph group_engagement["Agentic engagement"]
  node_orchestrator["Agent orchestrator<br/>[orchestrator.py]"]
  node_rag["Offer retrieval<br/>[rag.py]"]
  node_llm["Content generation<br/>[llm.py]"]
  node_guardrails["Content guardrails<br/>[guardrails.py]"]
  node_actions["Outreach actions<br/>[actions.py]"]
  node_escalation["Sales escalation<br/>[escalation.py]"]
  node_notifier["Message channels<br/>[notifier.py]"]
end

node_operator(("Dashboard user"))
node_external_llm(("LLM provider"))
node_sales(("Sales representative"))

node_operator -->|"uses"| node_dashboard
node_dashboard -->|"requests data"| node_api
node_api -->|"loads profiles"| node_ingestion
node_api -->|"uses scores"| node_batch
node_ingestion -->|"uses date schema"| node_features
node_ingestion -.->|"validates data"| node_quality
node_features -->|"supplies features"| node_training
node_training -->|"prepares inputs"| node_preparation
node_training -->|"evaluates models"| node_evaluation
node_training -->|"trains ensemble"| node_ensemble
node_ensemble -.->|"scores customers"| node_batch
node_monitoring -->|"informs retraining"| node_retraining
node_monitoring -->|"triggers retraining"| node_training
node_batch -->|"targets risk group"| node_assignment
node_assignment -->|"assigns variants"| node_experimentanalysis
node_experimentanalysis -->|"adjusts outcomes"| node_cuped
node_experimentanalysis -->|"feeds campaign"| node_orchestrator
node_api -.->|"invokes assistance"| node_orchestrator
node_orchestrator -->|"retrieves context"| node_rag
node_orchestrator -->|"generates draft"| node_llm
node_llm -->|"calls provider"| node_external_llm
node_orchestrator -->|"checks draft"| node_guardrails
node_orchestrator -->|"dispatches action"| node_actions
node_orchestrator -->|"routes cases"| node_escalation
node_actions -->|"sends message"| node_notifier
node_escalation -->|"forwards summary"| node_sales
node_eventflow -->|"publishes events"| node_eventbus
node_eventflow -->|"tracks customer"| node_cdp
node_eventflow -->|"updates features"| node_onlinefeatures
node_eventflow -->|"notifies customer"| node_notifier

click node_dashboard "https://github.com/koraysrn/retention-intelligence/blob/main/frontend/src/App.tsx"
click node_api "https://github.com/koraysrn/retention-intelligence/blob/main/src/serving/api.py"
click node_batch "https://github.com/koraysrn/retention-intelligence/blob/main/src/serving/batch_score.py"
click node_ingestion "https://github.com/koraysrn/retention-intelligence/blob/main/src/data/loader.py"
click node_quality "https://github.com/koraysrn/retention-intelligence/blob/main/src/data/quality.py"
click node_features "https://github.com/koraysrn/retention-intelligence/blob/main/src/features/ecommerce.py"
click node_onlinefeatures "https://github.com/koraysrn/retention-intelligence/blob/main/src/features/online_store.py"
click node_training "https://github.com/koraysrn/retention-intelligence/blob/main/src/models/train.py"
click node_preparation "https://github.com/koraysrn/retention-intelligence/blob/main/src/models/prepare.py"
click node_ensemble "https://github.com/koraysrn/retention-intelligence/blob/main/src/models/ensemble.py"
click node_evaluation "https://github.com/koraysrn/retention-intelligence/blob/main/src/models/evaluate.py"
click node_monitoring "https://github.com/koraysrn/retention-intelligence/blob/main/src/monitoring/drift.py"
click node_retraining "https://github.com/koraysrn/retention-intelligence/blob/main/src/monitoring/retrain.py"
click node_assignment "https://github.com/koraysrn/retention-intelligence/blob/main/src/experiments/assignment.py"
click node_experimentanalysis "https://github.com/koraysrn/retention-intelligence/blob/main/src/experiments/analysis.py"
click node_cuped "https://github.com/koraysrn/retention-intelligence/blob/main/src/experiments/cuped.py"
click node_orchestrator "https://github.com/koraysrn/retention-intelligence/blob/main/src/agents/orchestrator.py"
click node_rag "https://github.com/koraysrn/retention-intelligence/blob/main/src/agents/rag.py"
click node_llm "https://github.com/koraysrn/retention-intelligence/blob/main/src/agents/llm.py"
click node_guardrails "https://github.com/koraysrn/retention-intelligence/blob/main/src/agents/guardrails.py"
click node_actions "https://github.com/koraysrn/retention-intelligence/blob/main/src/agents/actions.py"
click node_escalation "https://github.com/koraysrn/retention-intelligence/blob/main/src/agents/escalation.py"
click node_notifier "https://github.com/koraysrn/retention-intelligence/blob/main/src/channels/notifier.py"
click node_cdp "https://github.com/koraysrn/retention-intelligence/blob/main/src/cdp/client.py"
click node_eventflow "https://github.com/koraysrn/retention-intelligence/blob/main/src/streaming/flow.py"
click node_eventbus "https://github.com/koraysrn/retention-intelligence/blob/main/src/streaming/events.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_dashboard,node_api,node_batch,node_operator toneBlue
class node_ingestion,node_quality,node_features,node_onlinefeatures,node_cdp,node_eventflow,node_eventbus toneAmber
class node_training,node_preparation,node_ensemble,node_evaluation,node_monitoring,node_retraining toneMint
class node_assignment,node_experimentanalysis,node_cuped toneRose
class node_orchestrator,node_rag,node_llm,node_guardrails,node_actions,node_escalation,node_notifier,node_external_llm,node_sales toneIndigo
```

## Components

### Dashboard and serving

- [Dashboard](https://github.com/koraysrn/retention-intelligence/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Serving API](https://github.com/koraysrn/retention-intelligence/blob/main/src/serving/api.py): `src/serving/api.py`
- [Batch scoring](https://github.com/koraysrn/retention-intelligence/blob/main/src/serving/batch_score.py): `src/serving/batch_score.py`

### Customer data

- [Data ingestion](https://github.com/koraysrn/retention-intelligence/blob/main/src/data/loader.py): `src/data/loader.py`
- [Data quality](https://github.com/koraysrn/retention-intelligence/blob/main/src/data/quality.py): `src/data/quality.py`
- [Feature engineering](https://github.com/koraysrn/retention-intelligence/blob/main/src/features/ecommerce.py): `src/features/ecommerce.py`
- [Online features](https://github.com/koraysrn/retention-intelligence/blob/main/src/features/online_store.py): `src/features/online_store.py`
- [CDP client](https://github.com/koraysrn/retention-intelligence/blob/main/src/cdp/client.py): `src/cdp/client.py`
- [Event flow](https://github.com/koraysrn/retention-intelligence/blob/main/src/streaming/flow.py): `src/streaming/flow.py`
- [Event bus](https://github.com/koraysrn/retention-intelligence/blob/main/src/streaming/events.py): `src/streaming/events.py`

### Churn modeling

- [Model training](https://github.com/koraysrn/retention-intelligence/blob/main/src/models/train.py): `src/models/train.py`
- [Training preparation](https://github.com/koraysrn/retention-intelligence/blob/main/src/models/prepare.py): `src/models/prepare.py`
- [Model ensemble](https://github.com/koraysrn/retention-intelligence/blob/main/src/models/ensemble.py): `src/models/ensemble.py`
- [Model evaluation](https://github.com/koraysrn/retention-intelligence/blob/main/src/models/evaluate.py): `src/models/evaluate.py`
- [Drift monitoring](https://github.com/koraysrn/retention-intelligence/blob/main/src/monitoring/drift.py): `src/monitoring/drift.py`
- [Retraining control](https://github.com/koraysrn/retention-intelligence/blob/main/src/monitoring/retrain.py): `src/monitoring/retrain.py`

### Campaign experiments

- [Experiment assignment](https://github.com/koraysrn/retention-intelligence/blob/main/src/experiments/assignment.py): `src/experiments/assignment.py`
- [Experiment analysis](https://github.com/koraysrn/retention-intelligence/blob/main/src/experiments/analysis.py): `src/experiments/analysis.py`
- [CUPED adjustment](https://github.com/koraysrn/retention-intelligence/blob/main/src/experiments/cuped.py): `src/experiments/cuped.py`

### Agentic engagement

- [Agent orchestrator](https://github.com/koraysrn/retention-intelligence/blob/main/src/agents/orchestrator.py): `src/agents/orchestrator.py`
- [Offer retrieval](https://github.com/koraysrn/retention-intelligence/blob/main/src/agents/rag.py): `src/agents/rag.py`
- [Content generation](https://github.com/koraysrn/retention-intelligence/blob/main/src/agents/llm.py): `src/agents/llm.py`
- [Content guardrails](https://github.com/koraysrn/retention-intelligence/blob/main/src/agents/guardrails.py): `src/agents/guardrails.py`
- [Outreach actions](https://github.com/koraysrn/retention-intelligence/blob/main/src/agents/actions.py): `src/agents/actions.py`
- [Sales escalation](https://github.com/koraysrn/retention-intelligence/blob/main/src/agents/escalation.py): `src/agents/escalation.py`
- [Message channels](https://github.com/koraysrn/retention-intelligence/blob/main/src/channels/notifier.py): `src/channels/notifier.py`

### Other components

- **Dashboard user**
- **LLM provider**
- **Sales representative**

## Connections

- Dashboard user → Dashboard: uses (evidence: `README.md`)
- Dashboard → Serving API: requests data (evidence: `frontend/src/App.tsx`)
- Serving API → Data ingestion: loads profiles (evidence: `src/serving/api.py`)
- Serving API → Batch scoring: uses scores (evidence: `src/serving/api.py`)
- Data ingestion → Feature engineering: uses date schema (evidence: `src/data/loader.py`)
- Data ingestion → Data quality: validates data
- Feature engineering → Model training: supplies features (evidence: `README.md`)
- Model training → Training preparation: prepares inputs (evidence: `src/models/train.py`)
- Model training → Model evaluation: evaluates models (evidence: `src/models/train.py`)
- Model training → Model ensemble: trains ensemble (evidence: `README.md`)
- Model ensemble → Batch scoring: scores customers
- Drift monitoring → Retraining control: informs retraining (evidence: `src/monitoring/retrain.py`)
- Drift monitoring → Model training: triggers retraining (evidence: `README.md`)
- Batch scoring → Experiment assignment: targets risk group (evidence: `README.md`)
- Experiment assignment → Experiment analysis: assigns variants (evidence: `src/experiments/analysis.py`)
- Experiment analysis → CUPED adjustment: adjusts outcomes (evidence: `src/experiments/analysis.py`)
- Experiment analysis → Agent orchestrator: feeds campaign (evidence: `README.md`)
- Serving API → Agent orchestrator: invokes assistance
- Agent orchestrator → Offer retrieval: retrieves context (evidence: `src/agents/orchestrator.py`)
- Agent orchestrator → Content generation: generates draft (evidence: `src/agents/orchestrator.py`)
- Content generation → LLM provider: calls provider (evidence: `src/agents/llm.py`)
- Agent orchestrator → Content guardrails: checks draft (evidence: `src/agents/orchestrator.py`)
- Agent orchestrator → Outreach actions: dispatches action (evidence: `src/agents/orchestrator.py`)
- Agent orchestrator → Sales escalation: routes cases (evidence: `src/agents/orchestrator.py`)
- Outreach actions → Message channels: sends message (evidence: `src/agents/actions.py`)
- Sales escalation → Sales representative: forwards summary (evidence: `README.md`)
- Event flow → Event bus: publishes events (evidence: `src/streaming/flow.py`)
- Event flow → CDP client: tracks customer (evidence: `src/streaming/flow.py`)
- Event flow → Online features: updates features (evidence: `src/streaming/flow.py`)
- Event flow → Message channels: notifies customer (evidence: `src/streaming/flow.py`)
