Skip to content

DARREN-2000/Relevanace_Engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎯 Relevance Engine

Consent-first, AI-powered next-best-action marketing automation platform

Quick Start β€’ Architecture β€’ API β€’ Full API Docs β€’ Deployment

CI Python FastAPI License Docker Kubernetes


πŸ“Œ What is Relevance Engine?

Relevance Engine is an intelligent marketing automation platform that puts user consent at the center of every decision. Instead of blasting messages to segments, it evaluates each user individually and decides: should we reach out at all? If yes β€” what to say, which channel, and when. If no β€” it stays silent. Because sometimes the best marketing action is no action.


✨ Key Features

Feature Description
🧠 Next-Best-Action Engine AI-driven decision engine that picks the optimal action per user
πŸ›‘οΈ Consent-First Architecture Every action verified against user consent before execution
🀫 "Do Nothing" as a Feature System can decide to suppress β€” reducing noise, increasing trust
πŸ“Š Behavioral Scoring Real-time intent, churn risk, activation, and fatigue scoring
πŸ”‡ Fatigue Management Automatic suppression when users are over-contacted
πŸ—ΊοΈ Journey Orchestration Multi-step automated journeys with consent gates at each step
πŸ§ͺ Experimentation Built-in A/B testing framework for continuous optimization
πŸ€– AI Agents Pluggable agents for segmentation, copy, journeys, and governance
πŸ“ˆ Analytics Dashboard Cohort analysis, funnels, attribution, and decision metrics
πŸ”— ConsentHub Integration Companion to B2B_Consent_Personalization

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   FastAPI REST API                          β”‚
β”‚  /users  /consents  /events  /decisions  /journeys  /analytics β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  Core Decision Engine                         β”‚
β”‚                                                              β”‚
β”‚  Scoring ──→ Fatigue ──→ Consent ──→ Suppression ──→ NBA    β”‚
β”‚                                                              β”‚
β”‚  "Should we act?"  β†’  "What action?"  β†’  "Which channel?"   β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚                           β”‚
  β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”              β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”
  β”‚PostgreSQLβ”‚              β”‚    Redis     β”‚
  β”‚ Users    β”‚              β”‚ Cache/Queue  β”‚
  β”‚ Consents β”‚              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  β”‚ Events   β”‚
  β”‚ Decisionsβ”‚         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚    AI Agents Layer    β”‚
                       β”‚ Segment β”‚ Journey     β”‚
                       β”‚ Copy    β”‚ Experiment  β”‚
                       β”‚ Governance            β”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

For the complete architecture, see docs/ARCHITECTURE.md.


πŸš€ Quick Start

Prerequisites

  • Docker 24+ & Docker Compose v2+

Start the Stack

# Clone
git clone https://github.com/DARREN-2000/Relevnace_Engine.git
cd Relevnace_Engine

# Configure
cp .env.example .env

# Launch (PostgreSQL + Redis + Backend)
make up

# Verify
curl http://localhost:8000/api/health

Try the API

# Create a user
curl -X POST http://localhost:8000/api/users \
  -H "Content-Type: application/json" \
  -d '{"email": "jane@example.com", "name": "Jane Doe", "lifecycle_stage": "trial"}'

# Record consent
curl -X POST http://localhost:8000/api/consents \
  -H "Content-Type: application/json" \
  -d '{"user_id": "<USER_ID>", "channel": "email", "status": "granted", "source": "signup"}'

# Track an event
curl -X POST http://localhost:8000/api/events \
  -H "Content-Type: application/json" \
  -d '{"user_id": "<USER_ID>", "event_type": "track", "event_name": "pricing_view"}'

# Get next-best-action decision
curl -X POST http://localhost:8000/api/decisions/next-best-action \
  -H "Content-Type: application/json" \
  -d '{"user_id": "<USER_ID>"}'

πŸ’» Local Development

cd backend

# Create virtual environment
python -m venv venv && source venv/bin/activate

# Install dependencies
pip install -r requirements-dev.txt

# Run with hot-reload (uses SQLite by default)
uvicorn app.main:app --reload

# Or use Docker with hot-reload
make dev

See the full Development Guide.


πŸ“‘ API Overview

Endpoint Method Description
/api/health GET Liveness check
/api/ready GET Readiness check (DB connectivity)
/api/users GET, POST List / create users
/api/users/{id} GET, PUT, DELETE User CRUD
/api/users/{id}/scores GET Behavioral scores
/api/consents POST Record consent
/api/consents/{user_id} GET User consent records
/api/consents/{user_id}/summary GET Consent summary
/api/decisions/next-best-action POST Core NBA decision
/api/decisions/next-best-action/batch POST Batch NBA decisions
/api/decisions/{id}/explain POST Decision explainability
/api/events POST Track events
/api/audiences GET, POST Audience segments
/api/journeys/templates GET, POST Journey templates
/api/journeys/{user_id}/enroll POST Enroll in journey
/api/experiments GET, POST A/B experiments
/api/analytics/dashboard GET Dashboard metrics
/api/analytics/cohorts GET Cohort analysis
/api/analytics/funnels GET Funnel analysis
/api/analytics/attribution GET Channel attribution

Full API documentation: docs/API.md


πŸ“ Project Structure

