A full-stack demo that registers users with facial embeddings and performs realtime authentication using webcam input. The backend stores embeddings and exposes REST/Socket.IO endpoints, while the frontend uses face-api.js to capture descriptors from the browser and render face landmarks.
- User registration with face embedding, age, and gender detection.
- Realtime authentication via Socket.IO events.
- Webcam-based face detection with landmark overlays.
- PostgreSQL-backed persistence using Prisma.
Frontend
- React + TypeScript + Vite
face-api.jsfor face detection/recognition- Socket.IO client and Axios
- Tailwind CSS for styling
Backend
- Node.js + Express
- Prisma ORM (PostgreSQL)
- Socket.IO for realtime authentication
.
├── backend
│ ├── prisma
│ │ └── schema.prisma
│ ├── server.js
│ ├── docker-compose.yaml
│ └── package.json
├── frontend
│ ├── src
│ │ ├── components
│ │ │ ├── Authenticate.tsx
│ │ │ └── Register.tsx
│ │ └── App.tsx
│ └── package.json
└── README.md
- Node.js 18+ (recommended)
- pnpm (recommended) or npm
- PostgreSQL database
- A webcam device for running the frontend
Create a .env file in backend/ with the following value:
DATABASE_URL=postgresql://USER:PASSWORD@HOST:PORT/DATABASE
cd backend
pnpm installGenerate the Prisma client and run migrations (or push the schema) against your database:
pnpm prisma generate
pnpm prisma migrate dev
# or: pnpm prisma db pushStart the backend server:
node server.jsThe backend listens on http://localhost:3000.
cd frontend
pnpm install
pnpm devThe frontend runs on http://localhost:5173 by default.
- Open the frontend in a browser and allow camera access.
- Register a user by entering a name/email and clicking Register.
- Switch to authentication and click Authenticate to match against stored embeddings.
Face recognition models are loaded at runtime from a CDN in the frontend components.
-
POST /register- Body:
{ name, email, faceEmbedding, gender, age } - Response: created user record or error.
- Body:
-
GET /detail/:name- Response: the stored face embeddings for the given name.
-
authenticate(client → server)- Payload:
{ faceEmbedding }
- Payload:
-
authResult(server → client)- Payload:
{ success: boolean, user?: string }
- Payload:
backend/docker-compose.yamldefines a MongoDB service, but the current backend uses PostgreSQL via Prisma. If you want MongoDB support, the backend needs to be updated accordingly.- The authentication match uses Euclidean distance with a threshold of
0.6.
- CORS errors: ensure the backend is running on port 3000 and the frontend is on
http://localhost:5173orhttp://localhost:3000. - No face detected: make sure the webcam is active and the lighting is adequate.
This project is provided as-is for educational purposes.