How thangved/face-detection works
Project Type and Purpose
• This is a client-only, single-page web application (built with Vite + React/TypeScript) for real-time face detection using faceapi.js.
• The app loads pre-trained models from the public/models folder and runs inference entirely in the browser via WebRTC video input.
Main Components
a. Client (Browser)
• React Application (src/App.tsx, src/main.tsx)
• FaceAPI.js Library (imported in code; no server dependency)
• Utilities
• getVideoStream.ts: acquires webcam via WebRTC
• loadModels.ts: fetches model shards & manifests from static server
b. Static Asset Server
• Serves index.html, JS bundles, CSS, and public/models/*
• Can be GitHub Pages, Netlify, Vercel, or any static host
c. CI/CD Pipeline
• GitHub Actions workflow (.github/workflows/deploy.yml)
• Runs build, test, and deployment steps on push
Relationships & Data Flow
• User → Browser: User navigates to the hosted URL.
• Browser → Static Server:
• Downloads index.html → bootstraps React app
• Downloads JS/CSS bundles (built by Vite)
• Downloads model weight manifests and shard files under public/models
• React App → Browser APIs:
• Calls getUserMedia() (WebRTC) to access webcam
• React App → FaceAPI.js:
• Calls loadModels() to fetch and initialize models in memory
• Streams video frames into faceapi.js detection pipeline
• React App → UI:
• Overlays detection results onto a <canvas> or <video> element
Architectural Patterns & Design Principles
• SPA Architecture: separation of concerns between static hosting and client logic
• Client-heavy ML Inference: all computation happens in the browser; no backend
• Modular Code: utilities under src/utils/, React components under src/
• CI/CD as Code: GitHub Actions defined in YAML