Skip to content

Latest commit

Β 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Node.js CI Coverage License

πŸŽ‰ Face Recognition Application

A professional face recognition application built with Node.js, TensorFlow.js, and Docker. This project delivers advanced face detection and recognition with enterprise-grade security and blazing-fast performance.


πŸš€ Features

✨ AI-Powered Recognition: Advanced face detection and recognition using TensorFlow.js and face-api.js
πŸ”’ Enterprise Security: Security best practices (rate limiting, input validation, secure file handling, CSP, CORS)
🐳 Docker Ready: Multi-stage Docker build for consistent deployment
⚑ High Performance: Optimized with compression, Redis caching, and efficient image processing
πŸ’» Modern UI: Responsive web interface (EJS + Tailwind CSS)
πŸ”— API First: RESTful API endpoints for integration
⏱️ Real-time Processing: Fast face detection and recognition with confidence scoring
πŸŽ₯ Live Face Recognition: Real-time face detection and recognition from webcam (WebRTC), with smart pause and overlay
πŸ“‹ Comprehensive Logging: Winston logger, request logging, error tracking
πŸ§ͺ Automated Testing: Jest, Supertest, CI/CD pipeline

πŸ“Έ Demo & Screenshots

Here are some main views of the application:

Home

Home Main dashboard view of the Face Recognition app.

Enroll Face

Enroll Page to enroll a new face into the database.

Recognize Face

Recognize Page to recognize a face from an uploaded photo.

Live Face Recognition

Live Recognize Real-time face recognition from webcam with overlay and results card.

About

About Project and developer profile page.


πŸ› οΈ Tech Stack

  • Backend: Node.js, Express.js
  • AI/ML: TensorFlow.js, face-api.js
  • Database: SQLite3
  • Image Processing: Sharp, Canvas
  • Security: Helmet, Rate Limiting, Input Validation, CORS, CSP
  • Performance: Compression, Redis Caching
  • Frontend: EJS, Tailwind CSS
  • Containerization: Docker, Docker Compose
  • Development: ESLint, Prettier, Nodemon, Jest, Supertest

πŸ“‹ Prerequisites

  • Node.js >= 18.0.0
  • npm >= 8.0.0
  • Docker & Docker Compose (for containerized deployment)

🚦 Quick Start

  1. Clone the repository
   git clone https://github.com/dedinopriadi/face-recognition-app.git
cd face-recognition-app
  1. Install dependencies
npm install
  1. Download Face Recognition Models
node scripts/download-models.js
   # Or download manually from:
# https://github.com/justadudewhohacks/face-api.js/tree/master/weights
# Place files in ./models directory
  1. Start development server
npm run dev
  1. Access the application

🐳 Docker Development

npm run docker:dev
# App: http://localhost:3000
# Redis: localhost:6379
# Redis Commander: http://localhost:8081

🚒 Production Deployment

npm run docker:prod

πŸ›  Project Structure

face-recognition-app/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   β”œβ”€β”€ database.js
β”‚   β”‚   β”œβ”€β”€ logger.js
β”‚   β”‚   β”œβ”€β”€ redis.js
β”‚   β”‚   └── config.js
β”‚   β”œβ”€β”€ controllers/
β”‚   β”‚   └── faceController.js
β”‚   β”œβ”€β”€ middleware/
β”‚   β”‚   β”œβ”€β”€ upload.js
β”‚   β”‚   └── validator.js
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   └── faceRoutes.js
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   └── faceRecognitionService.js
β”‚   β”œβ”€β”€ views/
β”‚   β”‚   β”œβ”€β”€ index.ejs
β”‚   β”‚   β”œβ”€β”€ enroll.ejs
β”‚   β”‚   β”œβ”€β”€ recognize.ejs
β”‚   β”‚   β”œβ”€β”€ 404.ejs
β”‚   β”‚   └── error.ejs
β”‚   └── server.js
β”œβ”€β”€ models/              # Face-api.js model files
β”œβ”€β”€ data/                # SQLite database files
β”œβ”€β”€ uploads/             # File uploads
β”œβ”€β”€ public/              # Static assets
β”œβ”€β”€ tests/               # Test files
β”œβ”€β”€ scripts/             # Build and deployment scripts
β”œβ”€β”€ Dockerfile           # Multi-stage Docker build
β”œβ”€β”€ docker-compose.dev.yml
β”œβ”€β”€ docker-compose.prod.yml
β”œβ”€β”€ package.json
└── README.md

πŸ”§ Configuration

Environment Variables

Buat file .env di root project, contoh:

NODE_ENV=development
PORT=3000
REDIS_HOST=redis
REDIS_PORT=6379
# REDIS_URL=redis://localhost:6379
UPLOAD_PATH=./uploads
MAX_FILE_SIZE=10485760
CORS_ORIGIN=http://localhost:3000
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX_REQUESTS=100

πŸ”’ Security Features

  • Helmet: Security headers
  • CSP: Content Security Policy strict
  • CORS: Configurable via env
  • Rate Limiting: Global & sensitive endpoint (Redis store)
  • Input Validation: All endpoints
  • File Upload Validation: Type, size, and content
  • User non-root: Dockerfile prod

πŸ“š API Documentation

Health Check

GET /health

Returns application health status.

API Status

GET /api/status

Returns API version and environment information.

Face Recognition Health

GET /api/face/health

Returns face recognition service status and model loading status.

Enroll New Face

POST /api/face/enroll
Content-Type: multipart/form-data
Body:
- name: string (required)
- image: file (required)

Enrolls a new face in the database.

Recognize Face

POST /api/face/recognize
Content-Type: multipart/form-data
Body:
- image: file (required)

Recognizes a face against the enrolled database.

Live Face Recognition (Webcam)

POST /api/face/recognize-live
Content-Type: multipart/form-data
Body:
- image: file (required, JPEG/PNG/WebP frame from webcam)

Performs real-time face recognition from webcam frames. Returns detected face info, bounding box, name, confidence, and overlay data.

Smart Pause:

  • When the same face is recognized continuously, the client will pause sending frames to save resources.
  • Recognition resumes automatically if the face changes or is no longer detected.

Example Response:

{
  "message": "Face recognized successfully",
  "data": {
    "recognized": true,
    "person": {
      "id": 8,
      "name": "Dedi Nopriadi",
      "confidence": 0.63,
      "similarity": 0.63,
      "box": { "x": 172, "y": 133, "width": 163, "height": 141 }
    }
  },
  "source": "live"
}

Get All Faces

GET /api/face/faces

Returns all enrolled faces.

Get Face by ID

GET /api/face/faces/:id

Returns specific face details.

Delete Face

DELETE /api/face/faces/:id

Deletes a face from the database.

Get Dashboard Data

GET /api/face/dashboard

Returns statistics and recent recognition logs.

Get Statistics

GET /api/face/stats

Returns face recognition statistics.


πŸ§ͺ Testing & Code Quality

npm test           # Run all tests
npm run test:watch # Watch mode
npm run lint       # Lint code
npm run lint:fix   # Auto-fix lint
npm run format     # Format code

🐳 Docker Commands

npm run docker:dev   # Development
npm run docker:prod  # Production
npm run docker:down  # Stop all containers

πŸ“Š Monitoring & Logging

  • Health check: /health
  • API status: /api/status
  • Face recognition health: /api/face/health
  • Request logging with Morgan
  • Error tracking and logging (Winston)
  • Live recognize: All frames are processed in-memory, no files are saved to disk for live recognition. Only important events are logged.

🀝 Contribute & Support

We welcome contributions from everyone! πŸš€

  • Fork this repository and submit your awesome pull requests.
  • Open issues for bugs, ideas, or questions.
  • Let's build something amazing together!

If you like this project, consider supporting it:

ko-fi


πŸ“„ License

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


πŸ™ Acknowledgments


Made with ❀️ by dedinopriadi β€” Happy coding!

About

AI-powered face recognition web app built with Node.js, TensorFlow.js, and Docker. Secure, modern, and production-ready. Enroll, detect, and recognize faces with RESTful API and responsive UI.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages