How kiruthikkumar16/facial works
Purpose and deployment shape
Enterprise facial-recognition platform using an edge-to-cloud architecture: local video inference produces face events and embeddings; a FastAPI service persists/searches them in PostgreSQL/pgvector; a Next.js dashboard presents live operations and analytics. Intended runtimes are a local Python edge node, Render-hosted API, Supabase PostgreSQL, and Vercel-hosted frontend.
Primary entry points
• Edge runtime: facial_recognition/run.py, with alternate CPU-oriented launch path facial_recognition/run_cpu.py; core application modules include facial_recognition/main.py and facial_recognition/main_cpu.py.
• API server: backend/main.py, run through Uvicorn.
• Dashboard: Next.js App Router root at facial-recognition-dashboard/app/page.tsx, composed by facial-recognition-dashboard/components/dashboard/dashboard.tsx.
Edge capture and inference
The edge process acquires RTSP/webcam frames, detects faces, generates 512-dimensional InsightFace/ONNX embeddings, and recognizes/enrolls identities. Detection and embedding responsibilities are separated in facial_recognition/detector.py and facial_recognition/recognizer.py; source acquisition resides in facial_recognition/capture.py. The Haar cascade asset at cascades/haarcascade_frontalface_default.xml is a local CV dependency.
Durable edge-to-cloud event pipeline
Each detection is dual-written: locally to a CSV-backed transaction/archive path and remotely to the API, so network loss does not discard events. Relevant pipeline/recovery boundaries are facial_recognition/pending.py, facial_recognition/review_pending.py, and backend/tasks/ingest_csv.py. Cloud-side CSV ingestion is also represented by backend/ingest_csv.py, enabling deferred reconciliation rather than making recognition dependent on API availability.
Cloud API and persistence boundary
FastAPI exposes ingestion, dashboard data, forensic search, and identity-management capabilities through backend/main.py. SQLAlchemy connection/session setup is centralized in backend/database.py; relational entities plus vector-bearing records are modeled in backend/models.py, with request/response contracts in backend/schemas.py. Configuration and deployment environment handling are in backend/config.py and backend/render.yaml. PostgreSQL on Supabase, with pgvector, is the authoritative cloud store for metadata and similarity search.
Vector search and identity lifecycle
Embeddings flow from edge inference or backend manual-image processing into pgvector-backed records. The backend keeps ONNX-capable CV processing available for forensic uploads, while database vector distance queries support cosine similarity and deduplication/merge workflows. Edge enrollment and unknown-person handling are represented by facial_recognition/enroll.py and facial_recognition/pending.py; the backend is the trust boundary for durable identity/profile mutation.
Live dashboard synchronization
The API WebSocket layer in backend/websocket.py broadcasts alert, health, or KPI changes after backend events. The frontend API boundary is facial-recognition-dashboard/lib/api.ts; React providers and query-state wiring begin at facial-recognition-dashboard/components/providers.tsx. Dashboard tabs divide operational views into alerts, analytics, forensic search, profiles, and system status, e.g. components/dashboard/tabs/alerts-tab.tsx, analytics-tab.tsx, and forensic-tab.tsx. Clients use push-triggered refresh/invalidation rather than continual database polling.
Frontend resilience and presentation boundary
The Next.js dashboard is a client presentation layer, not the source of truth. Shared dashboard composition is in facial-recognition-dashboard/components/dashboard/shared.tsx, while global and component-level failure containment is provided by facial-recognition-dashboard/components/error-boundary.tsx and components/ui/error-boundary.tsx. Environment-specific frontend API configuration is expected through facial-recognition-dashboard/.env.local.example.
Main entry points: main.py FastAPI service · recognizer.py Embedding and recognition · dashboard.tsx Dashboard composition · api.ts Frontend API client
Components 20
Edge node
Local video capture and recognition runtime.
- Edge launchers · GPU and CPU launch paths start local recognition.
facial_recognition/run.py - Frame capture
facial_recognition/capture.py - Face detection · Uses the local Haar cascade dependency.
facial_recognition/detector.py - Embedding and recognition · Produces 512-dimensional embeddings and recognition results.
facial_recognition/recognizer.py - Enrollment and unknowns
facial_recognition/enroll.py - Local event archive · Retains events while cloud delivery is unavailable.
facial_recognition/pending.py - Pending-event recovery
facial_recognition/review_pending.py
Cloud backend
Render-hosted API and Supabase persistence boundary.
- FastAPI service · Exposes ingestion, dashboard, forensic, and identity operations.
backend/main.py - API contracts
backend/schemas.py - Forensic image processing · Processes manual forensic uploads into embeddings.
backend/main.py - Deferred CSV ingestion · Imports archived edge events after deferred delivery.
backend/ingest_csv.py - SQLAlchemy persistence
backend/database.py - Identity and vector records · Defines relational entities and vector-bearing records.
backend/models.py - Supabase PostgreSQL + pgvector · Stores metadata and performs similarity, deduplication, and merge queries.
- WebSocket broadcaster · Publishes alerts, health, and KPI changes.
backend/websocket.py
Dashboard
Vercel-hosted Next.js operations client.
- Next.js dashboard · Operational presentation layer, not a source of truth.
facial-recognition-dashboard/app/page.tsx - Dashboard composition · Composes alerts, analytics, forensic, profiles, and system status views.
facial-recognition-dashboard/components/dashboard/dashboard.tsx - Frontend API client
facial-recognition-dashboard/lib/api.ts - Providers and query state · Refreshes or invalidates views from push events.
facial-recognition-dashboard/components/providers.tsx - Failure containment
facial-recognition-dashboard/components/error-boundary.tsx
Connections 21
- Edge launchers → Frame capture: starts
- Frame capture → Face detection: frames
- Face detection → Embedding and recognition: face crops
- Embedding and recognition → Enrollment and unknowns: recognized or unknown faces
- Embedding and recognition → Local event archive: dual-writes events
- Local event archive → Pending-event recovery: pending CSV events
- Embedding and recognition → FastAPI service: remote event ingestion
- Pending-event recovery → Deferred CSV ingestion: reconciles archived events
- Deferred CSV ingestion → FastAPI service: deferred import
- FastAPI service → API contracts: validates requests
- FastAPI service → Forensic image processing: forensic uploads
- FastAPI service → SQLAlchemy persistence: reads and mutates
- SQLAlchemy persistence → Identity and vector records: maps records
- Identity and vector records → Supabase PostgreSQL + pgvector: metadata and vectors
- FastAPI service → WebSocket broadcaster: backend changes
- Next.js dashboard → Dashboard composition: renders
- Dashboard composition → Providers and query state: uses
- Providers and query state → Frontend API client: queries and invalidates
- Frontend API client → FastAPI service: HTTP operations
- WebSocket broadcaster → Frontend API client: push updates
- Failure containment → Dashboard composition: contains UI failures