Schema design: employees, office buildings, and access cards
Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2024-05-24
Problem Statement
Designing the database schema and LLD for managing employees, office buildings, and their access cards in a corporate environment. The system should allow employees to be assigned access cards, which grant entry into specific buildings and track access logs.
Functional Requirements (FR)
1.Employee Management
•Store employee details (ID, name, department, role, contact info).
•Each employee is assigned one unique access card.
•An employee may work in multiple buildings.
2.Office Building Management
•Store details of office buildings (building ID, name, address, floors).
•Define zones/areas (e.g., lobby, server room, cafeteria) within a building.
•Restrict access based on employee role/department.
3.Access Card Management
•Each access card has a unique card ID.
•Each card is mapped to one employee.
•Define validity period (active, expired, blocked).
•Define access permissions (which buildings/zones an employee can enter).
4.Access Logging
•Track entry and exit logs when an access card is swiped.
•Log should include employee ID, building ID, zone, timestamp, status (granted/denied).
•Support reporting and auditing (who entered where and when).
5.Security
•Block or revoke access cards if lost/stolen.
•Detect unauthorized attempts and alert security.
Non-Functional Requirements (NFR)
•Scalability: Support thousands of employees and multiple office buildings.
•High Availability: System should work 24/7 with no downtime.
•Auditability: Maintain access logs for compliance and investigations.
•Security: Encrypt sensitive data, role-based access control for admin features.
Core Entities & Attributes
1.Employee
•employeeId, name, email, phone, department, role, accessCardId
2.Building
•buildingId, name, address, totalFloors
3.Zone
•zoneId, buildingId, name, accessLevelRequired
4.AccessCard
•cardId, employeeId, issueDate, expiryDate, status (active/blocked/expired)
5.AccessPermission
•cardId, buildingId, zoneId, allowed (true/false)
6.AccessLog
•logId, cardId, employeeId, buildingId, zoneId, timestamp, status (granted/denied)
APIs / Operations
1.Employee APIs
•createEmployee(details)
•assignAccessCard(employeeId, cardId)
•getEmployeeAccess(employeeId)
2.Building & Zone APIs
•createBuilding(name, address, floors)
•createZone(buildingId, zoneName, accessLevel)
3.Access Card APIs
•createAccessCard(employeeId)
•revokeAccessCard(cardId)
•updateAccessPermissions(cardId, buildingId, zoneId)
4.Access Logging APIs
•logAccess(cardId, buildingId, zoneId, status)
•getAccessLogs(employeeId, filters)
•getBuildingAccessReport(buildingId, dateRange)
Advanced Features (Optional / Bonus)
•Biometric + access card multi-factor authentication.
•Visitor management system with temporary access cards.
•Real-time monitoring dashboard for security admins.
•Integration with HR system (auto-revoke access when employee exits company).
•Geo-fencing (restrict entry after work hours).