Skip to content

yash-blip-ys/fintrust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

6 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Fintech Anomaly Detection & Privacy Protection System

A comprehensive behavior-based authentication and privacy-preserving data sharing system for fintech applications, featuring real-time anomaly detection, smart contract integration, and differential privacy.


๐Ÿ—๏ธ Architecture Overview

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Frontend      โ”‚    โ”‚  Flask Gateway   โ”‚    โ”‚ Spring Boot Microservices    โ”‚
โ”‚ (React, MUI)    โ”‚โ”€โ”€โ”€โ–ถโ”‚ (app.py)         โ”‚โ”€โ”€โ”€โ–ถโ”‚ - Authentication (BBA, ML)   โ”‚
โ”‚                 โ”‚    โ”‚ - Anomaly Check  โ”‚    โ”‚ - DigiLocker Integration     โ”‚
โ”‚ - User Flows    โ”‚    โ”‚ - Smart Contract โ”‚    โ”‚ - Third-party Request/Consentโ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                               โ”‚   MongoDB                    โ”‚
                                               โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“ Project Structure

fintust-canara/
โ”œโ”€โ”€ app.py                        # Flask API Gateway with anomaly detection
โ”œโ”€โ”€ backend/
โ”‚   โ”œโ”€โ”€ authentication/           # Behavior-based authentication & anomaly detection
โ”‚   โ”‚   โ””โ”€โ”€ src/main/java/com/fintech/fintrust/authentication/
โ”‚   โ”‚       โ”œโ”€โ”€ model/            # User, UserBehavior, AnomalyDetectionResult, etc.
โ”‚   โ”‚       โ”œโ”€โ”€ service/          # AuthService, AnomalyDetectionService, etc.
โ”‚   โ”‚       โ”œโ”€โ”€ controller/       # AuthController, AnomalyDetectionController
โ”‚   โ”‚       โ”œโ”€โ”€ repository/       # UserRepository, UserBehaviorRepository
โ”‚   โ”‚       โ””โ”€โ”€ security/         # JWT, OAuth2, AnomalyDetectionFilter
โ”‚   โ”œโ”€โ”€ api/                      # DigiLocker integration microservice
โ”‚   โ”‚   โ””โ”€โ”€ src/main/java/com/digilocker/integration/api/
โ”‚   โ”‚       โ”œโ”€โ”€ controller/       # DigiLocker OAuth2, document, health endpoints
โ”‚   โ”‚       โ”œโ”€โ”€ service/          # DigiLockerOAuth2Service, DocumentService
โ”‚   โ”‚       โ”œโ”€โ”€ repository/       # DigiLockerAuthRepository, UserRepository
โ”‚   โ”‚       โ”œโ”€โ”€ config/           # Security, RateLimiting, DigiLockerConfig
โ”‚   โ”‚       โ””โ”€โ”€ util/             # JWT, HMAC, AES, RateLimiter
โ”‚   โ””โ”€โ”€ request/                  # Third-party request, consent, and data minimization
โ”‚       โ””โ”€โ”€ src/main/java/com/thirdparty/user/request/
โ”‚           โ”œโ”€โ”€ controller/       # RequestController (initiate, consent, submit, etc.)
โ”‚           โ”œโ”€โ”€ service/          # RequestService, AsyncBlockchainService
โ”‚           โ”œโ”€โ”€ domain/           # Request, Consent, UserBehavior, DocumentMeta
โ”‚           โ”œโ”€โ”€ repository/       # RequestRepository, UserRepository
โ”‚           โ”œโ”€โ”€ filter/           # AnomalyDetectionFilter
โ”‚           โ””โ”€โ”€ util/             # JWT, etc.
โ”œโ”€โ”€ frontend/                     # React + TypeScript frontend
โ”‚   โ”œโ”€โ”€ src/                      # Main source code (UI, API calls)
โ”‚   โ””โ”€โ”€ public/                   # Static assets
โ””โ”€โ”€ README.md

๐Ÿงฉ Module Descriptions

1. backend/authentication

  • Purpose: Implements behavior-based authentication, user/session management, and real-time anomaly detection using ML/statistical models. Handles smart contract validation and privacy-preserving data sharing logic.
  • Key Features:
    • User registration, login, JWT/OAuth2
    • Behavioral trait collection (typing, touch, device, session)
    • Anomaly detection and risk scoring
    • Smart contract execution control
    • Privacy-preserving data minimization

2. backend/api

  • Purpose: Integrates with DigiLocker for secure document access, OAuth2 flows, and document verification. Handles secure storage and retrieval of DigiLocker tokens and documents.
  • Key Features:
    • OAuth2 authorization with DigiLocker
    • Secure document fetch, download, and verification
    • Token encryption, HMAC validation, and rate limiting
    • Health and status endpoints

3. backend/request

  • Purpose: Manages third-party requests for user data, consent handling, document attachment, and blockchain submission. Orchestrates data minimization and privacy compliance for external requests.
  • Key Features:
    • Initiate and track data/consent requests
    • Field-level and full consent management
    • Document upload and validation
    • Submit requests to blockchain (with async support)
    • Integrates with Flask API for data minimization
    • Anomaly detection filter for all requests

