How fyp-hyz-mjj-2024/posture-video-stream works
Project Type and Purpose
• This is a full-stack, browser-based frontend application built with Next.js and React, accompanied by a simple Node.js WebSocket server.
• Purpose: Provide a user interface for “Pedestrian Cell Phone Usage Detection” (alias “You Focus Your Walk”), enabling users to register, log in, manage users/faces, upload face data, and perform real-time face comparison via WebSocket.
Main Architectural Components
a. Browser / Client
• React components under components/ (e.g., Indicator.tsx, Inputs.tsx, ListItem.tsx, buttons.tsx)
• Pages under pages/ (e.g., pages/index.tsx, pages/user/*.tsx, pages/face/*.tsx, _app.tsx, _document.tsx)
b. Next.js Server (SSR & API)
• Custom server logic in lib/server.ts
• API routes under pages/api/ (e.g., hello.ts)
c. WebSocket Server
• public/ws-server.js serving real-time face comparison messages on port 8976
d. Shared Utilities & Configuration
• Auth helpers: lib/auth.ts
• File handling: lib/files.ts
• Common utils: lib/utils.ts and data/WSCode.tsx
• Environment/config: .env*, next.config.mjs, tsconfig.json, postcss.config.mjs, tailwind.config.ts
e. Deployment Artefacts
• Dockerfile for containerized build and run
• package.json / package-lock.json, .eslintrc.json, .gitignore
Relationships and Data Flows
• User’s Browser ⟷ Next.js Server over HTTP/HTTPS
• Server-Side Rendering of React pages
• RESTful calls to API routes (e.g., user login/register)
• Browser ⟷ WebSocket Server on ws://<host>:8976
• Real-time messages for face comparison sessions
• Next.js Server may interact with file storage or authentication backends via lib/files.ts & lib/auth.ts
Architectural Patterns & Design Principles
• Component-based UI (React)
• MVC-style separation:
• Views → pages/ & components/
• Controllers/Endpoints → pages/api/, public/ws-server.js
• Models/Services → lib/*.ts
• Configuration as code (env files, Next.js config, Dockerfile)
• Concurrency orchestration via concurrently (npm scripts)
Essential File Names to Display
• UI Layer: pages/index.tsx, pages/user/login.tsx, pages/face/compare_face.tsx, components/Indicator.tsx
• API Layer: pages/api/hello.ts, lib/server.ts
• Realtime Layer: public/ws-server.js
• Shared Logic: lib/auth.ts, lib/files.ts, lib/utils.ts
• Config & Deploy: .env, next.config.mjs, Dockerfile