A comprehensive, secure, face-recognition-based payment system with both Node.js backend and Python face recognition service, featuring a modern web frontend.
- 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
- 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
- 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
- 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
- HTML5/CSS3: Modern, responsive web interface
- JavaScript: Interactive user experience
- Bootstrap: Clean and professional UI design
- JavaScript Engine: face-api.js with TensorFlow.js
- Python Engine: InsightFace with advanced AI models
- Image Processing: Sharp, Canvas, OpenCV
- Authentication: JWT (JSON Web Tokens), bcryptjs
- Security: Helmet, CORS, rate limiting
- Validation: express-validator, Joi
- Node.js (v18 or higher)
- Python (3.9 or higher)
- MongoDB (local or cloud)
- Stripe account with API keys
- Git
git clone https://github.com/Aditya232-rtx/FacePay.git
cd FacePay# 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 ..Copy the environment template and configure your variables:
cp env.example .envEdit .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:5000Create a models directory and download the required face-api.js models:
mkdir models
cd modelsDownload the following files from face-api.js models:
tiny_face_detector_model-weights_manifest.jsontiny_face_detector_model-shard1face_landmark_68_model-weights_manifest.jsonface_landmark_68_model-shard1face_recognition_model-weights_manifest.jsonface_recognition_model-shard1face_expression_model-weights_manifest.jsonface_expression_model-shard1
The Python service will automatically download required models on first run.
# Start both services
./start-mvp.sh
# Or start services individually
./start-node-service.sh
./start-python-service.sh# 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.pyThe 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)
POST /api/auth/register
Content-Type: application/json
{
"firstName": "John",
"lastName": "Doe",
"email": "john@example.com",
"phone": "+1234567890",
"password": "securepassword123"
}POST /api/auth/login
Content-Type: application/json
{
"email": "john@example.com",
"password": "securepassword123"
}POST /api/auth/face-login
Content-Type: multipart/form-data
faceImage: [image file]POST /api/auth/register-face
Authorization: Bearer <token>
Content-Type: multipart/form-data
faceImage: [image file]POST /api/face/detect
Content-Type: multipart/form-data
image: [image file]POST /api/face/detect-python
Content-Type: multipart/form-data
image: [image file]POST /api/face/validate
Content-Type: multipart/form-data
image: [image file]POST /api/face/verify
Authorization: Bearer <token>
Content-Type: multipart/form-data
image: [image file]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: cardPOST /api/payments/confirm
Authorization: Bearer <token>
Content-Type: application/json
{
"paymentIntentId": "pi_xxx",
"paymentMethodId": "pm_xxx"
}GET /api/payments/history?limit=10&offset=0
Authorization: Bearer <token>GET /api/payments/stats?period=30d
Authorization: Bearer <token>GET /api/users/profile
Authorization: Bearer <token>PUT /api/users/profile
Authorization: Bearer <token>
Content-Type: application/json
{
"firstName": "John",
"lastName": "Smith",
"phone": "+1234567890"
}| 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 |
- 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)
- 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
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
# 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- Set
NODE_ENV=production - Configure production MongoDB URI
- Set strong JWT secret
- Configure Stripe production keys
- Set up SSL/TLS certificates
- Configure reverse proxy (nginx)
- Set up monitoring and logging
- Configure Python service for production
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 3000
CMD ["npm", "start"]FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 5000
CMD ["python", "app.py"]start-mvp.sh: Start both Node.js and Python servicesstart-node-service.sh: Start only Node.js backendstart-python-service.sh: Start only Python face recognition servicescripts/clear-database.js: Clear database for testingscripts/download-models.js: Download face recognition models
# Clear database
node scripts/clear-database.js
# Download models
node scripts/download-models.js- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
- 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
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- ๐ Check the documentation
- ๐ Create an issue in the repository
- ๐ฌ Contact the development team
- ๐ง Check troubleshooting guides in the repository
- Enhanced face recognition accuracy
- Mobile app development
- Real-time payment notifications
- Advanced fraud detection
- Multi-factor authentication
- International payment support
- Advanced analytics dashboard
- Biometric liveness detection
- Voice recognition integration
- Blockchain payment support
- 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