Consent-first, AI-powered next-best-action marketing automation platform
Quick Start β’ Architecture β’ API β’ Full API Docs β’ Deployment
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.
| 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 |
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 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.
- Docker 24+ & Docker Compose v2+
# 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# 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>"}'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 devSee the full Development Guide.
| 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
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
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
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-keymake test # Run all tests
make test-cov # Run with coverage report
make lint # Lint with ruff
make format # Auto-format codeThe 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
make up # Production stack
make dev # Development with hot-reload
make logs # Tail logs
make clean # Full cleanuphelm install relevance-engine ./helm/relevance-engine \
--namespace relevance-engine \
--values values-production.yamlSee the full Deployment Guide.
| 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 |
| 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 |
This project is licensed under the Apache License 2.0 β see the LICENSE file for details.
Built with β€οΈ for marketers who respect their users