Relevnace_Engine/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ main.py              # FastAPI application
β”‚   β”‚   β”œβ”€β”€ config.py            # Settings
β”‚   β”‚   β”œβ”€β”€ database.py          # SQLAlchemy setup
β”‚   β”‚   β”œβ”€β”€ api/                 # Route handlers (9 modules)
β”‚   β”‚   β”œβ”€β”€ engine/              # Core decision logic
β”‚   β”‚   β”‚   β”œβ”€β”€ next_best_action.py   # NBA engine
β”‚   β”‚   β”‚   β”œβ”€β”€ consent_engine.py     # Consent verification
β”‚   β”‚   β”‚   β”œβ”€β”€ fatigue.py            # Fatigue scoring
β”‚   β”‚   β”‚   β”œβ”€β”€ suppression.py        # Suppression rules
β”‚   β”‚   β”‚   └── scoring.py           # Behavioral scoring
β”‚   β”‚   β”œβ”€β”€ models/              # SQLAlchemy ORM (8 models)
β”‚   β”‚   β”œβ”€β”€ schemas/             # Pydantic validation (8 schemas)
β”‚   β”‚   └── agents/              # AI agents (5 agents)
β”‚   β”œβ”€β”€ tests/                   # pytest suite (10 test modules)
β”‚   β”œβ”€β”€ alembic/                 # Database migrations
β”‚   β”œβ”€β”€ Dockerfile
β”‚   └── requirements.txt
β”œβ”€β”€ helm/                        # Kubernetes Helm chart
β”‚   └── relevance-engine/
β”œβ”€β”€ docs/                        # Documentation
β”‚   β”œβ”€β”€ API.md
β”‚   β”œβ”€β”€ ARCHITECTURE.md
β”‚   β”œβ”€β”€ DEVELOPMENT.md
β”‚   └── DEPLOYMENT.md
β”œβ”€β”€ .github/workflows/           # CI/CD pipelines
β”‚   β”œβ”€β”€ ci.yml
β”‚   └── cd.yml
β”œβ”€β”€ docker-compose.yml           # Production stack
β”œβ”€β”€ docker-compose.dev.yml       # Dev overrides
β”œβ”€β”€ Makefile                     # Task runner
β”œβ”€β”€ AGENTS.md                    # Copilot agents context
└── .env.example                 # Environment template

πŸ’‘ Core Innovation: "Do Nothing" is a Valid Action

Most marketing platforms assume every user should receive a message. Relevance Engine challenges that assumption.

The NBA engine can return channel: "none" and action: "none" β€” meaning the best thing to do for this user right now is nothing. This happens when:

  • User is fatigued β€” too many recent contacts β†’ pause outreach
  • No consent β€” no channel has valid consent β†’ stay silent
  • Already activated β€” user has completed the goal β†’ stop nudging
  • Quiet hours β€” user's preferred quiet period β†’ defer
  • Frequency cap hit β€” daily/weekly limits reached β†’ wait

This approach leads to:

  • πŸ“‰ Lower unsubscribe rates
  • πŸ“ˆ Higher engagement when you do reach out
  • πŸ›‘οΈ Better compliance posture
  • πŸ’° More efficient marketing spend

πŸ”— Relationship to ConsentHub

Relevance Engine is designed as the action engine companion to B2B_Consent_Personalization (ConsentHub):

ConsentHub Relevance Engine
Role Consent management & personalization Decision & action execution
Decides What consent exists What to do with that consent
Owns Preference center, consent records NBA engine, journeys, experiments
Integration Provides consent data via API Consumes consent, acts on it

Configure the integration:

CONSENTHUB_API_URL=https://consenthub.example.com/api
CONSENTHUB_API_KEY=your-api-key

πŸ§ͺ Testing

make test              # Run all tests
make test-cov          # Run with coverage report
make lint              # Lint with ruff
make format            # Auto-format code

The test suite covers:

  • API endpoint tests (health, users, consents, decisions, events)
  • Core engine logic (NBA, consent, fatigue, suppression)
  • In-memory SQLite β€” no external services needed

🚒 Deployment

Docker Compose (recommended for single-server)

make up                # Production stack
make dev               # Development with hot-reload
make logs              # Tail logs
make clean             # Full cleanup

Kubernetes / Helm

helm install relevance-engine ./helm/relevance-engine \
  --namespace relevance-engine \
  --values values-production.yaml

See the full Deployment Guide.


πŸ“Š KPIs Tracked

KPI Description
Suppression Rate % of decisions where "do nothing" was the best action
Consent Coverage % of users with at least one active consent
Decision Confidence Average model confidence across NBA decisions
Channel Distribution Decision volume per channel
Fatigue Score (avg) Average user fatigue across the platform
Journey Completion Rate % of journey runs completed vs. started
Experiment Lift Measured improvement from A/B experiments
Engagement Rate Opens + clicks / decisions executed
Time-to-Action Latency from event to NBA decision

πŸ› οΈ Tech Stack

Layer Technology
API Framework FastAPI 0.115
Language Python 3.12
ORM SQLAlchemy 2.0
Database PostgreSQL 16
Cache Redis 7
Validation Pydantic 2.10
Auth python-jose (JWT) + passlib
Migrations Alembic
HTTP Client httpx
Testing pytest + pytest-cov + pytest-asyncio
Linting Ruff
Containers Docker + Docker Compose
Orchestration Kubernetes + Helm
CI/CD GitHub Actions

πŸ“„ License

This project is licensed under the Apache License 2.0 β€” see the LICENSE file for details.


Built with ❀️ for marketers who respect their users

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors