Skip to content

Latest commit

Β 

History

History
484 lines (364 loc) Β· 12.2 KB

File metadata and controls

484 lines (364 loc) Β· 12.2 KB

πŸš€ Hawkins Fraud Detection System - Local Setup Guide

Complete guide to download, setup, and run the Hawkins Fraud Detection System on your local machine.


πŸ“¦ Project Overview

Hawkins Fraud Detection System is a Next.js TypeScript application with Supabase backend integration featuring:

  • Real-time fraud detection and analytics
  • WhatsApp-based transaction approval system
  • Customer and corporate dashboards
  • AI-powered fraud reasoning
  • Secure authentication and authorization

🎯 Prerequisites

Before starting, ensure you have the following installed:

Required Software

  • Node.js: v18.x or higher (Download)
  • npm: v9.x or higher (comes with Node.js)
  • Git: Latest version (Download)
  • Code Editor: VS Code recommended (Download)

Verify Installation

node --version  # Should show v18.x or higher
npm --version   # Should show v9.x or higher
git --version   # Should show git version

πŸ“₯ Step 1: Download Project

Option A: Download ZIP (Easiest)

  1. Navigate to your project repository
  2. Click Code β†’ Download ZIP
  3. Extract the ZIP file to your desired location
  4. Open terminal/command prompt in the extracted folder

Option B: Clone via Git

git clone <your-repository-url>
cd hawkins-fraud-detection

πŸ”§ Step 2: Install Dependencies

Navigate to the project root directory and install all required packages:

# Install all npm dependencies
npm install

# This will install:
# - Next.js 14.2.0
# - React 18.2.0
# - TypeScript
# - Tailwind CSS
# - Supabase client
# - All other dependencies from package.json

Expected output:

added 342 packages, and audited 343 packages in 45s

πŸ” Step 3: Configure Environment Variables

3.1 Create Environment File

Copy the example environment file:

# Create .env.local file in project root
cp .env .env.local

3.2 Configure Supabase Connection

Get your Supabase credentials:

  1. Go to Supabase Dashboard
  2. Select your project (or create new one)
  3. Navigate to Settings β†’ API
  4. Copy the following values:

Update .env.local file:

# Supabase Configuration
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key-here

# Optional: Twilio WhatsApp Integration
TWILIO_ACCOUNT_SID=your-twilio-account-sid
TWILIO_AUTH_TOKEN=your-twilio-auth-token
TWILIO_WHATSAPP_NUMBER=whatsapp:+14155238886

3.3 Environment Variable Reference

Variable Required Description
NEXT_PUBLIC_SUPABASE_URL βœ… Yes Your Supabase project URL
NEXT_PUBLIC_SUPABASE_ANON_KEY βœ… Yes Supabase anonymous/public key
TWILIO_ACCOUNT_SID ❌ No Twilio Account SID (for WhatsApp)
TWILIO_AUTH_TOKEN ❌ No Twilio Auth Token (for WhatsApp)
TWILIO_WHATSAPP_NUMBER ❌ No Twilio WhatsApp number

Note: WhatsApp integration is optional. The app will work without it, but WhatsApp approval features will be disabled.


πŸ—„οΈ Step 4: Setup Supabase Database

4.1 Run Database Migrations

The project includes SQL migration files to set up your database schema:

Option A: Via Supabase Dashboard (Recommended)

  1. Go to Supabase Dashboard β†’ SQL Editor
  2. Open supabase/migrations/20251204173053_create_whatsapp_approvals.sql
  3. Copy the entire SQL content
  4. Paste into SQL Editor and click Run

Option B: Via Supabase CLI

# Install Supabase CLI (if not installed)
npm install -g supabase

# Login to Supabase
supabase login

# Link your project
supabase link --project-ref your-project-ref

# Run migrations
supabase db push

4.2 Database Schema Overview

The migration creates the following tables:

  • whatsapp_approvals - WhatsApp approval tracking
  • transactions - Transaction records
  • users - User authentication
  • fraud_scores - ML fraud detection scores

