Local-first foundation for a real-time fraud detection platform with:
- synthetic transaction generation (Spark)
- reproducible data workflow orchestration (DVC)
- model tracking and registry (MLflow)
- observability stack (Prometheus + Grafana)
- online serving API and UI (FastAPI + Redis)
flowchart LR
A[Raw Transactions\nSpark Generator] --> B[Offline Features\nParquet + DVC]
B --> C[Training Pipeline]
C --> D[MLflow Registry\nModel Stage]
B --> E[Redis Online Features]
D --> F[FastAPI Inference API]
E --> F
F --> G[Prediction Clients]
F --> H[Prometheus Metrics]
H --> I[Grafana Dashboards]
The current repository includes runnable data generation, training, serving, monitoring, and a full local Docker runtime stack.
configs/- feature, model, and monitoring configsdata/- raw, processed, and feature datasetsdocker/- container provisioning assetspipelines/- orchestration code (planned)src/- data, training, serving, and monitoring modulestests/- smoke and integration checksdvc.yaml- stage graph for reproducible pipeline executiondocker-compose.yml- local platform stack
Implemented in code:
src/data_pipeline/generate_data.pysynthetic data generationsrc/data_pipeline/build_features.py,validate_data.py,push_to_redis.pysrc/training/train.pytraining and MLflow logging fallbacksrc/serving/app.pyFastAPI inference API with transaction UI at/uisrc/monitoring/generate_monitoring_report.pymonitoring summary output- MLflow/Postgres/Redis/Prometheus/Grafana services in
docker-compose.yml docker/mlflow.Dockerfilecustom MLflow image withpsycopg2-binaryfor Postgres backend support- Prometheus scrape config and Grafana datasource provisioning
Verified in this workspace:
- feature generation, validation, training, Redis dry-run publishing, serving smoke tests, and monitoring report generation
- Docker-backed startup of MLflow, Redis, Prometheus, Grafana, and the API
- API/UI endpoint checks (
/docs,/ui) and MLflow/Grafana availability checks - static file checks for the updated code and docs
Planned but not yet implemented in this repo:
- broader CI and release automation
- richer end-to-end tests across data generation to prediction API
The DVC and Docker Compose files reference implemented components with a local development focus.
- Python 3.13
- Java 21 (for Spark local runtime compatibility in current script)
- Docker Desktop with Compose v2
- Git
python -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install --upgrade pippip install -r requirements/data.txtOptional role-specific installs:
pip install -r requirements/training.txt
pip install -r requirements/serving.txt
pip install -r requirements/monitoring.txtpython src/data_pipeline/generate_data.pyOutput:
data/raw/transactions.parquet
Run the serving API from the local venv:
.\.venv\Scripts\python.exe -m uvicorn serving.app:app --app-dir src --host 0.0.0.0 --port 8000Key endpoints:
GET /ui(interactive transaction form for fraud detection)GET /health/liveGET /health/readyPOST /predictGET /metrics
Primary local URLs:
- UI: http://localhost:8000/ui
- API docs: http://localhost:8000/docs
Run smoke tests:
.\.venv\Scripts\python.exe -m unittest tests/test_serving_smoke.py -vRun the full stack via Docker Compose:
docker compose up -dGenerate the monitoring report from current offline features and training metrics:
.\.venv\Scripts\python.exe src/monitoring/generate_monitoring_report.pyOutput:
data/processed/monitoring_report.json
Grafana dashboard provisioning is defined in:
docker/grafana/provisioning/dashboards/dashboards.ymldocker/grafana/dashboards/fraud-api-overview.json
Start core platform services:
docker compose up -d postgres mlflow redis prometheus grafanaStart full stack including API:
docker compose up -dEndpoints:
- MLflow: http://localhost:5000
- Prometheus: http://localhost:9090
- Grafana: http://localhost:3000 (admin/admin)
- API UI: http://localhost:8000/ui
- API docs: http://localhost:8000/docs
Stop services:
docker compose downRemove services and volumes:
docker compose down -vdvc.yaml defines a complete pipeline, and the implemented scripts now cover the declared stages in the repository.
Safe command now:
dvc repro generate_raw_dataThe remaining limitation is runtime infrastructure: MLflow, Redis, Prometheus, and Grafana still depend on Docker Desktop being available in this workspace.
Implemented executable stages include raw generation, feature building, validation, training, Redis publishing, and monitoring report generation.
Build PDF with Dockerized LaTeX (recommended in this workspace):
docker run --rm -v "${PWD}:/work" -w /work/docs/book blang/latex:ctanfull pdflatex -interaction=nonstopmode -halt-on-error main.tex
docker run --rm -v "${PWD}:/work" -w /work/docs/book blang/latex:ctanfull pdflatex -interaction=nonstopmode -halt-on-error main.tex