4. frontend

  • Purpose: Provides a modern, secure, and responsive UI for users to interact with authentication, consent, and document flows. Built with React, TypeScript, and Material UI.
  • Key Features:
    • User authentication and secure flows
    • Dashboard, document management, consent handling (in progress)
    • Responsive, accessible design
    • API integration with backend services

5. app.py (Flask Gateway)

  • Purpose: Serves as the API gateway, handling anomaly detection, smart contract validation, and routing requests to backend microservices. Performs real-time risk assessment and privacy-preserving data minimization.

๐Ÿš€ Quick Start

Prerequisites

  • Java 17+
  • Python 3.8+
  • Node.js 16+
  • MongoDB 5.0+
  • Maven 3.6+

1. Start Backend Microservices

# Authentication Service
cd backend/authentication
mvn spring-boot:run

# DigiLocker API Service
cd ../api
mvn spring-boot:run

# Third-party Request Service
cd ../request
mvn spring-boot:run

2. Start the Flask Gateway

python app.py

3. Start the Frontend

cd frontend
npm install
npm start

4. Test the System

Example API Request with Behavioral Data

curl -X POST http://localhost:5000/api/requests/123/submitForm \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "X-User-ID: user123" \
  -H "X-Session-ID: session456" \
  -H "X-Device-ID: device789" \
  -H "X-User-Location: 12.9716,77.5946" \
  -H "X-Typing-Pattern: {\"averageSpeed\": 0.5, \"variance\": 0.1}" \
  -H "X-Touch-Pattern: {\"pressure\": 0.8, \"duration\": 0.2}" \
  -F 'payload={
    "use_case": "Credit Card Issuance",
    "form_data": {
      "text_fields": {"Phone Number": "9876543210"},
      "file_uploads": {}
    }
  }'

Anomaly Detection API

# Detect anomaly
curl -X POST http://localhost:8089/api/anomaly/detect \
  -H "Content-Type: application/json" \
  -d '{
    "userId": "user123",
    "deviceId": "device789",
    "ipAddress": "192.168.1.1",
    "actionType": "API_REQUEST"
  }'

# Execute smart contract
curl -X POST http://localhost:8089/api/anomaly/smart-contract/execute \
  -H "Content-Type: application/json" \
  -d '{
    "userId": "user123",
    "contractFunction": "transferFunds",
    "parameters": {"amount": 1000, "recipient": "user456"}
  }'

๐Ÿ”ง Configuration

Anomaly Detection Thresholds

// In AnomalyDetectionService.java
private static final double TYPING_ANOMALY_THRESHOLD = 0.7;
private static final double TOUCH_ANOMALY_THRESHOLD = 0.6;
private static final double LOCATION_ANOMALY_THRESHOLD = 0.8;
private static final double SESSION_ANOMALY_THRESHOLD = 0.5;
private static final double OVERALL_ANOMALY_THRESHOLD = 0.6;

Privacy Settings

// In PrivacyPreservingDataService.java
private static final double EPSILON = 0.1; // Differential privacy parameter
private static final String ALGORITHM = "AES/GCM/NoPadding";

๐Ÿ“Š Behavioral Traits Analyzed

1. Typing Patterns

  • Typing Speed: Characters per second
  • Typing Variance: Consistency in typing rhythm
  • Pause Duration: Time between keystrokes
  • Backspace Frequency: Error correction patterns
  • Key Press Intervals: Timing between specific keys

2. Touch Patterns

  • Tap Pressure: Force applied to screen
  • Tap Duration: How long touches are held
  • Swipe Velocity: Speed of swipe gestures
  • Swipe Distance: Length of swipe movements
  • Touch Area: Where on screen user touches

3. Location Patterns

  • Geographic Location: GPS coordinates
  • Location History: Travel patterns
  • Location Hash: Privacy-preserving location data
  • Distance from Usual Location: Anomaly detection

4. Device Patterns

  • Device ID: Known vs unknown devices
  • Device Type: Mobile, tablet, desktop
  • Device Model: Specific device characteristics
  • IP Address: Network location

5. Session Patterns

  • Session Duration: How long sessions last
  • Request Frequency: API call patterns
  • Navigation Flow: Page-to-page movement
  • Time of Day: Usage patterns

๐Ÿ›ก๏ธ Security Measures

Risk Levels & Responses

  • LOW (0.0-0.3): Basic monitoring, allow access
  • MEDIUM (0.3-0.6): Enhanced monitoring, limited features
  • HIGH (0.6-0.8): Multi-factor authentication required
  • CRITICAL (0.8-1.0): Immediate block, account freeze

Smart Contract Security

  • Execution Control: Only executes when anomaly score < 0.8
  • Multi-signature: Required for high-value transactions
  • Time Locks: Delayed execution for suspicious activities
  • Audit Trail: Complete blockchain-based logging

๐Ÿ”’ Privacy Protection

