Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›‘οΈ Nafath Hackathon - Visual Authentication & AI Risk Analysis Platform

React Flutter Python OpenAI Socket.io Three.js

πŸ“‹ Table of Contents


🎯 Overview

This project is an innovative authentication platform built for the Nafath Hackathon that combines:

  1. Visual Authentication - A revolutionary approach using animated 3D particle nebulas with encoded color sequences
  2. QR Code Authentication - Traditional secure scanning method
  3. AI-Powered Risk Analysis - Real-time fraud detection using OpenAI's o3 model
  4. Mobile Approval Workflow - Flutter-based app mimicking the Nafath experience

The system provides a secure, multi-factor authentication solution for Saudi Arabian government and financial services, including banks, telecom providers, and government ministries.


πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                           NAFATH AUTHENTICATION PLATFORM                     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     WebSocket      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”           β”‚
β”‚  β”‚   Desktop Client   │◄──────────────────►│   Express Server   β”‚           β”‚
β”‚  β”‚   (React + Three)  β”‚                    β”‚   (Socket.io)      β”‚           β”‚
β”‚  β”‚                    β”‚                    β”‚   Port: 3000       β”‚           β”‚
β”‚  β”‚  β€’ 3D Nebula       β”‚                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜           β”‚
β”‚  β”‚  β€’ QR Generator    β”‚                                                      β”‚
β”‚  β”‚  β€’ Session Manager β”‚                                                      β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                                      β”‚
β”‚           β”‚                                                                  β”‚
β”‚           β”‚ Visual/QR Scan                                                   β”‚
β”‚           β–Ό                                                                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”           β”‚
β”‚  β”‚   Mobile Scanner   β”‚                    β”‚   Flask Backend    β”‚           β”‚
β”‚  β”‚   (React)          β”‚                    β”‚   Port: 8002       β”‚           β”‚
β”‚  β”‚                    β”‚                    β”‚                    β”‚           β”‚
β”‚  β”‚  β€’ Camera Capture  β”‚    HTTP/REST       β”‚  β€’ Request Store   β”‚           β”‚
β”‚  β”‚  β€’ Color Decoder   β”‚                    β”‚  β€’ Approval Logic  β”‚           β”‚
β”‚  β”‚  β€’ QR Scanner      β”‚                    β”‚  β€’ AI Risk Engine  β”‚           β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜           β”‚
β”‚                                                     β”‚                        β”‚
β”‚                                                     β”‚ Polls                  β”‚
β”‚                                                     β–Ό                        β”‚
β”‚                                            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”           β”‚
β”‚                                            β”‚   Flutter App      β”‚           β”‚
β”‚                                            β”‚   (Nafath Replica) β”‚           β”‚
β”‚                                            β”‚                    β”‚           β”‚
β”‚                                            β”‚  β€’ Request Display β”‚           β”‚
β”‚                                            β”‚  β€’ Approval Timer  β”‚           β”‚
β”‚                                            β”‚  β€’ Accept/Reject   β”‚           β”‚
β”‚                                            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜           β”‚
β”‚                                                     β”‚                        β”‚
β”‚                                                     β”‚ On Approve             β”‚
β”‚                                                     β–Ό                        β”‚
β”‚                                            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”           β”‚
β”‚                                            β”‚   OpenAI o3        β”‚           β”‚
β”‚                                            β”‚   Risk Analysis    β”‚           β”‚
β”‚                                            β”‚                    β”‚           β”‚
β”‚                                            β”‚  β€’ Fraud Detection β”‚           β”‚
β”‚                                            β”‚  β€’ Pattern Analysisβ”‚           β”‚
β”‚                                            β”‚  β€’ Risk Scoring    β”‚           β”‚
β”‚                                            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜           β”‚
β”‚                                                                              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

✨ Features

πŸŒ€ Visual Authentication System

  • 3D Animated Nebula - Particle-based sphere with 4000+ particles using Three.js shaders
  • Dual-Layer Color Encoding - Core and Aura colors create a 4-step visual sequence
  • Camera-Based Decoding - Mobile camera reads RGB color patterns in real-time
  • Rotation-Invariant Matching - Sequences can be read starting from any point
  • Fuzzy Matching - 50%+ similarity threshold for reliable detection

