Skip to content

NMOLE08/FacePay

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

18 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

FacePay - Face Recognition Payment System

A comprehensive, secure, face-recognition-based payment system with both Node.js backend and Python face recognition service, featuring a modern web frontend.

๐Ÿš€ Features

Core Features

  • Advanced Face Recognition: Dual-engine system with both JavaScript and Python-based recognition
  • Face-Based Payments: Secure payment processing with facial verification
  • Stripe Integration: Complete payment processing with Stripe
  • User Management: Full user registration, profile management, and authentication
  • Payment History: Comprehensive transaction tracking and management
  • Real-time Processing: Fast and accurate face detection and recognition

Security Features

  • Multi-Layer Authentication: JWT tokens, face recognition, and password protection
  • Rate Limiting: Protection against brute force attacks
  • Input Validation: Comprehensive request validation and sanitization
  • Encryption: Secure data transmission and storage
  • Account Protection: Temporary lockout after failed attempts

Technical Features

  • Microservices Architecture: Separate Node.js backend and Python face recognition service
  • Image Processing: Advanced face detection, quality validation, and embedding generation
  • API Documentation: Comprehensive REST API endpoints
  • Error Handling: Robust error management and logging
  • Development Tools: Startup scripts and utilities for easy development

๐Ÿ› ๏ธ Tech Stack

Backend Services

  • Node.js Backend: Express.js, MongoDB, JWT authentication
  • Python Face Recognition Service: InsightFace, OpenCV, Flask
  • Database: MongoDB with Mongoose ODM
  • Payment Processing: Stripe API integration

Frontend

  • HTML5/CSS3: Modern, responsive web interface
  • JavaScript: Interactive user experience
  • Bootstrap: Clean and professional UI design

Face Recognition

  • JavaScript Engine: face-api.js with TensorFlow.js
  • Python Engine: InsightFace with advanced AI models
  • Image Processing: Sharp, Canvas, OpenCV

Security & Validation

  • Authentication: JWT (JSON Web Tokens), bcryptjs
  • Security: Helmet, CORS, rate limiting
  • Validation: express-validator, Joi

๐Ÿ“‹ Prerequisites

  • Node.js (v18 or higher)
  • Python (3.9 or higher)
  • MongoDB (local or cloud)
  • Stripe account with API keys
  • Git

๐Ÿš€ Quick Start

1. Clone the Repository

git clone https://github.com/Aditya232-rtx/FacePay.git
cd FacePay

2. Install Dependencies

# Install Node.js dependencies
npm install

# Install Python dependencies
cd face-recognition-service
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -r requirements.txt
cd ..

3. Environment Setup

Copy the environment template and configure your variables:

cp env.example .env

Edit .env with your configuration:

# Server Configuration
PORT=3000
NODE_ENV=development

# Database Configuration
MONGODB_URI=mongodb://localhost:27017/facepay

# JWT Configuration
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
JWT_EXPIRES_IN=24h

# Stripe Configuration
STRIPE_SECRET_KEY=sk_test_your_stripe_secret_key
STRIPE_PUBLISHABLE_KEY=pk_test_your_stripe_publishable_key

# Face Recognition Configuration
FACE_RECOGNITION_THRESHOLD=0.6
FACE_DETECTION_CONFIDENCE=0.5

# Python Service Configuration
PYTHON_SERVICE_URL=http://localhost:5000

4. Download Face Recognition Models

For JavaScript Engine (face-api.js)

Create a models directory and download the required face-api.js models:

mkdir models
cd models

Download the following files from face-api.js models:

  • tiny_face_detector_model-weights_manifest.json
  • tiny_face_detector_model-shard1
  • face_landmark_68_model-weights_manifest.json
  • face_landmark_68_model-shard1
  • face_recognition_model-weights_manifest.json
  • face_recognition_model-shard1
  • face_expression_model-weights_manifest.json
  • face_expression_model-shard1

For Python Engine (InsightFace)

The Python service will automatically download required models on first run.

5. Start the Services

Option 1: Use Startup Scripts (Recommended)

# Start both services
./start-mvp.sh

# Or start services individually
./start-node-service.sh
./start-python-service.sh

Option 2: Manual Startup

# Terminal 1: Start Node.js backend
npm run dev

# Terminal 2: Start Python face recognition service
cd face-recognition-service
source venv/bin/activate
python app.py

