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.
β¨ 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
Here are some main views of the application:
Main dashboard view of the Face Recognition app.
Page to enroll a new face into the database.
Page to recognize a face from an uploaded photo.
Real-time face recognition from webcam with overlay and results card.
Project and developer profile page.
- 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
- Node.js >= 18.0.0
- npm >= 8.0.0
- Docker & Docker Compose (for containerized deployment)
- Clone the repository
git clone https://github.com/dedinopriadi/face-recognition-app.git
cd face-recognition-app- Install dependencies
npm install- 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- Start development server
npm run dev- Access the application
- π Web UI: http://localhost:3000
- π Enroll Faces: http://localhost:3000/enroll
- π΅οΈ Recognize Faces: http://localhost:3000/recognize
- π₯ Live Face Recognition: http://localhost:3000/live-recognize
- π Health Check: http://localhost:3000/health
- π API Status: http://localhost:3000/api/status
npm run docker:dev
# App: http://localhost:3000
# Redis: localhost:6379
# Redis Commander: http://localhost:8081npm run docker:prodface-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
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- 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
GET /health
Returns application health status.
GET /api/status
Returns API version and environment information.
GET /api/face/health
Returns face recognition service status and model loading status.
POST /api/face/enroll
Content-Type: multipart/form-data
Body:
- name: string (required)
- image: file (required)
Enrolls a new face in the database.
POST /api/face/recognize
Content-Type: multipart/form-data
Body:
- image: file (required)
Recognizes a face against the enrolled database.
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 /api/face/faces
Returns all enrolled faces.
GET /api/face/faces/:id
Returns specific face details.
DELETE /api/face/faces/:id
Deletes a face from the database.
GET /api/face/dashboard
Returns statistics and recent recognition logs.
GET /api/face/stats
Returns face recognition statistics.
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 codenpm run docker:dev # Development
npm run docker:prod # Production
npm run docker:down # Stop all containers- 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.
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:
This project is licensed under the MIT License. See the LICENSE file for details.
- @vladmandic/face-api for face recognition (Node.js optimized fork of face-api.js)
- TensorFlow.js for AI capabilities
- Express.js for the web framework
- Tailwind CSS for styling
Made with β€οΈ by dedinopriadi β Happy coding!