A production-ready transaction fraud detection system with real-time risk assessment capabilities. Built with Go backend and React frontend.
- Detects suspicious financial transactions in real time
- Allows users to make transactions
- Evaluates transactions for risk
- Flags or blocks suspicious transactions
- Transaction ingestion through APIs
- Stores transaction data in a database
- Streams transactions for evaluation
Risk scoring based on rules such as:
- Large transaction amounts
- Multiple transactions in a short time
- Transactions from new devices
Returns a risk score for each transaction
- Inspired by real-world systems like Visa, Stripe, and Razorpay
- Uses event-driven and asynchronous processing
- Maintains audit trails for transactions and fraud flags
- Go 1.24+ - Backend runtime
- Node.js 18+ - Frontend runtime
- PostgreSQL 12+ - Database
- Redis 6+ - Session cache
- Make - Build automation
- Git - Version control
git clone <repository-url>
cd Transaction-Risk-AnalysisCopy the example environment file and configure your credentials:
cp .env.example .envEdit the .env file with your database, Redis, email, and admin credentials. Note: The admin credentials you set here will be used for initial login.
Execute the automated setup script from the root directory:
./setup.shImportant: When prompted to overwrite the .env file, select No if you've already configured it in step 2.
The setup script will:
- Install backend dependencies
- Install frontend dependencies
- Create the PostgreSQL database
- Run database migrations
- Verify Redis connection
Open two separate terminals:
Terminal 1 - Backend:
cd Backend
make runBackend will start on http://localhost:8080
Terminal 2 - Frontend:
cd Frontend
npm run devFrontend will start on http://localhost:3000
-
Login as Admin
- Use the admin credentials you configured in the
.envfile - Navigate to
http://localhost:3000/login - Enter admin email and password
- Verify OTP sent to your email
- Use the admin credentials you configured in the
-
Create Users
- Navigate to the Users tab
- Create two users with the following details:
- Name, email, phone, password
- Device info (e.g., "phone")
- Location (latitude/longitude)
- Initial deposit: 5-10 lakhs or more (₹500,000 - ₹1,000,000)
- Important: Use working email addresses - OTPs and transaction alerts will be sent there
- Both users will receive account creation approval
-
Login as User
- Open a new browser or incognito window
- Login with one of the newly created users
- Complete OTP verification
-
Make a Transaction
- Copy the second user's account number (the one you're NOT logged in as)
- Navigate to Create Transaction
- Enter the recipient account number
-
Trigger Risk Rules
To flag or block a transaction, trigger one or more risk rules:
a) Dynamic Amount Rule (35 points)
- First transaction: Amount > ₹1 lakh (₹100,000)
- Subsequent transactions: Amount > 2x your average transaction amount
- (Make 3-4 small transactions first, then a large one to trigger)
b) New Device Rule (20 points)
- User was created with device info:
"phone" - Make transaction with different device:
"laptop"or"tablet"
c) Geo-Location Anomaly Rule (20 points)
- Use different latitude/longitude than user's registration location
- Example: Register at
(19.0760, 72.8777), transact from(28.6139, 77.2090)
d) Velocity Rule (25 points)
- Make 5+ transactions within 5 minutes
Risk Score Thresholds:
- Score 30-69: Transaction is FLAGGED (requires user approval)
- Score ≥70: Transaction is BLOCKED (rejected immediately)
Tip: Trigger 1-2 rules for flagged transaction, 3+ rules for blocked transaction
-
Approve Flagged Transactions
- When a transaction is flagged, an email is sent to the user
- Click the verification link in the email
- Important: Open the link in the same browser where the user is logged in
- The link contains localhost address (app not deployed yet)
- Opening in a different browser/device won't work
- Review transaction details
- Approve or reject the transaction
-
View Transaction Audits
- Navigate to Transactions tab
- Click on any transaction to view details
- Check Audit Trail for complete event history
- View Rule Breakdown to see which rules were triggered
# Development
make run # Run the application
make build # Build the binary
make test # Run all tests
make test-coverage # Run tests with coverage report
make fmt # Format code
make lint # Run linter
make clean # Clean build artifacts
# Database
make migrate # Run database migrations
make clean-db # Clean database (removes all data)npm run dev # Start development server
npm run build # Build for production
npm run preview # Preview production build
npm run lint # Run ESLint# Check if port is in use
lsof -i :8080 # Backend
lsof -i :3000 # Frontend
# Kill process on port
lsof -ti:8080 | xargs kill -9
lsof -ti:3000 | xargs kill -9# Access PostgreSQL CLI
psql -U postgres -d fraud_detection_db
# Check database connection
pg_isready -U postgres
# Count records
psql -U postgres -d fraud_detection_db -c "SELECT COUNT(*) FROM transactions;"# Check Redis connection
redis-cli ping # Should return: PONG
# View cached sessions
redis-cli KEYS "session:*"
# Clear all cache
redis-cli FLUSHALL# Backend logs
cd Backend
tail -f server.log
# Search for errors
grep ERROR server.log.
├── Backend/ # Go backend service
│ ├── cmd/ # Application entry points
│ ├── config/ # Configuration management
│ ├── internal/ # Private application code
│ ├── pkg/ # Public libraries
│ ├── migrations/ # Database migrations
│ └── tests/ # Test suites
├── Frontend/ # React frontend application
│ ├── src/ # Source code
│ ├── public/ # Static assets
│ └── package.json # Dependencies
├── .env # Environment variables
├── setup.sh # Automated setup script
└── README.md # This file
API documentation is available via Postman collection:
Backend/postman_collection.jsonImport this file into Postman to test all API endpoints.
- Check if PostgreSQL is running:
pg_isready - Check if Redis is running:
redis-cli ping - Verify
.envfile configuration - Check if port 8080 is available
- Check if port 3000 is available
- Verify
node_modulesare installed:npm install - Check backend is running on port 8080
- Verify
EMAIL_USERandEMAIL_PASSin.env - For Gmail: Use App Password (not regular password)
- Enable 2FA and generate App Password in Gmail settings
- Ensure you're triggering enough risk rules
- Check transaction amount relative to user's average
- Verify device info and location are different from registration
- View rule breakdown in transaction details
Proprietary - Internal Project