πŸ“± QR Code Authentication

  • Dynamic QR Generation - Session-specific codes with challenge tokens
  • 30-Second Challenge Windows - Time-based security tokens
  • Instant Verification - Fallback for environments where visual scanning isn't optimal

πŸ€– AI-Powered Risk Analysis

  • OpenAI o3 Integration - Advanced reasoning model for fraud detection
  • Multi-Signal Analysis - Evaluates device, location, behavior patterns
  • Contextual Scoring - 0-100 risk score with LOW/MEDIUM/HIGH/CRITICAL levels
  • Detailed Reporting - Comprehensive risk reasons and assessments

πŸ“² Mobile Approval Workflow

  • Real-Time Notifications - Polling-based request detection
  • Visual Timer - 60-second countdown with animated progress
  • One-Tap Actions - Accept or reject with immediate feedback

πŸ”’ Security Features

  • Device Fingerprinting - Browser/device identification via WebGL, Canvas, Audio
  • IP Intelligence - City, country, VPN detection
  • Historical Pattern Analysis - Behavioral anomaly detection
  • Challenge-Response Protocol - Cryptographic handshake verification

πŸ“¦ Components

1. Web Frontend - absher-hakathon

A React + Vite application featuring:

Feature Description
Desktop View 3D particle nebula with color-encoded authentication
Scanner View Camera-based visual pattern decoder
Login System User authentication before scanning
Real-time Sync Socket.io WebSocket communication

Key Technologies:

  • React 19.2 with React Router
  • Three.js via React Three Fiber & Drei
  • Framer Motion animations
  • Tailwind CSS styling
  • Socket.io client

2. Mobile App - nafath_replica

A Flutter cross-platform application:

Feature Description
Request Polling Fetches pending auth requests every 5 seconds
Circular Timer Custom-painted 60-dash countdown display
Approval Actions Accept/Reject buttons with API integration
Auto-Timeout Automatic rejection when timer expires

Supported Platforms:

  • iOS
  • Android
  • Web
  • macOS
  • Windows
  • Linux

3. Backend - NafathBackend

Python Flask API with AI integration:

Endpoint Method Description
/api/request POST Store authentication request
/api/request GET Retrieve pending request
/api/approval POST Submit approval decision
/api/approval GET Fetch approval result with risk analysis

Additional Tools:

  • fingerprinter.html - Browser fingerprint generator
  • request_builder_2.html - Interactive request builder UI
  • request_properties.json - Request schema definition

πŸš€ Installation

Prerequisites

  • Node.js 18+ (for web frontend)
  • Flutter 3.8+ (for mobile app)
  • Python 3.9+ (for backend)
  • OpenAI API Key (for AI risk analysis)

1. Clone the Repository

git clone https://github.com/your-repo/NafathHackathonAll.git
cd NafathHackathonAll

2. Install Web Frontend

cd absher-hakathon

# Install dependencies
npm install

# Start development server (includes Express backend)
npm run dev

The server runs on http://localhost:5173 (Vite) with WebSocket on port 3000.

3. Install Backend

cd NafathBackend/backend

# Create virtual environment (recommended)
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Add your OpenAI API key
# Edit agent.py and replace "OPENAI_KEY" with your actual key

# Start the server
python app.py

The API runs on http://localhost:8002.

4. Install Flutter App

cd nafath_replica

# Get dependencies
flutter pub get

# Run on your preferred platform
flutter run                    # Auto-detect device
flutter run -d chrome          # Web browser
flutter run -d macos           # macOS
flutter run -d ios             # iOS simulator
flutter run -d android         # Android emulator

πŸ“– Usage

Desktop Authentication Flow

  1. Open Desktop App - Navigate to http://localhost:5173
  2. View Nebula - A 3D particle sphere with encoded colors appears
  3. Toggle QR Mode - Click "Show QR Code" for easier scanning