πŸš€ Step 5: Run the Application

5.1 Start Development Server

npm run dev

Expected output:

> hawkins-fraud-detection@0.1.0 dev
> next dev

- ready started server on 0.0.0.0:3000, url: http://localhost:3000
- event compiled client and server successfully in 2.5s (502 modules)

5.2 Access the Application

Open your browser and navigate to:

http://localhost:3000

Available Routes:

  • /login - Login page
  • /customer-dashboard - Customer view
  • /corporate-dashboard - Corporate/admin view
  • /transaction-review - Transaction review interface
  • /fraud-analytics - Fraud analytics dashboard
  • /transaction-submission - Submit new transactions

πŸ”’ Step 6: Setup Authentication (Optional)

6.1 Enable Email Authentication in Supabase

  1. Go to Supabase Dashboard β†’ Authentication β†’ Providers
  2. Enable Email provider
  3. Configure email templates (optional)

6.2 Create Test User

-- Run in Supabase SQL Editor
INSERT INTO auth.users (email, encrypted_password, email_confirmed_at)
VALUES (
  'test@example.com',
  crypt('password123', gen_salt('bf')),
  NOW()
);

πŸ“± Step 7: Setup WhatsApp Integration (Optional)

7.1 Prerequisites

  • Twilio account (Sign up)
  • WhatsApp Business API access

7.2 Configure Twilio

Follow the detailed guide in TWILIO_SETUP_GUIDE.md

Quick Setup:

  1. Get Twilio credentials from console.twilio.com
  2. Add credentials to .env.local
  3. Deploy Supabase Edge Functions:
supabase functions deploy send-whatsapp-approval
supabase functions deploy check-whatsapp-approval
supabase functions deploy whatsapp-webhook

πŸ› οΈ Troubleshooting

Common Issues and Solutions

Issue 1: Port 3000 Already in Use

# Solution 1: Kill the process using port 3000
npx kill-port 3000

# Solution 2: Use a different port
npm run dev -- -p 3001

Issue 2: Supabase Connection Error

Error: Invalid Supabase URL or key

Solution:

  1. Verify .env.local has correct credentials
  2. Check Supabase project is active
  3. Ensure no extra spaces in environment variables
  4. Restart development server after changing .env.local

Issue 3: Module Not Found Errors

# Clear node_modules and reinstall
rm -rf node_modules package-lock.json
npm install

Issue 4: TypeScript Compilation Errors

# Rebuild TypeScript
npm run build

Issue 5: Tailwind CSS Not Working

# Verify tailwind.config.js exists
# Restart dev server
npm run dev

πŸ“‚ Project Structure

hawkins-fraud-detection/
β”œβ”€β”€ public/                          # Static assets
β”‚   β”œβ”€β”€ assets/images/              # Image files
β”‚   └── favicon.ico                 # Site favicon
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/                        # Next.js app directory
β”‚   β”‚   β”œβ”€β”€ api/                    # API routes
β”‚   β”‚   β”œβ”€β”€ login/                  # Login page
β”‚   β”‚   β”œβ”€β”€ customer-dashboard/     # Customer dashboard
β”‚   β”‚   β”œβ”€β”€ corporate-dashboard/    # Corporate dashboard
β”‚   β”‚   β”œβ”€β”€ fraud-analytics/        # Analytics page
β”‚   β”‚   β”œβ”€β”€ transaction-review/     # Review interface
β”‚   β”‚   └── transaction-submission/ # Transaction form
β”‚   β”œβ”€β”€ components/                 # Reusable components
β”‚   β”‚   β”œβ”€β”€ ui/                     # UI components
β”‚   β”‚   └── common/                 # Shared components
β”‚   β”œβ”€β”€ contexts/                   # React contexts
β”‚   β”œβ”€β”€ lib/                        # Library configurations
β”‚   β”œβ”€β”€ styles/                     # Global styles
β”‚   └── utils/                      # Utility functions
β”œβ”€β”€ supabase/
β”‚   β”œβ”€β”€ functions/                  # Edge functions
β”‚   └── migrations/                 # Database migrations
β”œβ”€β”€ .env.local                      # Environment variables (create this)
β”œβ”€β”€ next.config.mjs                 # Next.js configuration
β”œβ”€β”€ package.json                    # Dependencies
β”œβ”€β”€ tailwind.config.js              # Tailwind configuration
└── tsconfig.json                   # TypeScript configuration

