Skip to content

basedanurag/ICP--Blockchain-Fraud-Detector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

21 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ICP Blockchain Fraud Detection System - Full Stack Implementation

A comprehensive blockchain fraud detection system that combines AI/ML fraud detection capabilities with a robust full-stack application. This project provides real-time analysis of blockchain transactions to identify potentially fraudulent activities on the ICP blockchain.

πŸ—οΈ Project Architecture

The system consists of three main components:

  • AI/ML Service: Python-based fraud detection module using RandomForestClassifier
  • Backend API: Rust-based backend service providing RESTful APIs
  • Frontend Dashboard: React-based web application for user interaction
  • Database: MongoDB for data persistence

πŸ“‹ Prerequisites

Before setting up the project, ensure you have the following installed:

Required Software

  • Docker (for MongoDB)
  • Python 3.8+ (for AI/ML service)
  • Rust 1.70+ (for backend service)
  • Node.js 16+ and npm (for frontend)
  • Git (for version control)

Development Tools (Recommended)

  • MongoDB Compass (for database management)
  • Postman or Thunder Client (for API testing)
  • VS Code or your preferred IDE

πŸš€ Installation & Setup

1. Clone and Navigate to Project

git clone https://github.com/basedanurag/ICP--Blockchain-Fraud-Detector.git
cd "ICP--Blockchain-Fraud-Detector"

2. Start MongoDB Database

# Start MongoDB using Docker
docker run -d -p 27017:27017 --name mongodb mongo:latest

# Verify MongoDB is running
docker ps

3. Setup AI/ML Fraud Detection Service

# Navigate to fraud detection module
cd fraud_detection_module

# Create virtual environment (recommended)
python -m venv venv

# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate

# Install Python dependencies
pip install -r requirements.txt

# Train the fraud detection model (if not already present)
python train_model.py

# Test the fraud detection module
python test_fraud_detection.py

# Return to project root
cd ..

4. Setup Rust Backend Service

# Navigate to backend directory
cd backend

# Build the Rust project
cargo build

# Run the backend service
cargo run
# Backend will be available at http://localhost:8080

# In a new terminal, return to project root
cd ..

5. Setup React Frontend

# Navigate to frontend directory
cd frontend

# Install Node.js dependencies
npm install

# Start the development server
npm start
# Frontend will be available at http://localhost:3000

πŸ”— Service URLs

Once all services are running, you can access:

πŸ§ͺ Testing the System

Backend API Testing

# Test backend health endpoint
curl http://localhost:8080/health

# Test fraud analysis endpoint
curl -X POST http://localhost:8080/api/analyze \
  -H "Content-Type: application/json" \
  -d '{"wallet_address": "0x1234567890abcdef1234567890abcdef12345678"}'

Frontend Testing

  1. Open http://localhost:3000 in your browser
  2. Navigate through the dashboard
  3. Test fraud detection functionality
  4. Verify data visualization components

πŸ“ Project Structure

ICP--Blockchain-Fraud-Detector/
β”œβ”€β”€ backend/                    # Rust backend service
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ main.rs            # Application entry point
β”‚   β”‚   β”œβ”€β”€ routes.rs          # API route definitions
β”‚   β”‚   β”œβ”€β”€ models.rs          # Data models
β”‚   β”‚   β”œβ”€β”€ db.rs              # Database operations
β”‚   β”‚   └── icp/               # ICP blockchain integration
β”‚   β”œβ”€β”€ Cargo.toml             # Rust dependencies
β”‚   └── .env                   # Environment variables
β”œβ”€β”€ frontend/                   # React frontend application
β”‚   β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ public/
β”‚   β”œβ”€β”€ package.json           # Node.js dependencies
β”‚   └── tailwind.config.js     # Tailwind CSS configuration
β”œβ”€β”€ fraud_detection_module/     # Python AI/ML service
β”‚   β”œβ”€β”€ fraud_detection.py     # Main fraud detection logic
β”‚   β”œβ”€β”€ train_model.py         # Model training script
β”‚   β”œβ”€β”€ test_fraud_detection.py # Testing script
β”‚   β”œβ”€β”€ fraud_model.pkl        # Trained ML model
β”‚   └── requirements.txt       # Python dependencies
β”œβ”€β”€ README.md                   # This file
└── BACKEND_DEVELOPER_GUIDE.md  # Backend development guide

πŸ”§ Development Commands

Backend Development

cd backend
cargo check          # Check for compilation errors
cargo test           # Run tests
cargo run --release  # Run optimized build

Frontend Development

cd frontend
npm run build        # Build for production
npm test             # Run tests
npm run eject        # Eject from Create React App (irreversible)

AI/ML Model Development

cd fraud_detection_module
python train_model.py              # Retrain the model
python test_fraud_detection.py     # Test model performance

πŸ› οΈ Configuration

Environment Variables

Create a .env file in the backend directory:

DATABASE_URL=mongodb://localhost:27017/fraud_detection
RUST_LOG=info
SERVER_HOST=127.0.0.1
SERVER_PORT=8080

MongoDB Configuration

The system uses MongoDB for data persistence. Ensure MongoDB is running on the default port (27017) or update the connection string in your configuration.

πŸ“Š Features

  • Real-time Fraud Detection: AI-powered analysis of blockchain transactions
  • Interactive Dashboard: React-based web interface for monitoring and analysis
  • REST API: Comprehensive API for integration with external systems
  • Scalable Architecture: Microservices-based design for easy scaling
  • Data Visualization: Charts and graphs for fraud pattern analysis
  • Historical Analysis: View historical fraud detection results

🚨 Troubleshooting

Common Issues

  1. MongoDB Connection Error

    • Ensure Docker is running: docker ps
    • Restart MongoDB container: docker restart mongodb
  2. Rust Compilation Errors

    • Update Rust: rustup update
    • Clean build: cargo clean && cargo build
  3. Frontend Build Issues

    • Clear npm cache: npm cache clean --force
    • Delete node_modules: rm -rf node_modules && npm install
  4. Python Module Import Errors

    • Ensure virtual environment is activated
    • Reinstall dependencies: pip install -r requirements.txt

Logs Location

  • Backend logs: Console output when running cargo run
  • Frontend logs: Browser console (F12)
  • AI/ML logs: fraud_detection_module/fraud_detection.log

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m 'Add some amazing feature'
  4. Push to the branch: git push origin feature/amazing-feature
  5. Open a Pull Request

πŸ† Acknowledgments

  • Built for DoraHacks hackathon
  • Uses ICP blockchain infrastructure
  • Implements machine learning for fraud detection
  • Modern full-stack architecture with Rust and React

Note: This is a development setup guide. For production deployment, additional considerations for security, monitoring, and scalability should be implemented.

About

this repo contains the full project of icp blockchain transaction detection

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published