executor1389/RealTimeCreditCardFraudDetectionApi
0
1# ๐๏ธ System Architecture: FraudShield AI2 3This document provides a deep dive into the technical design and data flow of the FraudShield AI ecosystem.4 5## ๐ก Overall Data Flow6 7The system follows a modern MLOps pattern, separating the training/validation environment from the high-performance serving environment.8 9```mermaid10graph TD11 A["Raw Data (Kaggle CSV)"] --> B["Data Validation (Pandas/Great Expectations)"]12 B --> C["Model Training (LightGBM)"]13 C --> D["Experiment Tracking (MLflow/DagsHub)"]14 D --> E["Model Artifact (src/model.txt)"]15 16 E --> F["FastAPI Serving Layer"]17 G["User Frontend (JS/CSS)"] --> F18 F --> H["Real-Time Prediction"]19 20 H --> I["Monitoring (Evidently AI)"]21 H --> J["Metrics (Prometheus)"]22 23 subgraph "Cloud Deployment (Hugging Face / Vercel)"24 F25 G26 end27```28 29## ๐ ๏ธ Component Breakdown30 31### 1. Data Foundation Layer32* **Dataset**: Uses the real Kaggle "Credit Card Fraud Detection" dataset (284k+ rows).33* **Validation**: Every time data is processed, `scripts/data_validation.py` ensures schema integrity (30 features, no nulls, correct price ranges).34* **Versioning**: DVC is used to track data versions without bloat the Git repository.35 36### 2. Model Engineering Layer37* **Algorithm**: LightGBM was chosen for its extreme speed and ability to handle the 1:578 class imbalance ratio via `scale_pos_weight`.38* **Features**: 30 total (Time, V1-V28, and Amount).39* **Tracking**: Every training run is logged to **DagsHub (MLflow)**, tracking hyperparameters, metrics (F1-score, Recall), and the final model file.40 41### 3. Serving & Infrastructure42* **API**: A FastAPI application ([src/app.py](src/app.py)) provides a `/predict` endpoint.43* **Frontend**: A responsive, glassmorphic UI ([frontend/index.html](frontend/index.html)) communicates with the API.44* **Containerization**: The entire app is wrapped in a **Docker** image for easy deployment.45 46### 4. CI/CD Pipeline47* **GitHub Actions**: On every push, the system:48 1. Installs system dependencies (`libgomp1`).49 2. Generates a fresh mock dataset for testing.50 3. Validates the code via a smoke test.51 4. Automatically pushes to **Hugging Face Spaces**.52 53### 5. Monitoring & Observability54* **Drift Detection**: Evidently AI analyzes the difference between production input and training data to detect "Model Decay."55* **Metrics**: Prometheus scrapes transaction volume and latency from the API.56 57---58*Return to [README.md](README.md)*59 