A production-ready AI-powered marketing automation platform with enterprise security, performance monitoring, and comprehensive API endpoints.
- Guaranteed Structured Output with OpenAI function calling
- Type-Safe Processing using Pydantic models
- 7-Step Content Pipeline: SEO, Marketing Brief, Article Generation, SEO Optimization, Internal Docs, Content Formatting, Design Kit
- Quality Scoring with confidence metrics for every step
- Human-in-the-Loop approval system for quality control
- Template-Based Prompts with Jinja2 for easy customization
- API Key Authentication with role-based access control
- Advanced Rate Limiting with attack detection and IP whitelisting
- Input Validation preventing SQL injection, XSS, and command injection
- Security Audit Logging with comprehensive event tracking
- Content Sanitization and validation
- 20% Faster than agent-based approach
- 10% Lower Costs with optimized token usage
- Intelligent Caching with TTL and LRU eviction
- Connection Pooling for database optimization
- Real-time Performance Monitoring with metrics collection
- SQL Databases: SQLite, PostgreSQL, MySQL
- NoSQL Databases: MongoDB, Redis
- Content Sources: File, API, Web Scraping, Webhook
- Health Monitoring and connection management
- Docker & Kubernetes deployment with HPA and monitoring
- AWS CloudFormation templates for complete infrastructure deployment
- CI/CD Pipeline with security scanning and performance testing
- Comprehensive Testing with 1,350+ tests covering all critical paths
- API Documentation with Swagger/OpenAPI
- Monitoring & Observability with Prometheus and Grafana
# Clone
git clone https://github.com/your-org/marketing-project.git
cd marketing-project
# Create virtual environment (recommended)
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# UDPipe English model is automatically downloaded on first use
# If you need to download it manually, it will be cached at ~/.udpipe/models/
# For development (optional)
pip install -r requirements-dev.txt
# Install the project in development mode
pip install -e .
# Set up environment
cp env.example .env
# Fill .env with your secrets (especially OPENAI_API_KEY)
# Redis defaults work for local development (localhost:6379)
# Run the marketing project
python -m marketing_project.main run
# Start the API server
python -m marketing_project.main serve
# Run tests
pytest
# Run security and database tests
python test_security_and_database.py
# Run load tests
python run_load_test.py --url http://localhost:8000 --test basic# Start all services (Redis, API, Worker)
cd deploy/docker
docker-compose -f docker-compose.dev.yml up -d
# Check service health
docker-compose -f docker-compose.dev.yml ps
# View logs
docker-compose -f docker-compose.dev.yml logs -f api
docker-compose -f docker-compose.dev.yml logs -f worker
# Stop services
docker-compose -f docker-compose.dev.yml down# Start all services
cd deploy/docker
docker-compose up -d
# Check service health
docker-compose ps
# View logs
docker-compose logs -f api
# Stop services
docker-compose downThe Marketing Project provides a comprehensive REST API with enterprise-grade security and performance monitoring.
| Method | Endpoint | Description | Authentication |
|---|---|---|---|
POST |
/api/v1/process/blog |
Process blog posts through AI pipeline | API Key |
POST |
/api/v1/process/transcript |
Process transcripts (podcasts, videos) | API Key |
POST |
/api/v1/process/release-notes |
Process software release notes | API Key |
POST |
/api/v1/analyze |
Analyze content for marketing insights | API Key |
POST |
/api/v1/pipeline |
Run complete pipeline with auto-routing | API Key |
| Method | Endpoint | Description | Authentication |
|---|---|---|---|
GET |
/api/v1/content-sources |
List all content sources | API Key |
GET |
/api/v1/content-sources/{name}/status |
Get source status | API Key |
POST |
/api/v1/content-sources/{name}/fetch |
Fetch content from source | API Key |
| Method | Endpoint | Description | Authentication |
|---|---|---|---|
GET |
/api/v1/jobs/{job_id}/status |
Get job status and progress | API Key |
GET |
/api/v1/jobs/{job_id}/result |
Get completed job results | API Key |
GET |
/api/v1/jobs |
List all jobs with filtering | API Key |
| Method | Endpoint | Description | Authentication |
|---|---|---|---|
GET |
/api/v1/onboarding-examples |
List active quick-start job templates | JWT |
GET |
/api/v1/onboarding-examples/admin |
List all templates including inactive (admin) | JWT (admin) |
POST |
/api/v1/onboarding-examples/admin |
Create a new template (admin) | JWT (admin) |
GET |
/api/v1/onboarding-examples/admin/{id} |
Get single template by ID (admin) | JWT (admin) |
PATCH |
/api/v1/onboarding-examples/admin/{id} |
Update a template (admin) | JWT (admin) |
DELETE |
/api/v1/onboarding-examples/admin/{id} |
Delete a template (admin) | JWT (admin) |
| Method | Endpoint | Description | Authentication |
|---|---|---|---|
GET |
/api/v1/analytics/dashboard |
Dashboard statistics (admin) | JWT (admin) |
GET |
/api/v1/analytics/quality-scores |
Per-job quality score history with pagination | JWT (admin) |
GET |
/api/v1/analytics/monitoring/unified |
Unified monitoring metrics | JWT (admin) |
GET |
/api/v1/analytics/monitoring/cost |
Cost tracking metrics | JWT (admin) |
GET |
/api/v1/analytics/monitoring/quality |
Quality trend analysis | JWT (admin) |
| Method | Endpoint | Description | Authentication |
|---|---|---|---|
GET |
/api/v1/health |
Health check for Kubernetes probes | None |
GET |
/api/v1/ready |
Readiness check for Kubernetes probes | None |
GET |
/api/v1/performance/summary |
Get performance summary and metrics | JWT |
GET |
/api/v1/security/audit |
Get security audit logs | JWT |
GET |
/api/v1/cache/stats |
Get cache statistics | JWT |
The application uses Keycloak for authentication and authorization. All protected endpoints require a valid JWT token from Keycloak.
- Authenticate with Keycloak through the frontend application, or
- Use Keycloak's token endpoint directly:
curl -X POST "https://your-keycloak-server.com/realms/your-realm/protocol/openid-connect/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "client_id=your-client-id" \
-d "client_secret=your-client-secret" \
-d "grant_type=client_credentials" \
-d "scope=openid"Include the token in the Authorization header:
curl -H "Authorization: Bearer your-access-token-here" \
-H "Content-Type: application/json" \
-d '{"content": {"id": "test", "title": "Test", "content": "Test content", "snippet": "Summary"}}' \
http://localhost:8000/api/v1/process/blogThe following endpoints do not require authentication:
GET /api/v1/health- Health checkGET /api/v1/ready- Readiness check
Some endpoints may require specific roles:
- Admin-only endpoints require the
adminrole - Editor endpoints require the
editororadminrole - Regular user endpoints are accessible to all authenticated users
For detailed Keycloak setup instructions, see docs/KEYCLOAK_SETUP.md.
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc - OpenAPI Schema:
http://localhost:8000/openapi.json
The core of this project is a sophisticated 7-step AI pipeline built on OpenAI's function calling feature.
Content Input
β
Simplified Processor (blog, transcript, or release notes)
β
FunctionPipeline (orchestrates 7 AI function calls)
β
βββββββββββββββββββββββββββββββββββββββββββ
β Step 1: SEO Keywords β
β Step 2: Marketing Brief β
β Step 3: Article Generation β
β Step 4: SEO Optimization β
β Step 5: Internal Documentation β
β Step 6: Content Formatting β
β Step 7: Design Kit & Visual Elements β
βββββββββββββββββββββββββββββββββββββββββββ
β
Structured JSON Result (Pydantic models)
β Guaranteed Structured Output - Every step returns typed JSON β 20% Faster - No agent reasoning loops, direct function calls β 10% Cheaper - Optimized token usage, no redundant processing β Type-Safe - Pydantic models prevent runtime errors β Quality Metrics - Confidence scores for every step β Human Approval - Optional review before finalizing β Template-Based - Easy to customize prompts via Jinja2
from marketing_project.processors import process_blog_post
import json
content = {
"id": "blog-123",
"title": "10 Marketing Tips",
"content": "Here are 10 proven marketing strategies...",
"snippet": "Top marketing tips for 2025",
"author": "Jane Smith",
"tags": ["marketing", "tips", "strategy"]
}
result_json = await process_blog_post(json.dumps(content))
result = json.loads(result_json)
# Access structured pipeline results
seo_keywords = result["pipeline_result"]["step_results"]["seo_keywords"]
marketing_brief = result["pipeline_result"]["step_results"]["marketing_brief"]
final_content = result["pipeline_result"]["final_content"]- API Key Authentication: Secure API key validation with role-based access
- Rate Limiting: Advanced rate limiting with IP and user-based limits
- Attack Detection: Automatic detection and blocking of suspicious patterns
- IP Whitelisting: Configurable IP whitelist for trusted sources
- SQL Injection Prevention: Pattern detection and query sanitization
- XSS Protection: Script injection detection and content sanitization
- Command Injection Prevention: Shell command pattern blocking
- Content Validation: Comprehensive input validation and sanitization
- Audit Logging: Comprehensive security event logging
- Risk Scoring: Automatic risk assessment for requests
- Anomaly Detection: Detection of unusual access patterns
- Security Alerts: Real-time security event notifications
- Real-time Metrics: Request/response time, memory, CPU usage
- Performance Dashboards: Built-in performance monitoring
- Load Testing: Comprehensive load testing framework
- Query Optimization: Automatic database query optimization
- Intelligent Caching: LRU cache with TTL support
- Connection Pooling: Database connection optimization
- Query Caching: Automatic query result caching
- Response Compression: Automatic response compression
# Basic load test
python run_load_test.py --url http://localhost:8000 --test basic
# Stress test
python run_load_test.py --url http://localhost:8000 --test stress
# Comprehensive test
python run_load_test.py --url http://localhost:8000 --test all# Build and run with Docker Compose
cd deploy/docker
docker-compose up -d
# Build production image
docker build -t marketing-project-api:latest -f deploy/docker/Dockerfile .
# Scale workers
docker-compose up -d --scale worker=4# Deploy to Kubernetes
kubectl apply -k deploy/k8s/
# Check deployment status
kubectl get pods -n marketing-project
# View logs
kubectl logs -f -n marketing-project deployment/marketing-project-api# Set required environment variables
export OPENAI_API_KEY="your_openai_api_key_here"
export API_KEY="your_32_character_minimum_api_key_here"
export DATABASE_PASSWORD="your_database_password_here"
export MONGODB_PASSWORD="your_mongodb_password_here"
# Deploy to AWS
cd deploy/aws
./deploy-aws.sh -e production -r us-east-2See deploy/AWS_DEPLOYMENT.md for detailed AWS deployment instructions.
Copy env.example to .env and configure:
To enable telemetry tracing with Arthur, set the following environment variables:
ARTHUR_BASE_URL: Base URL for Arthur API (default:http://localhost:3030)ARTHUR_API_KEY: API key for Arthur authentication (required for telemetry)ARTHUR_TASK_ID: Task ID for Arthur (required for telemetry, must haveis_agentic=True)
If these variables are not set, the application will run normally without telemetry. Telemetry initialization is non-blocking and will not prevent the application from starting if misconfigured.
- API keys and authentication
- Database connections
- Security settings
- Performance monitoring
- Logging configuration
Templates live under src/marketing_project/prompts/${TEMPLATE_VERSION}/{en,fr,...}/. Set TEMPLATE_VERSION=v1 in your .env.
To add a new language:
# Copy English templates
cp -r src/marketing_project/prompts/v1/en src/marketing_project/prompts/v1/es
# Translate the .j2 files
# Update your .env or environment
export LANG=esmarketing-project/
βββ src/marketing_project/ # Main application code
β βββ api/ # FastAPI routes and endpoints
β βββ core/ # Core models and utilities
β βββ processors/ # Content processors (blog, transcript, release notes)
β βββ services/ # Business logic and external integrations
β β βββ function_pipeline.py # AI function pipeline orchestrator
β βββ prompts/ # Jinja2 templates for AI prompts
β β βββ v1/en/ # English prompt templates
β βββ middleware/ # FastAPI middleware (auth, logging, cors)
β βββ models/ # Pydantic data models
β βββ config/ # Configuration management
βββ tests/ # Test suite (1,350+ tests)
β βββ api/ # API endpoint tests
β βββ services/ # Service layer tests
β βββ plugins/ # Plugin tests
βββ deploy/ # Deployment configurations
β βββ docker/ # Docker and docker-compose files
β βββ k8s/ # Kubernetes manifests
β βββ aws/ # AWS CloudFormation templates
βββ docs/ # Documentation
βββ content/ # Sample content for testing
βββ requirements.txt # Python dependencies
This project follows a clean, simple architecture:
- Function-Based Pipeline - Direct OpenAI function calls with structured outputs
- Type-Safe Processing - Pydantic models for all data structures
- Template-Driven Prompts - Jinja2 templates for easy customization
- Multi-Locale Support - Internationalization ready
- Comprehensive Testing - pytest with async support
- Docker & K8s Ready - Production deployment ready
- Modern Python - Type hints, async/await, and best practices
-
Processors (
src/marketing_project/processors/)- Simple, focused processors for each content type
- Validate input with Pydantic models
- Call FunctionPipeline for AI processing
- Return structured JSON results
-
FunctionPipeline (
src/marketing_project/services/function_pipeline.py)- Orchestrates 7-step AI pipeline
- Uses OpenAI function calling for guaranteed JSON
- Loads prompts from Jinja2 templates
- Returns typed Pydantic models
-
Templates (
src/marketing_project/prompts/v1/en/)- Comprehensive 100-170 line prompts
- Best practices and guidelines
- Easy to customize and version
-
API Layer (
src/marketing_project/api/)- FastAPI endpoints
- Authentication and authorization
- Job queue integration
- Health checks and monitoring
# Install dependencies
pip install -r requirements.txt
# Install development dependencies
pip install -r requirements-dev.txt
# Add a new dependency
pip install package-name
# Then update requirements.txt manually
# Update dependencies
pip install --upgrade -r requirements.txt
# Show installed packages
pip list
# Freeze current environment
pip freeze > requirements-current.txtThe project includes complete Kubernetes manifests for production deployment:
# Deploy to Kubernetes
kubectl apply -k deploy/k8s/
# Or deploy individual components
kubectl apply -f deploy/k8s/namespace.yml
kubectl apply -f deploy/k8s/configmap.yml
kubectl apply -f deploy/k8s/deployment.yml
kubectl apply -f deploy/k8s/service.yml
kubectl apply -f deploy/k8s/ingress.yml
kubectl apply -f deploy/k8s/hpa.yml
kubectl apply -f deploy/k8s/cronjob.yml- Auto-scaling - HPA based on CPU and memory usage
- Health checks - Liveness and readiness probes
- TLS termination - Secure HTTPS access
- Resource limits - Prevents resource exhaustion
- Scheduled execution - CronJob for automated processing
- Monitoring ready - Metrics endpoint and structured logging
See deploy/k8s/README.md for detailed deployment instructions.
See docs/ for:
- Architecture diagrams
- API reference
- Deployment guides
- Development guidelines
Please read CONTRIBUTING.md for development guidelines and best practices.
This project is licensed under the MIT License. See LICENSE for details.
- β Migration to Function Pipeline - 83% code reduction, 20% faster
- β Quality Scoring - Confidence metrics for all pipeline steps
- β Human-in-the-Loop - Approval system for quality control
- β Template System - Easy prompt customization with Jinja2
- β Simplified Architecture - Clean, maintainable codebase
- β Comprehensive Documentation - 7,400+ lines of documentation
For migration details, see the documentation files in the project root.