Implement a locking mechanism to prevent concurrent edits on an appointment. Only one user can edit at a time, while others can only view. The UI must reflect the lock status and current editor.
-
Locking System
- Create a REST/WebSocket endpoint to acquire/release locks on appointments
- Store lock metadata (lockedBy, appointmentId, timestamp)
- Auto-release locks after 5 minutes of inactivity
- Handle concurrent lock requests gracefully
-
APIs
GET /appointments/:id/lock-status- Get current lock statusPOST /appointments/:id/acquire-lock- Attempt to acquire lockDELETE /appointments/:id/release-lock- Release existing lockWS /appointments/:id/updates- Real-time lock/pointer updates (Bonus)
-
Models
interface AppointmentLock { appointmentId: string; userId: string; userInfo: { name: string; email: string }; // Bonus: Add position data expiresAt: Date; }
-
Lock Awareness
- Show visual indicator when appointment is locked
- Disable form inputs when not the lock owner
- Display current editor's identity and lock timer
-
Real-Time Updates
- Implement WebSocket connection for lock status changes
- Show loading state during lock acquisition/release
- (Bonus) Display other users' pointers using aceternity Following Pointer
-
Takeover Feature
- Add "Request Control" button for admins
- Force release lock after confirmation (admin-only)
- Handle takeover conflicts gracefully
-
Concurrency Control
- Use optimistic locking or versioning for data integrity
- Handle race conditions in lock acquisition
- Implement proper error handling for lock conflicts
-
State Management
- Use React Context/Redux for lock state
- Sync frontend state with backend via WebSocket/REST
- Handle tab/window close events to release locks
-
Security
- Validate user permissions for lock operations
- Sanitize WebSocket messages
- Implement rate limiting for lock attempts
-
Collaborative Cursors
- Broadcast mouse position via WebSocket
- Display other users' cursors with aceternity animation
- Throttle position updates for performance
-
Admin Takeover
- Add admin role verification
- Implement priority locking for admins
- Add audit trail for forced takeovers
- Complete lock workflow implementation
- Unit tests for critical paths (lock acquisition/conflict/resolution)
- Documentation of architecture decisions
- (Bonus) Animated cursor demonstration
- Implementation completeness
- Handling of edge cases
- Code quality & TypeScript usage
- Real-time synchronization efficiency
- Error handling and user feedback
- Bonus feature implementation quality
- Backend: Node.js, Express, TypeORM/Prisma, WebSocket
- Frontend: React, TypeScript, React-Query, Zustand/Jotai
- UI: aceternity/ui for animated cursor, Tailwind CSS