Data Minimization

  • Use Case Based: Only required fields per use case
  • Field Masking: Sensitive data masking (PAN, Aadhar, Phone)
  • Address Generalization: City-level location only
  • File Filtering: Only essential documents shared

Differential Privacy

  • Laplace Noise: Mathematical noise addition
  • K-Anonymity: Group-based anonymization
  • Epsilon Parameter: Privacy vs utility trade-off
  • Sensitivity Analysis: Impact assessment

Encryption & Tokenization

  • AES-256-GCM: Military-grade encryption
  • Token Generation: Secure token replacement
  • Key Management: Secure key storage
  • Data Residency: Local data storage compliance

๐Ÿ“ˆ Machine Learning Models

Anomaly Detection Algorithms

  1. Statistical Analysis: Z-score, IQR methods
  2. Isolation Forest: Unsupervised anomaly detection
  3. One-Class SVM: Novelty detection
  4. Autoencoder: Deep learning anomaly detection

Feature Engineering

  • Temporal Features: Time-based patterns
  • Spatial Features: Location-based analysis
  • Behavioral Features: User interaction patterns
  • Contextual Features: Environmental factors

Model Training

  • Historical Data: User behavior history
  • Baseline Establishment: Normal behavior patterns
  • Continuous Learning: Adaptive model updates
  • Performance Monitoring: Accuracy and F1-score tracking

๐Ÿšจ API Response Examples

Normal Request (No Anomaly)

{
  "use_case": "Credit Card Issuance",
  "minimum_required_fields": ["PAN Card", "Aadhar", "Phone Number"],
  "form_data": {
    "text_fields": {"Phone Number": "987****210"},
    "file_uploads": {"PAN_Card": {...}}
  },
  "security_metadata": {
    "anomaly_detection_performed": true,
    "anomaly_score": 0.15,
    "risk_level": "LOW",
    "smart_contract_validated": true,
    "privacy_preserving_minimization_applied": true
  }
}

Anomaly Detected

{
  "error": "ANOMALY_DETECTED",
  "message": "Access blocked due to detected anomaly",
  "anomalyScore": 0.85,
  "riskLevel": "HIGH",
  "riskFactors": ["UNUSUAL_LOCATION", "UNKNOWN_DEVICE"],
  "recommendedAction": "BLOCK"
}

๐Ÿ”ง Development

Adding New Behavioral Traits

  1. Extend UserBehavior.java model
  2. Update AnomalyDetectionService.java with new calculation methods
  3. Modify AnomalyDetectionFilter.java to extract new data
  4. Update thresholds and risk assessment logic

Customizing Privacy Rules

  1. Modify PrivacyPreservingDataService.java
  2. Update field minimization logic
  3. Adjust differential privacy parameters
  4. Configure compliance frameworks

Smart Contract Integration

  1. Update SmartContractService.java with your blockchain
  2. Configure contract addresses and ABIs
  3. Implement transaction validation logic
  4. Add multi-signature requirements

๐Ÿ“‹ Compliance

GDPR Compliance

  • Data Minimization: Only necessary data collected
  • Consent Management: Explicit user consent
  • Right to Erasure: Data deletion capabilities
  • Data Portability: Export user data
  • Privacy by Design: Built-in privacy protection

DPDP (India) Compliance

  • Data Principal Rights: User control over data
  • Consent Framework: Granular consent management
  • Data Localization: Local data storage
  • Breach Notification: Incident reporting
  • Cross-border Transfer: Restricted data sharing

๐Ÿงช Testing

Unit Tests

cd backend/authentication
mvn test

Integration Tests

# Test anomaly detection
curl -X POST http://localhost:8089/api/anomaly/detect \
  -H "Content-Type: application/json" \
  -d @test_data.json

# Test privacy protection
curl -X POST http://localhost:5000/api/requests/123/submitForm \
  -F 'payload=@test_payload.json'

Performance Testing

  • Load Testing: Apache JMeter scripts included
  • Stress Testing: High-volume anomaly detection
  • Latency Testing: Response time optimization
  • Accuracy Testing: False positive/negative analysis

๐Ÿš€ Deployment

Docker Deployment

# Build and run with Docker Compose
docker-compose up -d

Kubernetes Deployment

# Deploy to Kubernetes cluster
kubectl apply -f k8s/

Production Configuration

  • SSL/TLS: HTTPS encryption
  • Rate Limiting: API protection
  • Monitoring: Prometheus + Grafana
  • Logging: ELK stack integration
  • Backup: Automated data backup

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Implement your changes
  4. Add tests
  5. Submit a pull request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ†˜ Support

For support and questions:

  • Create an issue in the repository
  • Contact the development team
  • Check the documentation

๐Ÿ”ฎ Future Enhancements

  • Biometric Integration: Fingerprint, face recognition
  • Advanced ML Models: Deep learning for better accuracy
  • Real-time Streaming: Apache Kafka integration
  • Microservices: Service mesh architecture
  • Edge Computing: Local anomaly detection
  • Quantum Security: Post-quantum cryptography

Built with โค๏ธ for secure and privacy-preserving fintech applications

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors