Skip to content

SamXop123/TrustLens

Repository files navigation

πŸ›‘οΈ TrustLens – AI Fraud Protection

Early-call, consent-based fraud detection powered by Azure AI Speech and Google Gemini

TrustLens is an intelligent fraud detection system that helps users verify suspicious calls, messages, and links before harm occurs. By analyzing the first 20 seconds of a call or examining text content, TrustLens provides an early risk signal to help users make informed decisions.


🌟 Features

πŸŽ™οΈ Voice Call Scan (Primary Feature)

  • Real-time Audio Analysis: Record the first 20 seconds of suspicious calls
  • Consent-Based: User must explicitly enable fraud scanning
  • Speech-to-Text: Powered by Azure Cognitive Services
  • AI Risk Assessment: Google Gemini analyzes conversation patterns
  • Privacy-First: Audio is processed in memory only, never saved

πŸ’¬ Message Scan

  • Analyze suspicious SMS, emails, or chat messages
  • Detect common scam patterns and phishing attempts
  • Get instant risk assessment with detailed indicators

πŸ”— Link Check

  • Verify suspicious URLs without visiting them
  • URL-based analysis (safe - no crawling or fetching)
  • Identify potentially malicious domains and patterns

πŸ—οΈ Architecture

Tech Stack

Frontend:

  • React 19.2
  • React Router 7.11 (SPA routing)
  • Vite 7.2 (Build tool)
  • Web Audio API (Audio recording)

Backend:

  • Node.js + Express
  • Azure Cognitive Services Speech SDK
  • Google Gemini AI API
  • Multer (Multipart form data)

Processing Pipeline

Audio β†’ Azure Speech β†’ Transcript β†’ Gemini β†’ Fraud Result
  ↓
[Memory Only]
  ↓
[Discarded After Processing]

Project Structure

TrustLens/
β”œβ”€β”€ src/                      # Frontend source
β”‚   β”œβ”€β”€ components/           # React components
β”‚   β”‚   β”œβ”€β”€ Dashboard.jsx     # Main landing page
β”‚   β”‚   β”œβ”€β”€ VoiceFraudPage.jsx # Voice call detection flow
β”‚   β”‚   β”œβ”€β”€ TextFraudPage.jsx  # Message analysis
β”‚   β”‚   β”œβ”€β”€ LinkFraudPage.jsx  # URL verification
β”‚   β”‚   β”œβ”€β”€ IncomingCallScreen.jsx
β”‚   β”‚   β”œβ”€β”€ ConsentModal.jsx   # User consent UI
β”‚   β”‚   β”œβ”€β”€ ScanningScreen.jsx # Recording progress
β”‚   β”‚   └── ResultScreen.jsx   # Risk assessment display
β”‚   β”œβ”€β”€ hooks/
β”‚   β”‚   └── useAudioCapture.js # Audio recording logic
β”‚   β”œβ”€β”€ App.jsx               # Main app component
β”‚   └── main.jsx              # Entry point
β”‚
β”œβ”€β”€ backend/                  # Backend API
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”œβ”€β”€ speechService.js  # Azure Speech integration
β”‚   β”‚   β”œβ”€β”€ geminiService.js  # Google Gemini integration
β”‚   β”‚   └── aiService.js      # AI provider abstraction
β”‚   β”œβ”€β”€ prompts/
β”‚   β”‚   └── fraudPrompts.js   # Gemini prompt engineering
β”‚   └── server.js             # Express server
β”‚
└── public/                   # Static assets

πŸš€ Getting Started

Prerequisites

  • Node.js 16 or higher
  • Azure Cognitive Services Speech subscription
  • Google Gemini API key
  • Modern web browser with microphone access

1. Clone the Repository

git clone <repository-url>
cd TrustLens

2. Install Dependencies

Frontend:

npm install

Backend:

cd backend
npm install

3. Configure Environment Variables

Create a .env file in the backend/ folder:

# Azure Speech Service
AZURE_SPEECH_KEY=your_azure_speech_key_here
AZURE_SPEECH_REGION=your_azure_region_here

# Google Gemini AI
GEMINI_API_KEY=your_gemini_api_key_here

# AI Provider (optional, default: gemini)
AI_PROVIDER=gemini

Getting API Keys:

4. Run the Application

Terminal 1 - Backend:

cd backend
npm start
# Server runs on http://localhost:3001

Terminal 2 - Frontend:

npm run dev
# App runs on http://localhost:5173

5. Open in Browser

Navigate to http://localhost:5173 and grant microphone permissions when prompted.


πŸ“± Usage

Voice Call Scan

  1. Navigate to the Voice Call Scan section from the dashboard
  2. Click "Safe Scan" to enable fraud detection
  3. Accept consent to allow microphone access
  4. Speak naturally for up to 20 seconds
  5. View the Early Risk Signal and detailed analysis

Message Scan

  1. Select Message Scan from the dashboard
  2. Paste the suspicious message (up to 5,000 characters)
  3. Click "Analyze Message"
  4. Review risk indicators and recommendations

Link Check

  1. Choose Link Check from the dashboard
  2. Paste the suspicious URL
  3. Click "Check Link"
  4. See the risk assessment (no URL is visited)

πŸ”’ Privacy & Security

Privacy Guarantees

  • βœ… No Audio Storage: Audio is processed in memory only, never written to disk
  • βœ… No Transcript Storage: Text is analyzed and immediately discarded
  • βœ… No Database: Zero data persistence
  • βœ… User Consent: Explicit permission required for audio recording
  • βœ… Local Processing: Recording happens in the browser
  • βœ… Secure Transmission: Audio sent via HTTPS to backend

Responsible AI

  • Uses "Early Risk Signal" terminology instead of "confidence" or "accuracy"
  • Clearly states analysis is based on the first 20 seconds only
  • Does not claim definitive fraud detection
  • Provides probabilistic risk assessment, not absolute judgment

πŸ§ͺ Development

Available Scripts

Frontend:

npm run dev      # Start dev server with HMR
npm run build    # Build for production
npm run preview  # Preview production build
npm run lint     # Run ESLint

Backend:

npm start        # Start production server
npm run dev      # Start with auto-reload (Node --watch)

Debug Mode

To enable debug output in the frontend (shows transcript and confidence):

  1. Open src/components/ResultScreen.jsx
  2. Change const DEBUG_MODE = false to const DEBUG_MODE = true
  3. Debug info will appear on the result screen

πŸ”Œ API Endpoints

POST /analyze-audio

Analyze audio for fraud detection

Request:

  • Content-Type: multipart/form-data
  • audio: Audio file (WAV, WebM, MP3, OGG)

Response:

{
  "transcript": "Hello, this is regarding your account...",
  "duration": "5.2 seconds",
  "confidence": "0.92",
  "fraudAssessment": {
    "riskLevel": "high",
    "riskScore": 87,
    "summary": "Multiple fraud indicators detected",
    "indicators": [
      {
        "type": "urgency",
        "severity": "high",
        "description": "Creates false sense of urgency"
      }
    ],
    "recommendation": "Exercise extreme caution",
    "confidence": 85
  }
}

POST /analyze-text

Analyze text message for fraud

Request:

{
  "message": "Your account has been suspended. Click here to verify..."
}

POST /analyze-link

Analyze URL for potential threats

Request:

{
  "url": "https://suspicious-link.example.com"
}

GET /health

Health check endpoint

Response:

{
  "status": "ok",
  "message": "TrustLens backend is running"
}

🎨 UI/UX Features

  • Mobile-First Design: Optimized for 420px viewport
  • Dark Theme: Modern gradient background (#0f172a β†’ #1e293b)
  • Smooth Animations: All transitions use ease timing
  • Accessible: Proper ARIA labels and semantic HTML
  • Responsive: Natural scrolling with viewport-aware sizing
  • Consistent Navigation: "Back to Dashboard" on all pages

πŸ› οΈ Technology Decisions

Why Azure Speech?

  • Industry-leading speech-to-text accuracy
  • Confidence scores for transcript quality
  • Support for real-time and batch processing

Why Google Gemini?

  • Advanced reasoning capabilities for fraud pattern detection
  • JSON-structured responses for reliable parsing
  • Cost-effective for text analysis

Why Web Audio API?

  • Browser-native audio recording
  • WAV format (16kHz, 16-bit, mono) for optimal Azure compatibility
  • No external dependencies required

Why No Database?

  • Privacy-first: No user data retention
  • Reduced attack surface
  • Simplified deployment
  • GDPR compliant by design

πŸ“Š Risk Levels

Level Score Range Color Meaning
Low 0-30% 🟒 Green Minimal fraud indicators
Medium 31-69% 🟑 Yellow Some suspicious patterns
High 70-100% πŸ”΄ Red Multiple fraud indicators

🀝 Contributing

Contributions are welcome! Please follow these guidelines:

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

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ™ Acknowledgments

  • Azure Cognitive Services for speech recognition
  • Google Gemini AI for fraud analysis
  • React Team for the amazing framework
  • Vite Team for the lightning-fast build tool

πŸ“ž Support

For issues, questions, or suggestions:


Built with ❀️ for safer digital interactions