Mobile Authentication Flow

  1. Login - Go to http://localhost:5173/login
    • Username: user1 or user2
    • Password: password
  2. Scan - Point camera at desktop nebula or QR code
  3. Authenticate - Session pairs automatically on match

Request Builder Flow

  1. Open Builder - Open NafathBackend/request_builder_2.html in browser
  2. Configure Request - Fill in operation details, requester context
  3. Submit - Send to backend
  4. Approve in App - Open Flutter app and accept/reject
  5. View Risk - Risk analysis appears after approval

Flutter App Flow

  1. Launch App - The app shows "Waiting for requests"
  2. Receive Request - When a request is sent, it displays with a timer
  3. Approve/Reject - Tap the appropriate button
  4. AI Analysis - On approval, risk assessment is generated

πŸ”Œ API Reference

Store Request

POST /api/request
Content-Type: application/json

{
  "request_metadata": {
    "target_national_id": "1234567890"
  },
  "operation_details": {
    "client_name": "STC_BANK",
    "operation_type": "OPEN_BANK_ACCOUNT",
    "operation_sensitivity": "HIGH"
  },
  "requester_context": {
    "device": { ... },
    "ip_information": { ... }
  }
}

Get Pending Request

GET /api/request

Submit Approval

POST /api/approval
Content-Type: application/json

{
  "status": "approved"
}

Get Approval Result

GET /api/approval

Response includes AI risk analysis:

{
  "status": "success",
  "approval_risk": {
    "risk_score": 35,
    "risk_level": "MEDIUM",
    "risk_reasons": ["First-time device usage", "IP city mismatch"],
    "overall_assessment": "Some anomalies detected but within acceptable parameters.",
    "analysis_confidence": 75
  }
}

πŸ” Authentication Flow

[Service Provider]                [Backend]                [Mobile App]              [AI Engine]
       β”‚                             β”‚                          β”‚                        β”‚
       β”‚  1. POST /api/request       β”‚                          β”‚                        β”‚
       │────────────────────────────►│                          β”‚                        β”‚
       β”‚                             β”‚                          β”‚                        β”‚
       β”‚                             β”‚  2. GET /api/request     β”‚                        β”‚
       β”‚                             │◄─────────────────────────│ (polling every 5s)    β”‚
       β”‚                             β”‚                          β”‚                        β”‚
       β”‚                             β”‚  3. Request Data         β”‚                        β”‚
       β”‚                             │─────────────────────────►│                        β”‚
       β”‚                             β”‚                          β”‚                        β”‚
       β”‚                             β”‚                          β”‚ 4. User Decision      β”‚
       β”‚                             β”‚                          β”‚    (60s timer)        β”‚
       β”‚                             β”‚                          β”‚                        β”‚
       β”‚                             β”‚  5. POST /api/approval   β”‚                        β”‚
       β”‚                             │◄─────────────────────────│                        β”‚
       β”‚                             β”‚                          β”‚                        β”‚
       β”‚                             β”‚  6. Analyze Risk         β”‚                        β”‚
       β”‚                             │─────────────────────────────────────────────────►│
       β”‚                             β”‚                          β”‚                        β”‚
       β”‚                             β”‚  7. Risk Assessment      β”‚                        β”‚
       β”‚                             │◄─────────────────────────────────────────────────│
       β”‚                             β”‚                          β”‚                        β”‚
       β”‚  8. GET /api/approval       β”‚                          β”‚                        β”‚
       │◄────────────────────────────│                          β”‚                        β”‚
       β”‚  (includes risk analysis)   β”‚                          β”‚                        β”‚

πŸ›‘οΈ Security Features

Visual Authentication Security

Layer Protection
Color Encoding 4-step RGB sequence with core/aura dual-layer
Rotation Tolerance All 4 rotations mapped for flexible reading
Fuzzy Matching 50% similarity threshold prevents false negatives
Session Isolation Each session has unique sequence

Challenge-Response Protocol

Feature Implementation
Time-Based Tokens 30-second challenge windows
SHA-256 Hashing Cryptographic challenge generation
Window Tolerance Current + previous window accepted
Secret Key Server-side secret for token generation

AI Risk Analysis Signals

Signal Group Factors Analyzed
Device Context Device hash, user agent, browser, OS
IP Intelligence City, country, VPN status, ISP
Behavioral Patterns Request frequency, historical cities, device usage
Temporal Analysis 24-hour activity, session duration, timeouts
Data Consistency Name, phone, address verification

πŸ§ͺ Demo Credentials

Web Login

Username Password Role
user1 password Admin
user2 password Visitor

Supported Service Providers

  • Ministry of Justice
  • Real Estate Registrars
  • STC Bank / STC
  • SAB Bank / Al Rajhi Bank / Alinma Bank
  • Monshaat
  • Ejar
  • Mobily

Supported Operations

  • Platform Login
  • Register Account
  • Issue Power of Attorney
  • Open Bank Account
  • Issue New SIM
  • Verify Trusted Device
  • Verify Loan Request

πŸ› οΈ Technologies Used

Frontend

Technology Version Purpose
React 19.2.0 UI Framework
Vite 7.2.4 Build Tool
Three.js 0.181.2 3D Graphics
React Three Fiber 9.4.0 React + Three.js Bridge
Socket.io Client 4.8.1 WebSocket Communication
Framer Motion 12.23.24 Animations
Tailwind CSS 3.4.17 Styling
Lucide React 0.554.0 Icons

Backend

Technology Version Purpose
Flask 3.0.0 API Framework
Flask-CORS 4.0.0 Cross-Origin Requests
OpenAI Latest AI Risk Analysis (o3 model)
Express 5.1.0 WebSocket Server
Socket.io 4.8.1 Real-time Communication

Mobile

Technology Version Purpose
Flutter 3.8.1 Cross-Platform Framework
http 1.5.0 HTTP Client
cupertino_icons 1.0.8 iOS Icons

πŸ“ Project Structure

NafathHackathonAll/
β”œβ”€β”€ absher-hakathon/              # Web Frontend (React + Vite)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ Login.jsx         # User authentication
β”‚   β”‚   β”‚   β”œβ”€β”€ Scanner.jsx       # Visual/QR scanner
β”‚   β”‚   β”‚   β”œβ”€β”€ ParticleField.jsx # 3D nebula shader
β”‚   β”‚   β”‚   └── OverlayUI.jsx     # UI overlays
β”‚   β”‚   β”œβ”€β”€ App.jsx               # Main app with routing
β”‚   β”‚   └── main.jsx              # Entry point
β”‚   β”œβ”€β”€ server.js                 # Express + Socket.io server
β”‚   └── package.json
β”‚
β”œβ”€β”€ nafath_replica/               # Flutter Mobile App
β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”œβ”€β”€ main.dart             # App entry point
β”‚   β”‚   └── process_screen.dart   # Request approval screen
β”‚   └── pubspec.yaml
β”‚
β”œβ”€β”€ NafathBackend/                # Python Backend
β”‚   β”œβ”€β”€ backend/
β”‚   β”‚   β”œβ”€β”€ app.py                # Flask API
β”‚   β”‚   β”œβ”€β”€ agent.py              # OpenAI risk analysis
β”‚   β”‚   β”œβ”€β”€ prompt.txt            # AI system prompt
β”‚   β”‚   └── requirements.txt      # Python dependencies
β”‚   β”œβ”€β”€ fingerprinter.html        # Device fingerprinting tool
β”‚   β”œβ”€β”€ request_builder_2.html    # Request builder UI
β”‚   └── request_properties.json   # Request schema
β”‚
└── README.md                     # This file

🀝 Contributing

  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 was created for the Nafath Hackathon.


πŸ™ Acknowledgments

  • Nafath - For the hackathon opportunity
  • OpenAI - For the o3 reasoning model
  • Three.js Community - For shader examples and guidance

Built with ❀️ for the Nafath Hackathon

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages