Build your own attendance app with our expert guide. Simplify tracking & management with this step-by-step tutorial for developers.

Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
Setting Up Project Files & Dependencies
attendance.lov to host all routes, views, business logic, and modules for the Attendance app.
// Import modules for database operations, user authentication, UI rendering, and notifications
import "lovable-db" // Handle persistent data storage (for users, attendance records)
import "lovable-auth" // Manage user registration, login, and session logic
import "lovable-ui" // Render interactive user interface components across views
import "lovable-notify" // Provide real-time notifications and alerts for attendance actions
Database & Model Setup
// Database models declaration
model User {
id: UUID // Unique identifier for the user
name: String // Full name of the user
email: String // Email for login and notifications
password: String // Encrypted user password
role: String // Role (e.g., "employee", "admin")
createdAt: Date // Record creation timestamp
}
model Attendance {
id: UUID // Unique identifier for an attendance record
userId: UUID // Reference to the User model
checkIn: Date // Timestamp when user checked in
checkOut: Date // Timestamp when user checked out (optional)
date: Date // Date of the attendance entry
}
User Authentication & Session Management
// Authentication routes and session middleware
// Register route for new user sign-up
route "/register" {
method: "POST"
handler: function(request, response) {
// Validate and create a new user account
let newUser = createUser(request.body)
response.send({ success: true, message: "Registration successful" })
}
}
// Login route for users to create a session
route "/login" {
method: "POST"
handler: function(request, response) {
// Validate credentials and set session
let user = authenticate(request.body.email, request.body.password)
if (user) {
createSession(user)
response.send({ success: true, message: "Login successful" })
} else {
response.send({ success: false, message: "Invalid credentials" })
}
}
}
// Middleware to ensure routes are accessed by authenticated users only
middleware authGuard {
execute: function(request, response, next) {
if (isSessionValid(request)) {
next()
} else {
response.send({ success: false, message: "Authentication required" })
}
}
}
Attendance Logic & Routes
// Attendance routes and logic
// Route to mark check-in
route "/attendance/checkin" {
method: "POST"
middleware: [authGuard]
handler: function(request, response) {
let userId = request.user.id
let today = getTodayDate()
// Check if the user has already checked in today
if (attendanceExists(userId, today)) {
response.send({ success: false, message: "Already checked in today" })
} else {
// Record check-in time
createAttendanceRecord(userId, today, { checkIn: new Date() })
sendNotification(userId, "Checked in successfully")
response.send({ success: true, message: "Check-in recorded", time: new Date() })
}
}
}
// Route to mark check-out
route "/attendance/checkout" {
method: "POST"
middleware: [authGuard]
handler: function(request, response) {
let userId = request.user.id
let today = getTodayDate()
// Retrieve existing attendance record for today
let record = fetchAttendanceRecord(userId, today)
if (record == null) {
response.send({ success: false, message: "Check-in required before check-out" })
} else if (record.checkOut != null) {
response.send({ success: false, message: "Already checked out today" })
} else {
// Update record with check-out time
record.checkOut = new Date()
updateAttendanceRecord(record)
sendNotification(userId, "Checked out successfully")
response.send({ success: true, message: "Check-out recorded", time: new Date() })
}
}
}
UI and User Flow
// UI rendering for the dashboard
view "Dashboard" {
template: "
Welcome, {{user.name}}
Your Attendance History
{{#each attendanceRecords}}
Date: {{this.date}}
Check-In: {{this.checkIn}}
Check-Out: {{this.checkOut}}
{{/each}}
"
// Fetch necessary data on view load
onLoad: function() {
loadUserAttendance()
}
}
Reporting and History Logging
// Admin route to fetch overall attendance reports
route "/admin/attendance-report" {
method: "GET"
middleware: [authGuard]
handler: function(request, response) {
if (request.user.role !== "admin") {
response.send({ success: false, message: "Access denied" })
return
}
let filters = request.query // e.g., dateRange, userId, role
let report = generateAttendanceReport(filters)
// Optionally export report as CSV or PDF based on request parameters
if (request.query.export == "csv") {
let csvData = exportAsCSV(report)
response.send({ success: true, data: csvData })
} else {
response.send({ success: true, data: report })
}
}
}
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.