Skip to content

jenkins-369/FraudGuard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FraudGuard - AI-Powered Fraud Detection Platform

A complete full-stack solution for secure digital transactions in Bangladesh, featuring AI-powered fraud detection, beautiful user interface, and comprehensive security measures. Built with Next.js, MongoDB, and Google Generative AI.

Features

πŸ€– AI-Powered Security

  • Advanced Fraud Detection: Real-time AI analysis using Google Generative AI (Gemini)
  • Multi-Layer Risk Assessment: Amount, behavior, location, and merchant-based scoring
  • Intelligent Transaction Monitoring: Automatic fraud pattern recognition
  • Risk Factor Analysis: Detailed explanations for fraud scores

πŸ” Enterprise-Grade Security

  • JWT Authentication: Stateless, secure token-based authentication
  • Rate Limiting: 100 requests per 15 minutes per IP address
  • Input Validation: Comprehensive Zod schema validation
  • Security Headers: XSS, CSRF, and injection protection
  • Password Security: bcrypt hashing with 12 salt rounds
  • Payment Security: Stripe integration for secure payment processing

πŸ’³ Complete Transaction System

  • Multi-Payment Support: Cards, bank transfers, digital wallets, cash via Stripe
  • Real-Time Processing: Instant fraud analysis and status updates
  • Transaction Lifecycle: Pending β†’ Processing β†’ Completed/Failed
  • Reference Tracking: Unique transaction IDs for all payments
  • Status Transparency: Real-time transaction status visibility

πŸͺ Smart Merchant Network

  • Merchant Discovery: Browse verified merchants by category
  • Personalized Recommendations: AI-driven merchant suggestions
  • Risk Scoring: Dynamic merchant reliability assessment
  • Performance Analytics: Success rates and transaction metrics
  • Merchant Profiles: Detailed business information and contact details

🎨 Beautiful User Interface

  • Modern Design: Clean, professional interface with Tailwind CSS
  • Responsive Layout: Optimized for desktop, tablet, and mobile
  • Intuitive Navigation: Easy-to-use dashboard and transaction management
  • Real-Time Updates: Live transaction status and notifications
  • Accessibility: WCAG compliant with keyboard navigation support
  • Modular Architecture: Context-based state management without prop drilling

πŸ“Š Advanced Analytics

  • Dashboard Insights: Transaction summaries and spending analytics
  • Fraud Monitoring: Risk score tracking and fraud pattern analysis
  • Merchant Analytics: Performance metrics and user engagement
  • Transaction History: Advanced filtering and search capabilities
  • Export Capabilities: Data export for accounting and compliance

πŸ—οΈ Architecture Highlights

  • Modular Backend: Separated concerns with dedicated API modules
  • Context-Based Frontend: React Context for clean state management
  • Type-Safe: Full TypeScript coverage with strict typing
  • Scalable Structure: Easy to extend and maintain
  • Reusable Components: UI primitives that can be used across the app

πŸ› οΈ Tech Stack

Backend

  • Framework: Next.js 16 with App Router and API Routes
  • Database: MongoDB with Mongoose ODM
  • Authentication: JWT (JSON Web Tokens) with bcrypt password hashing
  • AI/ML: Google Generative AI (Gemini) for fraud detection
  • Payment Processing: Stripe for secure payment handling
  • Validation: Zod schemas for type-safe input validation
  • Security: Rate limiting, input sanitization, security headers
  • Language: TypeScript for type safety

Frontend

  • UI Framework: Next.js 16 with React 19
  • Styling: Tailwind CSS for responsive, modern design
  • State Management: React Context for authentication and dashboard state
  • Routing: Next.js App Router with protected routes
  • Forms: Client-side validation with real-time feedback
  • Components: Modular, reusable UI components with context-based state
  • Architecture: Component composition with custom hooks and context providers

DevOps & Tools

  • Package Manager: npm
  • Development: Hot reload, TypeScript checking
  • Build: Optimized production builds with Next.js
  • Environment: Configurable environment variables
  • Error Handling: React Error Boundaries and API error handling
  • Payment Integration: Stripe for secure payment processing

πŸ“‘ API Endpoints

πŸ” Authentication

  • POST /api/auth/register - User registration with role selection
  • POST /api/auth/login - User login with JWT token return
  • POST /api/auth/logout - User logout (client-side token removal)

