A comprehensive admin system for managing students and tracking attendance, built with Next.js, MongoDB, and JWT authentication.
- Secure Login: JWT-based authentication with environment variable credentials
- Student Management: Add, edit, update, and remove students
- Attendance Tracking: Mark daily attendance with status (Present, Absent, Late)
- Attendance History: View and filter attendance records with export functionality
- Dashboard: Overview of student statistics and attendance metrics
- Performance Leaderboard: View student rankings based on attendance scores
- Members Page: Display all active students with their information
- Responsive Design: Works on desktop and mobile devices
Create a .env file in the root directory with the following variables:
# GitHub Token (existing)
GITHUB_TOKEN=your_github_token
# Admin credentials
ADMIN_EMAIL=admin@example.com
ADMIN_PASSWORD=admin123
# JWT Secret (change this in production)
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
# MongoDB connection
MONGODB_URI=mongodb://localhost:27017/student-managementMake sure you have MongoDB installed and running locally, or use a cloud MongoDB service like MongoDB Atlas.
For local MongoDB:
# Install MongoDB (Ubuntu/Debian)
sudo apt-get install mongodb
# Start MongoDB service
sudo systemctl start mongodb
# Or using Docker
docker run -d -p 27017:27017 --name mongodb mongo:latestnpm installnpm run seedThis will create 5 sample students in your database.
npm run devThe application will be available at http://localhost:3000
- Navigate to
/admin/loginor click "Admin" in the navigation - Login with the credentials from your
.envfile:- Email:
admin@example.com - Password:
admin123
- Email:
After logging in, you'll have access to:
- Dashboard: Overview of students and today's attendance
- Student Management: Add, edit, and remove students
- Take Attendance: Mark attendance for any date
- Reports: View attendance history and export data
- Performance Leaderboard: View student rankings and performance metrics
The Performance Leaderboard ranks students based on their attendance scores:
- Scoring System:
- Present = 1 point
- Late = 0.5 points
- Absent = 0 points
- Features:
- Top 3 students highlighted with special badges
- Visual chart showing top 10 performers
- Complete leaderboard table with detailed statistics
- Real-time attendance percentage calculations
- Access: Navigate to
/admin/performanceor click "Performance" from the dashboard
- Visit
/membersto see all active students - Students added by admin will automatically appear here
-
POST /api/auth/login- Admin login- Request:
{ email: string, password: string } - Response:
{ token: string, message: string } - Status: 200 (success), 401 (invalid credentials), 400 (validation error)
- Request:
-
POST /api/auth/logout- Admin logout- Response:
{ message: string } - Status: 200 (success)
- Response:
-
GET /api/auth/csrf- Get CSRF token- Headers:
Authorization: Bearer <token> - Response:
{ csrfToken: string } - Status: 200 (success), 401 (unauthorized)
- Headers:
-
GET /api/students- Get all active students- Headers:
Authorization: Bearer <token> - Query Params:
page,limit,search,includeUnverified - Response:
{ students: Student[], pagination: {...} } - Status: 200 (success), 401 (unauthorized)
- Headers:
-
POST /api/students- Create new student (admin-created)- Headers:
Authorization: Bearer <token>,x-csrf-token: <csrf> - Request:
{ name, email, studentId, ... } - Response:
{ student: Student, message: string } - Status: 201 (created), 400 (validation error), 401 (unauthorized)
- Headers:
-
PUT /api/students/[id]- Update student- Headers:
Authorization: Bearer <token>,x-csrf-token: <csrf> - Request:
{ name, email, studentId, ... } - Response:
{ student: Student, message: string } - Status: 200 (success), 400 (validation error), 404 (not found)
- Headers:
-
DELETE /api/students/[id]- Soft delete student- Headers:
Authorization: Bearer <token>,x-csrf-token: <csrf> - Response:
{ message: string } - Status: 200 (success), 404 (not found), 401 (unauthorized)
- Headers:
-
GET /api/students/next-id- Get next available student ID- Headers:
Authorization: Bearer <token> - Response:
{ nextId: string } - Status: 200 (success), 401 (unauthorized)
- Headers:
-
POST /api/students/verify- Approve or reject student registration- Headers:
Authorization: Bearer <token>,x-csrf-token: <csrf> - Request:
{ studentId: string, action: 'approve' | 'reject', studentIdToAssign?: string } - Response:
{ message: string } - Status: 200 (success), 400 (validation error), 404 (not found)
- Headers:
-
GET /api/attendance- Get attendance records (with filters)- Headers:
Authorization: Bearer <token> - Query Params:
date,studentId,page,limit - Response:
{ attendance: Attendance[], pagination: {...} } - Status: 200 (success), 401 (unauthorized)
- Headers:
-
POST /api/attendance- Record single attendance- Headers:
Authorization: Bearer <token>,x-csrf-token: <csrf> - Request:
{ studentId: string, date: string, status: 'present' | 'late' | 'absent', notes?: string } - Response:
{ attendance: Attendance, message: string } - Status: 201 (created), 400 (validation error), 404 (student not found)
- Headers:
-
POST /api/attendance/bulk- Record bulk attendance- Headers:
Authorization: Bearer <token>,x-csrf-token: <csrf> - Request:
{ date: string, attendanceRecords: [{ studentId, status, notes? }] } - Response:
{ successful: number, failed: number, results: [], errors: [] } - Status: 200 (success), 400 (validation error)
- Headers:
GET /api/admin/performance- Get student performance leaderboard- Headers:
Authorization: Bearer <token> - Response:
{ "leaderboard": [ { "_id": "string", "studentId": "string", "studentName": "string", "totalPoints": number, "totalDays": number, "presentCount": number, "lateCount": number, "absentCount": number, "attendancePercentage": number, "rank": number } ], "generatedAt": "ISO 8601 timestamp" } - Status: 200 (success), 401 (unauthorized), 500 (server error)
- Scoring: Present = 1 point, Late = 0.5 points, Absent = 0 points
- Headers:
{
name: String (required),
email: String (optional),
studentId: String (optional, unique),
phone: String (optional),
course: String (optional),
year: String (optional),
isActive: Boolean (default: true),
timestamps: true
}{
studentId: ObjectId (ref: Student, required),
date: Date (required),
status: String (enum: ['present', 'absent', 'late'], required),
notes: String (optional),
markedBy: String (default: 'admin'),
timestamps: true
}- JWT token authentication
- HTTP-only cookies for token storage
- Protected admin routes with middleware
- Input validation and sanitization
- Secure password handling (ready for bcrypt hashing)
- Frontend: Next.js 15, React 19, TypeScript
- Styling: Tailwind CSS, Radix UI components
- Backend: Next.js API routes
- Database: MongoDB with Mongoose
- Authentication: JWT tokens
- Deployment: Ready for Vercel deployment
- Update environment variables for production
- Use a strong JWT secret
- Use MongoDB Atlas or another cloud database
- Consider implementing password hashing for admin credentials
- Set up proper CORS and security headers
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is open source and available under the MIT License.