This project is a Backend REST API for managing student attendance.
It allows:
- Managing subjects
- Marking daily attendance for students
- Preventing duplicate attendance for the same student, subject, and date
- Fetching attendance records
- Calculating attendance percentage (overall & subject-wise)
This project focuses on backend fundamentals, clean API design, validation, and SQL-based data handling.
- Python
- Flask
- MySQL
- Postman (API testing)
Attendance-Management-System-API/
│
├── app.py # Application entry point
├── db.py # MySQL database connection
├── models/
│ ├── __init__.py
│ ├── subject.py # Subject database operations
│ └── attendance.py # Attendance database operations
├── routes/
│ ├── __init__.py
│ ├── subject_routes.py # Subject-related routes
│ └── attendance_routes.py # Attendance-related routes
├── requirements.txt
├── README.md
└── screenshots/ # Postman API testing screenshots
git clone https://github.com/iamajaykr06/Attendance-Management-System-API.git
cd Attendance-Management-System-API
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
CREATE DATABASE attendance_db;
CREATE TABLE subjects (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
code VARCHAR(50) NOT NULL UNIQUE
);
CREATE TABLE attendance (
id INT AUTO_INCREMENT PRIMARY KEY,
student_id INT NOT NULL,
subject_id INT NOT NULL,
attendance_date DATE NOT NULL,
status ENUM('present', 'absent') NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE(student_id, subject_id, attendance_date)
);
Note: Student records are assumed to exist and are referenced using student_id.
The UNIQUE constraint ensures attendance cannot be marked twice for the same student, subject, and date.
Edit db.py and update:
- MySQL username
- Password
- Database name
python app.py
Server runs at:
http://127.0.0.1:5000
POST /subjects
{
"name": "Software Engineering",
"code": "CS101"
}
Responses
201 Created400 Bad Request
Example error response:
{
"message": "Attendance already marked or invalid data"
}
GET /subjects
POST /attendance
{
"student_id": 1,
"subject_id": 1,
"attendance_date": "2026-01-12",
"status": "present"
}
201 Created400 Bad Request(duplicate or invalid data)
GET /attendance/student/{student_id}
GET /attendance/date/{date}
GET /attendance/percentage/student/{student_id}
{
"student_id": 1,
"attendance_percentage": "100.00"
}
GET /attendance/percentage/student/{student_id}/subject/{subject_id}
{
"student_id": 1,
"subject_id": 1,
"attendance_percentage": "100.00"
}
All API request & response screenshots (tested using Postman) are available in the screenshots/ directory, including:
- Subject creation
- Attendance marking
- Duplicate attendance validation
- Attendance retrieval
- Attendance percentage calculation
- Subject management
- Attendance marking with duplicate prevention
- Date-wise and student-wise attendance retrieval
- Attendance percentage calculation
- Input validation
- Proper HTTP status codes
- Clean project structure
- REST API design using Flask
- SQL constraints for data integrity
- Backend validation strategies
- Attendance calculation logic
- Clean separation of routes and models
Ajay Kumar