The services will be available at:

  • Node.js Backend: http://localhost:3000
  • Python Face Recognition Service: http://localhost:5000
  • Frontend: http://localhost:3000 (served by Node.js)

๐Ÿ“š API Documentation

Authentication Endpoints

Register User

POST /api/auth/register
Content-Type: application/json

{
  "firstName": "John",
  "lastName": "Doe",
  "email": "john@example.com",
  "phone": "+1234567890",
  "password": "securepassword123"
}

Login

POST /api/auth/login
Content-Type: application/json

{
  "email": "john@example.com",
  "password": "securepassword123"
}

Face Login

POST /api/auth/face-login
Content-Type: multipart/form-data

faceImage: [image file]

Register Face

POST /api/auth/register-face
Authorization: Bearer <token>
Content-Type: multipart/form-data

faceImage: [image file]

Face Recognition Endpoints

Detect Faces (JavaScript Engine)

POST /api/face/detect
Content-Type: multipart/form-data

image: [image file]

Detect Faces (Python Engine)

POST /api/face/detect-python
Content-Type: multipart/form-data

image: [image file]

Validate Face Quality

POST /api/face/validate
Content-Type: multipart/form-data

image: [image file]

Verify Face

POST /api/face/verify
Authorization: Bearer <token>
Content-Type: multipart/form-data

image: [image file]

Payment Endpoints

Face Payment

POST /api/payments/face-payment
Authorization: Bearer <token>
Content-Type: multipart/form-data

faceImage: [image file]
amount: 25.50
currency: usd
description: "Coffee purchase"
paymentMethod: card

Confirm Payment

POST /api/payments/confirm
Authorization: Bearer <token>
Content-Type: application/json

{
  "paymentIntentId": "pi_xxx",
  "paymentMethodId": "pm_xxx"
}

Get Payment History

GET /api/payments/history?limit=10&offset=0
Authorization: Bearer <token>

Get Payment Statistics

GET /api/payments/stats?period=30d
Authorization: Bearer <token>

User Management Endpoints

Get Profile

GET /api/users/profile
Authorization: Bearer <token>

Update Profile

PUT /api/users/profile
Authorization: Bearer <token>
Content-Type: application/json

{
  "firstName": "John",
  "lastName": "Smith",
  "phone": "+1234567890"
}

๐Ÿ”ง Configuration

Environment Variables

Variable Description Default
PORT Server port 3000
NODE_ENV Environment mode development
MONGODB_URI MongoDB connection string -
JWT_SECRET JWT signing secret -
JWT_EXPIRES_IN JWT expiration time 24h
STRIPE_SECRET_KEY Stripe secret key -
STRIPE_PUBLISHABLE_KEY Stripe publishable key -
FACE_RECOGNITION_THRESHOLD Face recognition threshold 0.6
FACE_DETECTION_CONFIDENCE Face detection confidence 0.5
PYTHON_SERVICE_URL Python face recognition service URL http://localhost:5000
BCRYPT_ROUNDS Password hashing rounds 12
MAX_FILE_SIZE Maximum file upload size 5MB

Face Recognition Settings

  • Threshold: Lower values (0.4-0.6) are more strict, higher values (0.7-0.9) are more lenient
  • Confidence: Minimum confidence for face detection (0.5-0.9)

๐Ÿ”’ Security Features

  • JWT Authentication: Secure token-based authentication
  • Password Hashing: bcrypt with configurable rounds
  • Rate Limiting: Prevents brute force attacks
  • Input Validation: Comprehensive request validation
  • CORS Protection: Configurable cross-origin requests
  • Helmet: Security headers
  • Account Locking: Temporary lock after failed attempts
  • Face Recognition Security: Multi-engine verification system

๐Ÿ“ Project Structure

FacePay/
โ”œโ”€โ”€ src/                          # Node.js backend
โ”‚   โ”œโ”€โ”€ config/
โ”‚   โ”‚   โ””โ”€โ”€ database.js           # Database configuration
โ”‚   โ”œโ”€โ”€ middleware/
โ”‚   โ”‚   โ”œโ”€โ”€ auth.js              # Authentication middleware
โ”‚   โ”‚   โ””โ”€โ”€ errorHandler.js      # Error handling middleware
โ”‚   โ”œโ”€โ”€ models/                   # Database models
โ”‚   โ”œโ”€โ”€ routes/                   # API routes
โ”‚   โ”‚   โ”œโ”€โ”€ auth.js              # Authentication routes
โ”‚   โ”‚   โ”œโ”€โ”€ face.js              # Face recognition routes
โ”‚   โ”‚   โ”œโ”€โ”€ payments.js          # Payment routes
โ”‚   โ”‚   โ””โ”€โ”€ users.js             # User management routes
โ”‚   โ”œโ”€โ”€ services/
โ”‚   โ”‚   โ”œโ”€โ”€ faceRecognition.js   # Face recognition service
โ”‚   โ”‚   โ””โ”€โ”€ paymentService.js    # Payment processing service
โ”‚   โ””โ”€โ”€ server.js                # Main server file
โ”œโ”€โ”€ face-recognition-service/     # Python face recognition service
โ”‚   โ”œโ”€โ”€ app.py                   # Flask application
โ”‚   โ”œโ”€โ”€ requirements.txt         # Python dependencies
โ”‚   โ””โ”€โ”€ README.md               # Service documentation
โ”œโ”€โ”€ frontend/                     # Web frontend
โ”‚   โ”œโ”€โ”€ html/                    # HTML pages
โ”‚   โ”œโ”€โ”€ css/                     # Stylesheets
โ”‚   โ”œโ”€โ”€ assets/                  # Images and resources
โ”‚   โ””โ”€โ”€ index.html              # Main entry point
โ”œโ”€โ”€ scripts/                      # Utility scripts
โ”‚   โ”œโ”€โ”€ clear-database.js        # Database cleanup
โ”‚   โ””โ”€โ”€ download-models.js       # Model downloader
โ”œโ”€โ”€ uploads/                      # File uploads directory
โ”œโ”€โ”€ models/                       # Face recognition models
โ”œโ”€โ”€ start-mvp.sh                 # Main startup script
โ”œโ”€โ”€ start-node-service.sh        # Node.js service starter
โ”œโ”€โ”€ start-python-service.sh      # Python service starter
โ””โ”€โ”€ README.md                    # This file

๐Ÿงช Testing

# Run Node.js tests
npm test

# Run tests with coverage
npm run test:coverage

# Test face recognition service
cd face-recognition-service
python -m pytest

๐Ÿš€ Deployment

Production Setup

  1. Set NODE_ENV=production
  2. Configure production MongoDB URI
  3. Set strong JWT secret
  4. Configure Stripe production keys
  5. Set up SSL/TLS certificates
  6. Configure reverse proxy (nginx)
  7. Set up monitoring and logging
  8. Configure Python service for production

Docker Deployment

Node.js Backend

FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 3000
CMD ["npm", "start"]

Python Face Recognition Service

FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 5000
CMD ["python", "app.py"]

๐Ÿ› ๏ธ Development Tools

Utility Scripts

  • start-mvp.sh: Start both Node.js and Python services
  • start-node-service.sh: Start only Node.js backend
  • start-python-service.sh: Start only Python face recognition service
  • scripts/clear-database.js: Clear database for testing
  • scripts/download-models.js: Download face recognition models

Database Management

# Clear database
node scripts/clear-database.js

# Download models
node scripts/download-models.js

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass
  6. Submit a pull request

Development Guidelines

  • Follow the existing code style
  • Add comprehensive error handling
  • Include API documentation for new endpoints
  • Write tests for new features
  • Update the README for significant changes

๐Ÿ“„ License

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

๐Ÿ†˜ Support

For support and questions:

  • ๐Ÿ“– Check the documentation
  • ๐Ÿ› Create an issue in the repository
  • ๐Ÿ’ฌ Contact the development team
  • ๐Ÿ”ง Check troubleshooting guides in the repository

๐Ÿ”ฎ Roadmap

Short Term

  • Enhanced face recognition accuracy
  • Mobile app development
  • Real-time payment notifications
  • Advanced fraud detection

Long Term

  • Multi-factor authentication
  • International payment support
  • Advanced analytics dashboard
  • Biometric liveness detection
  • Voice recognition integration
  • Blockchain payment support

๐Ÿ† Acknowledgments

  • InsightFace: Advanced face recognition models
  • face-api.js: JavaScript face recognition library
  • Stripe: Payment processing platform
  • MongoDB: Database solution
  • Express.js: Web framework
  • Flask: Python web framework

FacePay - Secure, Fast, and Reliable Face Recognition Payments

About

Face Recognition Payment System MVP

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •