How mwasifanwar/finrisk-predictor works
Project type and purpose
• This is a backend‐focused, real-time anomaly detection system for financial transactions. It exposes both REST endpoints and WebSocket streams (via FastAPI) and embeds multiple ML stages (graph neural networks, LSTMs, ensembles, time‐series analysis) to flag fraud, money laundering, and market manipulation.
File structure
• Top-level files
• main.py / inference.py / train.py – entry points for serving, inference, and training.
• requirements.txt – Python dependencies.
• api/
• fastapi_server.py – initializes API server.
• endpoints.py – REST routes.
• websocket_handler.py – real-time push to clients.
• core/
• transaction_processor.py – orchestrates per-transaction workflow.
• feature_engineer.py (actually under data/) and time_series_analyzer.py – extract features/time patterns.
• graph_neural_network.py, anomaly_detector.py, risk_scorer.py – model-driven scoring logic.
• data/
• data_loader.py – pulls or streams raw data.
• feature_engineer.py – feature creation.
• synthetic_data.py – simulates data for training.
• models/
• gnn_models.py, lstm_models.py, ensemble_models.py – ML model definitions and loading.
• monitoring/
• performance_tracker.py, drift_detector.py, model_updater.py – runtime health, data drift, auto-retraining.
• utils/
• config_loader.py, alert_system.py, metrics_calculator.py, visualization.py – cross-cutting helpers.
• tests/ – unit tests for each component.
README
• Confirms goal: “Advanced anomaly detection system using graph neural networks and time series analysis to identify fraudulent transactions… in real-time data streams.”
a. Main components
1. External Data Sources (financial feeds, transaction logs)
2. Data Ingestion Layer (data_loader.py)
3. API Gateway (FastAPI REST & WebSocket)
4. Core Processing Engine
• Transaction Processor
• Feature Engineering & Time-Series Analyzer
• GNN / LSTM / Ensemble Models
• Anomaly Detector & Risk Scorer
5. Model Repository / Storage (serialized model files, metrics DB, time-series DB)
6. Monitoring & Alerting
• Drift Detector, Performance Tracker, Model Updater, Alert System
7. Training Pipeline (train.py + synthetic_data) for offline retraining
b. Relationships & interactions
• Data flow: External Sources → Ingestion → Core Processing → API responses & WebSocket pushes to clients.
• Monitoring taps into metrics emitted by Core Processing and Data Ingestion.
• Model Updater writes new model artifacts back to the Model Repository, which Core Processing loads at runtime.
• Training Pipeline reads historical/synthetic data, writes trained models to the repository.
c. Architectural patterns
• Layered separation: ingestion, API, business logic, storage, monitoring.
• Dependency inversion between core logic and data sources (via config_loader).
• ML pipelines broken into discrete stages (feature extraction → model inference → scoring).
d. Key technologies & frameworks
• Python 3.x, FastAPI, WebSockets
• PyTorch/TensorFlow (implied for GNN/LSTM)
• Time-series libraries (e.g., pandas, numpy)
• Monitoring: custom drift-detector, performance APIs
• Storage: any relational/NoSQL DB for metrics and models
Detail
• Config Loader and Alert System as utility blocks that interface across layers.
• Both synchronous (REST) and asynchronous (WebSocket, streaming) interactions.