Backend system for live attendance tracking with WebSocket support.
- Node.js, Express
- MongoDB, Mongoose
- JWT, bcrypt
- Zod (validation)
- ws (WebSocket)
npm installCreate a .env file:
MONGODB_URI=mongodb://localhost:27017/live-attendance
JWT_SECRET=your_jwt_secret_key_here
PORT=3000npm start
# or for development with watch mode
npm run devPOST /auth/signup- Create user accountPOST /auth/login- Login and get JWT tokenGET /auth/me- Get current user info (requires auth)
POST /class- Create class (teacher only)POST /class/:id/add-student- Add student to class (teacher only)GET /class/:id- Get class details with students
GET /students- Get all students (teacher only)GET /class/:id/my-attendance- Get student's attendance status (student only)
POST /attendance/start- Start attendance session (teacher only)
ws://localhost:3000/ws?token=<JWT_TOKEN>
ATTENDANCE_MARKED (Teacher)
{
"event": "ATTENDANCE_MARKED",
"data": {
"studentId": "s100",
"status": "present"
}
}TODAY_SUMMARY (Teacher)
{
"event": "TODAY_SUMMARY"
}MY_ATTENDANCE (Student)
{
"event": "MY_ATTENDANCE"
}DONE (Teacher)
{
"event": "DONE"
}Success:
{
"success": true,
"data": { ... }
}Error:
{
"success": false,
"error": "Error message"
}