Automated Action 4730c37915 Implement comprehensive transaction fraud monitoring API
- Created FastAPI application with transaction ingestion endpoints
- Built dynamic rule engine supporting velocity checks and aggregations
- Implemented real-time and batch screening capabilities
- Added rule management with versioning and rollback functionality
- Created comprehensive audit and reporting endpoints with pagination
- Set up SQLite database with proper migrations using Alembic
- Added intelligent caching for aggregate computations
- Included extensive API documentation and example rule definitions
- Configured CORS, health endpoints, and proper error handling
- Added support for time-windowed aggregations (sum, count, avg, max, min)
- Built background processing for high-volume batch screening
- Implemented field-agnostic rule conditions with flexible operators

Features include transaction ingestion, rule CRUD operations, real-time screening,
batch processing, aggregation computations, and comprehensive reporting capabilities
suitable for fintech fraud monitoring systems.
2025-06-27 16:00:48 +00:00

43 lines
2.1 KiB
Python

from sqlalchemy import Column, Integer, String, Text, DateTime, Float
from sqlalchemy.sql import func
from app.db.base import Base
class ScreeningResult(Base):
__tablename__ = "screening_results"
id = Column(Integer, primary_key=True, index=True)
transaction_id = Column(String, index=True, nullable=False)
rule_id = Column(Integer, index=True, nullable=False)
rule_name = Column(String, nullable=False)
rule_version = Column(Integer, default=1)
status = Column(String, nullable=False) # flagged, clean, error
risk_score = Column(Float, default=0.0)
details = Column(Text, nullable=True) # JSON string with detailed results
aggregated_data = Column(Text, nullable=True) # JSON string with computed aggregations
screening_type = Column(String, default="real_time") # real_time, batch
created_at = Column(DateTime(timezone=True), server_default=func.now())
class ScreeningBatch(Base):
__tablename__ = "screening_batches"
id = Column(Integer, primary_key=True, index=True)
batch_id = Column(String, unique=True, index=True, nullable=False)
name = Column(String, nullable=True)
description = Column(Text, nullable=True)
status = Column(String, default="pending") # pending, processing, completed, failed
total_transactions = Column(Integer, default=0)
processed_transactions = Column(Integer, default=0)
flagged_transactions = Column(Integer, default=0)
rules_applied = Column(Text, nullable=True) # JSON array of rule IDs
started_at = Column(DateTime(timezone=True), nullable=True)
completed_at = Column(DateTime(timezone=True), nullable=True)
created_at = Column(DateTime(timezone=True), server_default=func.now())
class AggregateCache(Base):
__tablename__ = "aggregate_cache"
id = Column(Integer, primary_key=True, index=True)
cache_key = Column(String, unique=True, index=True, nullable=False)
cache_value = Column(Text, nullable=False) # JSON string
expires_at = Column(DateTime(timezone=True), nullable=False)
created_at = Column(DateTime(timezone=True), server_default=func.now())