πŸ’³ Transactions

  • GET /api/transactions - List user transactions with pagination and filtering
  • GET /api/transactions/[id] - Get detailed transaction information
  • PUT /api/transactions/[id] - Update transaction status (merchants only)
  • POST /api/transactions/create - Create new transaction with fraud analysis
  • GET /api/transactions/stats - Get transaction statistics and recent transactions
  • GET /api/transactions/success - Handle Stripe payment success callback and create transaction record

πŸͺ Merchants

  • GET /api/merchants - List available merchants with filtering and pagination
  • GET /api/merchants/[id] - Get merchant details with user personalization

πŸ‘€ User Profile

  • GET /api/profile - Get current user profile information
  • PUT /api/profile - Update user profile information

🎯 User Journey

  1. Registration: Users can register as customers or merchants
  2. Dashboard: Personalized overview with transaction statistics
  3. Merchant Discovery: Browse and discover trusted merchants
  4. Secure Payments: Create transactions with real-time fraud detection
  5. Transaction Tracking: Monitor payment status and history
  6. Profile Management: Update personal information and security settings

πŸš€ Getting Started

Prerequisites

  • Node.js 18+ and npm
  • MongoDB (local or cloud instance)
  • Git
  • Google Gemini API Key (for fraud detection)

Quick Start

# Clone the repository
git clone <repository-url>
cd detect_fraud_transaction

# Install dependencies
npm install

# Set up environment variables
# The .env.local file has been created with placeholder values
# Edit .env.local with your actual MongoDB URI, JWT secret, and Gemini API key

# Start MongoDB (if running locally)
mongod

# Run the development server
npm run dev

Visit http://localhost:3000 to see the application running!

πŸ”§ Configuration

Environment Variables

The .env.local file has been created with the following variables:

# Database Configuration
MONGODB_URI=mongodb://localhost:27017/fraud_detection_db

# JWT Secret for Authentication
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production-make-it-very-long-and-random

# API Configuration
NEXT_PUBLIC_API_URL=http://localhost:3000

# Gemini AI API Key for Fraud Detection
# Get your API key from: https://makersuite.google.com/app/apikey
GEMINI_API_KEY=your-gemini-api-key-here

# Stripe Configuration
# Get your keys from: https://dashboard.stripe.com/apikeys
STRIPE_SECRET_KEY=your-stripe-secret-key-here
STRIPE_PUBLISHABLE_KEY=your-stripe-publishable-key-here

Database Setup

The application automatically creates collections and indexes on first run. No manual database setup required.

Installation

  1. Clone the repository

    git clone <repository-url>
    cd detect_fraud_transaction
  2. Install dependencies

    npm install
  3. Set up environment variables

    The .env.local file has been created with placeholder values. Update it with your actual credentials:

    # Edit .env.local with your MongoDB URI, JWT secret, and Gemini API key
    nano .env.local
  4. Start MongoDB

    # Make sure MongoDB is running on your system
    mongod
  5. Run the development server

    npm run dev

Usage

Making API Requests

All API endpoints require authentication except for registration and login. Include the JWT token in the Authorization header:

Authorization: Bearer <your-jwt-token>

Example Transaction Creation

const response = await fetch("/api/transactions/create", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    Authorization: "Bearer your-jwt-token",
  },
  body: JSON.stringify({
    merchantId: "merchant-id",
    amount: 1000,
    description: "Payment for services",
    paymentMethod: {
      type: "card",
      details: {
        /* card details */
      },
    },
  }),
});

Security Features

  • Rate Limiting: 100 requests per 15 minutes per IP
  • Input Validation: All inputs validated with Zod schemas
  • Fraud Detection: AI-powered analysis of transaction patterns
  • Secure Headers: Protection against common web vulnerabilities
  • Password Hashing: bcrypt with 12 salt rounds
  • Token Expiration: JWT tokens expire in 7 days
  • Payment Security: Stripe handles all payment processing securely

Fraud Detection

The system uses multiple layers of fraud detection:

  1. Rule-Based Analysis: Amount thresholds, transaction frequency, location checks
  2. AI Analysis: Google Generative AI (Gemini) analysis of transaction descriptions and patterns
  3. Behavioral Analysis: User transaction patterns and history
  4. Merchant Risk Scoring: Dynamic risk assessment based on merchant performance

Production Deployment

  1. Build the application

    npm run build
  2. Start production server

    npm start
  3. Use PM2 for process management

    npm install -g pm2
    pm2 start npm --name "fraud-detection-api" -- start

Contributing

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

License

This project is licensed under the MIT License.

Support

For support and questions, please open an issue in the repository.

About

AI powerd fraud transaction detection system.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages