A production-ready enterprise platform that ingests, processes, and analyzes DMARC aggregate reports with advanced ML-powered threat detection, distributed task processing, and comprehensive security features.
- π§ Automated DMARC Report Ingestion - IMAP inbox monitoring with Celery task queue
- π€ Bulk File Upload - Drag-and-drop 50-200 reports simultaneously
- π Idempotent Processing - SHA256-based duplicate prevention
- πΎ PostgreSQL Storage - Production-grade relational database
- π JWT Authentication - Role-based access control (Admin/Analyst/Viewer)
- π RESTful API - FastAPI with auto-generated documentation
- β Comprehensive Testing - 70%+ code coverage enforced
- π³ Docker Deployment - Single-command orchestration
- π Multi-Channel Alerting - Email, Slack, Discord, Microsoft Teams
- β‘ Celery + Redis Queue - Asynchronous background job processing
- π
Celery Beat Scheduler - Automated periodic tasks
- Email ingestion every 15 minutes
- Report processing every 5 minutes
- Alert checks hourly
- ML model training weekly
- πΈ Flower Dashboard - Real-time task monitoring at
:5555 - π Retry Logic - Exponential backoff with 3 attempts
- π Task Tracking - PostgreSQL result backend
- π JWT Authentication - Access tokens (15min) + refresh tokens (7 days)
- π₯ Role-Based Access Control - Admin, Analyst, Viewer roles
- π API Key Management - Per-user API keys with SHA256 hashing
- π‘οΈ Password Security - bcrypt hashing (12 rounds)
- π User Management - Admin-only user creation (no self-registration)
- π Token Refresh - Seamless token renewal
- π Audit Trail - User action tracking
- π― Alert Lifecycle - Created β Acknowledged β Resolved
- π Deduplication - SHA256 fingerprinting with cooldown periods
- β° Alert Suppressions - Time-based muting for maintenance windows
- π Alert History - Persistent storage with full lifecycle tracking
- π Configurable Rules - UI-based threshold management
- π Teams Priority - Microsoft Teams notifications sent first
- π Alert Analytics - Trends, resolution times, acknowledgment rates
- π€ Anomaly Detection - Isolation Forest ML model for suspicious IPs
- π IP Geolocation - MaxMind GeoLite2 offline mapping
- πΊοΈ Country Heatmaps - Geographic visualization of email sources
- π Model Management - Training, versioning, deployment
- π Automated Training - Weekly ML model updates (Sunday 2 AM)
- π― Daily Detection - Automatic anomaly scanning (3 AM)
- πΎ 90-Day Caching - Efficient geolocation data caching
- π Prediction History - ML prediction tracking and analytics
- β‘ Redis Caching - 90%+ hit rate, sub-200ms response times
- π§ Query Optimization - N+1 query elimination, indexed lookups
- π Auto-Invalidation - Cache clearing on new data
- π Connection Pooling - Optimized database and cache connections
- π 8 Interactive Charts:
- DMARC results timeline (line chart)
- Results by domain (bar chart)
- Top source IPs (bar chart)
- Disposition breakdown (pie chart)
- SPF/DKIM alignment breakdown (stacked bar)
- Policy compliance (doughnut chart)
- Failure rate trend with moving average (line chart)
- Top sending organizations (horizontal bar)
- π Source IP - Exact match or CIDR ranges
- π Authentication - DKIM/SPF pass/fail
- π Disposition - None/Quarantine/Reject
- π’ Organization - Sending organization filter
- π Date Range - Custom or preset ranges
- π Domain - Multi-domain filtering
- π CSV Exports - Reports, records, sources
- π PDF Reports - Professional summary with charts
- π Rate Limiting - 10/min CSV, 5/min PDF
- π‘οΈ Security - CSV formula injection prevention
- Framework: Python 3.11 + FastAPI
- Task Queue: Celery + Redis
- ML/Analytics: scikit-learn, NumPy, pandas
- Geolocation: MaxMind GeoLite2 + geoip2
- Auth: JWT (PyJWT), bcrypt
- Database: PostgreSQL 15 + SQLAlchemy 2.0
- Cache: Redis 7 (Alpine)
- PDF: ReportLab
- Stack: Vanilla HTML/CSS/JS + Chart.js v4.4.0
- Charts: Chart.js for visualizations
- Web Server: Nginx (reverse proxy)
- Orchestration: Docker Compose
- Services: Backend, Celery Worker, Celery Beat, PostgreSQL, Redis, Nginx, Flower
- Monitoring: Flower dashboard for Celery tasks
- Docker & Docker Compose
- MaxMind GeoLite2 database (free account)
- Email account with IMAP access (for automated ingestion)
- Microsoft Teams/Slack webhooks (for alerts)
git clone <repo-url>
cd dmarc- Sign up at: https://dev.maxmind.com/geoip/geolite2-free-geolocation-data
- Download GeoLite2-City.mmdb
- Place at:
backend/data/GeoLite2-City.mmdb
mkdir -p backend/data
# Copy GeoLite2-City.mmdb to backend/data/cp .env.sample .env
# Edit .env with your settingsRequired Settings:
# JWT Secret (generate with: python -c "import secrets; print(secrets.token_urlsafe(64))")
JWT_SECRET_KEY=your-secret-key-here
# Celery + Redis
USE_CELERY=true
CELERY_BROKER_URL=redis://redis:6379/0
# Database
DATABASE_URL=postgresql://dmarc:dmarc@db:5432/dmarc
# Email (optional - for automated ingestion)
EMAIL_HOST=imap.gmail.com
EMAIL_PORT=993
EMAIL_USER=your-email@example.com
EMAIL_PASSWORD=your-app-password
# Alerts (optional)
TEAMS_WEBHOOK_URL=https://your-teams-webhookdocker compose up -d --buildServices:
backend- FastAPI application (port 8000)celery-worker- Background task processorcelery-beat- Scheduled task schedulerflower- Celery monitoring UI (port 5555)db- PostgreSQL databaseredis- Cache & message brokernginx- Web server (port 80)
docker compose exec backend alembic upgrade headMigrations Applied:
001- Ingested reports table002- DMARC reports & records tables003- Performance indexes004- Celery task tracking005- User authentication006- Enhanced alerting007- ML analytics & geolocation
docker compose exec backend python scripts/create_admin_user.pyFollow the prompts to create your first admin user.
- Dashboard: http://localhost
- API Docs: http://localhost:8000/docs
- Flower (Tasks): http://localhost:5555
- Health Check: http://localhost/health
Use the admin credentials you created to login via the dashboard or API.
curl -X POST http://localhost:8000/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "admin@example.com",
"password": "your-password"
}'Response:
{
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGc...",
"refresh_token": "eyJ0eXAiOiJKV1QiLCJhbGc...",
"token_type": "bearer"
}curl -H "Authorization: Bearer <access_token>" http://localhost:8000/api/reportsPOST /auth/login- Login with email/passwordPOST /auth/refresh- Refresh access tokenPOST /auth/logout- Logout (invalidate tokens)
GET /users/me- Get current user profileGET /users- List all users (admin)POST /users- Create user (admin)PATCH /users/{id}- Update user (admin)DELETE /users/{id}- Delete user (admin)POST /users/api-keys- Generate API key
GET /api/domains- List domainsGET /api/reports- List reports (paginated)GET /api/reports/{id}- Get report detailsPOST /api/upload- Bulk file upload
GET /api/rollup/summary- Aggregate statisticsGET /api/rollup/sources- Top source IPsGET /api/rollup/alignment- DKIM/SPF alignmentGET /api/rollup/timeline- Time-series dataGET /api/rollup/failure-trend- Failure rate trends
GET /api/export/reports/csv- Export reports CSVGET /api/export/records/csv- Export records CSVGET /api/export/sources/csv- Export sources CSVGET /api/export/report/pdf- Generate PDF summary
GET /alerts/history- Alert historyGET /alerts/rules- Alert rulesPOST /alerts/rules- Create rule (admin)PATCH /alerts/{id}/acknowledge- Acknowledge alertPATCH /alerts/{id}/resolve- Resolve alertPOST /alerts/suppressions- Create suppression
GET /analytics/geolocation/map- Country heatmapGET /analytics/geolocation/lookup/{ip}- IP geolocationGET /analytics/ml/models- List ML modelsPOST /analytics/ml/train- Train model (admin)POST /analytics/ml/deploy- Deploy model (admin)POST /analytics/anomalies/detect- Detect anomaliesGET /analytics/anomalies/recent- Recent predictions
POST /tasks/trigger/email-ingestion- Trigger email fetchPOST /tasks/trigger/process-reports- Process pending reportsGET /tasks/status/{task_id}- Get task status
| Role | Permissions |
|---|---|
| Admin | Full access: users, models, rules, all data |
| Analyst | Read/write: reports, alerts, analytics |
| Viewer | Read-only: dashboards, reports, analytics |
Access at http://localhost:5555
Monitors:
- Active tasks
- Task history
- Worker status
- Task schedules (Beat)
# View all schedules
docker compose exec celery-beat celery -A app.celery_app inspect scheduled
# Force run a task
docker compose exec celery-worker celery -A app.celery_app call \
app.tasks.ml_tasks.train_anomaly_model_task# Run all tests with coverage
docker compose exec backend pytest -v --cov=app
# Run specific test suite
docker compose exec backend pytest tests/unit/ -v
docker compose exec backend pytest tests/integration/ -v
# Generate HTML coverage report
docker compose exec backend pytest --cov=app --cov-report=htmlCoverage: 70%+ enforced in CI/CD
- FEATURES.md - Complete feature list
- PHASE1_DEPLOYMENT.md - Celery setup
- PHASE2_DEPLOYMENT.md - Authentication setup
- PHASE3_DEPLOYMENT.md - Enhanced alerting setup
- PHASE4_DEPLOYMENT.md - ML analytics setup
- DEPLOYMENT.md - Production deployment
- TESTING.md - Testing documentation
- API Docs - Interactive Swagger UI
βββββββββββββββ ββββββββββββββββ ββββββββββββββ
β Nginx ββββββΆβ Backend ββββββΆβ PostgreSQL β
β (Port 80) β β (FastAPI) β β (DB) β
βββββββββββββββ ββββββββ¬ββββββββ ββββββββββββββ
β
βΌ
βββββββββββββββ ββββββββββββββββ
β Redis ββββββΆβCelery Worker β
β (Broker) β β + Beat β
βββββββββββββββ ββββββββββββββββ
β
βΌ
βββββββββββββββ
β Flower β
β (Monitor) β
βββββββββββββββ
# View logs
docker compose logs -f backend
docker compose logs -f celery-worker
# Rebuild after code changes
docker compose up --build -d backend
# Create new migration
docker compose exec backend alembic revision --autogenerate -m "description"
# Reset database (WARNING: deletes all data)
docker compose down -v
docker compose up -d
docker compose exec backend alembic upgrade head
docker compose exec backend python scripts/create_admin_user.pySee backend/DEPLOYMENT.md for:
- SSL/TLS with Let's Encrypt
- Database backups
- Security hardening
- Performance tuning
- Monitoring setup
Minimum:
- CPU: 2 cores
- RAM: 4GB
- Storage: 10GB
Recommended:
- CPU: 4+ cores
- RAM: 8GB
- Storage: 50GB+ (depends on volume)
MIT
Version: 2.0.0 (Enterprise Edition) Last Updated: January 2026 Status: β Production Ready