🎨 Available Scripts

# Development
npm run dev          # Start development server on localhost:3000

# Production Build
npm run build        # Create optimized production build
npm run start        # Start production server

# Code Quality
npm run lint         # Run ESLint for code quality checks

# Type Checking
npx tsc --noEmit    # Check TypeScript types without emitting files

πŸ” Testing the Application

1. Test Login Flow

  1. Navigate to http://localhost:3000/login
  2. Enter test credentials
  3. Should redirect to dashboard

2. Test Customer Dashboard

  1. Navigate to http://localhost:3000/customer-dashboard
  2. Submit a quick transaction
  3. View transaction history

3. Test WhatsApp Approval (if configured)

  1. Submit transaction requiring approval
  2. Check WhatsApp for approval message
  3. Reply "Yes it's me" to approve

4. Test Analytics Dashboard

  1. Navigate to http://localhost:3000/fraud-analytics
  2. View fraud trend charts
  3. Check model performance metrics

πŸ“Š Performance Optimization

Development Mode

  • Hot Module Replacement (HMR) enabled
  • Fast Refresh for React components
  • Source maps for debugging

Production Mode

# Build for production
npm run build

# This will:
# - Optimize JavaScript bundles
# - Minify CSS and HTML
# - Generate static assets
# - Create optimized images

πŸ” Security Best Practices

Environment Variables

  • βœ… Never commit .env.local to Git
  • βœ… Use strong Supabase RLS policies
  • βœ… Rotate API keys regularly
  • βœ… Use HTTPS in production

Authentication

  • βœ… Enable email verification
  • βœ… Implement rate limiting
  • βœ… Use secure session management
  • βœ… Enable MFA for admin accounts

πŸ“ Additional Documentation

  • Twilio Setup: See TWILIO_SETUP_GUIDE.md
  • API Documentation: See API_REFERENCE.md (if available)
  • Deployment Guide: See DEPLOYMENT.md (if available)

πŸ†˜ Getting Help

Resources

Common Support Channels

  • GitHub Issues (if project is on GitHub)
  • Stack Overflow (tag: nextjs, supabase, typescript)
  • Supabase Discord Community

βœ… Verification Checklist

Before considering setup complete, verify:

  • Node.js and npm installed correctly
  • Project dependencies installed successfully
  • .env.local file created with valid credentials
  • Supabase database migrations applied
  • Development server starts without errors
  • Application loads at http://localhost:3000
  • Login functionality works
  • Customer dashboard accessible
  • No console errors in browser
  • Tailwind CSS styling appears correctly
  • TypeScript compilation successful

πŸŽ‰ Success!

Your Hawkins Fraud Detection System is now running locally!

Next Steps:

  1. Explore different dashboards and features
  2. Configure WhatsApp integration (optional)
  3. Customize styling and branding
  4. Add custom fraud detection rules
  5. Deploy to production (Vercel recommended)

πŸ“¦ Creating Production Build

When ready to deploy:

# Create optimized production build
npm run build

# Test production build locally
npm run start

# Deploy to Vercel (recommended)
npm install -g vercel
vercel

πŸ”„ Keeping Updated

To update dependencies:

# Check for outdated packages
npm outdated

# Update all packages to latest compatible versions
npm update

# Update to latest major versions (careful!)
npx npm-check-updates -u
npm install

Last Updated: December 4, 2025 Version: 1.0.0 Minimum Node Version: 18.x