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.
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
POST /api/auth/register- User registration with role selectionPOST /api/auth/login- User login with JWT token returnPOST /api/auth/logout- User logout (client-side token removal)
GET /api/transactions- List user transactions with pagination and filteringGET /api/transactions/[id]- Get detailed transaction informationPUT /api/transactions/[id]- Update transaction status (merchants only)POST /api/transactions/create- Create new transaction with fraud analysisGET /api/transactions/stats- Get transaction statistics and recent transactionsGET /api/transactions/success- Handle Stripe payment success callback and create transaction record
GET /api/merchants- List available merchants with filtering and paginationGET /api/merchants/[id]- Get merchant details with user personalization
GET /api/profile- Get current user profile informationPUT /api/profile- Update user profile information
- Registration: Users can register as customers or merchants
- Dashboard: Personalized overview with transaction statistics
- Merchant Discovery: Browse and discover trusted merchants
- Secure Payments: Create transactions with real-time fraud detection
- Transaction Tracking: Monitor payment status and history
- Profile Management: Update personal information and security settings
- Node.js 18+ and npm
- MongoDB (local or cloud instance)
- Git
- Google Gemini API Key (for fraud detection)
# 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 devVisit http://localhost:3000 to see the application running!
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-hereThe application automatically creates collections and indexes on first run. No manual database setup required.
-
Clone the repository
git clone <repository-url> cd detect_fraud_transaction
-
Install dependencies
npm install
-
Set up environment variables
The
.env.localfile 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 -
Start MongoDB
# Make sure MongoDB is running on your system mongod -
Run the development server
npm run dev
All API endpoints require authentication except for registration and login. Include the JWT token in the Authorization header:
Authorization: Bearer <your-jwt-token>
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 */
},
},
}),
});- 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
The system uses multiple layers of fraud detection:
- Rule-Based Analysis: Amount thresholds, transaction frequency, location checks
- AI Analysis: Google Generative AI (Gemini) analysis of transaction descriptions and patterns
- Behavioral Analysis: User transaction patterns and history
- Merchant Risk Scoring: Dynamic risk assessment based on merchant performance
-
Build the application
npm run build
-
Start production server
npm start
-
Use PM2 for process management
npm install -g pm2 pm2 start npm --name "fraud-detection-api" -- start
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License.
For support and questions, please open an issue in the repository.